Added basic template functionality.
[cmless] / bin / misc.py
CommitLineData
d955cfad
AT
1# (c) 2017 Aaron Taylor <ataylor at subgeniuskitty dot com>
2# See LICENSE file for copyright and license details.
3
4# Python imports
5import sys, subprocess
6
7# CMless imports
8import debug, config
9
10# Accepts a string containing a filesystem path to a text file.
11# Returns a string containing the contents of that file.
12def load_file(path):
13 try:
14 with open(path) as f:
15 contents = f.read()
16 except:
17 if debug.print_to_browser: print("Unable to open " + path + " for reading.")
18 sys.exit("Unable to open " + path + " for reading.")
19 return contents
20
21# Accepts a string containing markup'ed text
22# Returns a string containing HTML'ed text
23def process_markup(text):
24 try:
25 p = subprocess.Popen(config.markup_processor,
26 stdout=subprocess.PIPE,stdin=subprocess.PIPE)
27 except:
28 if debug.print_to_browser: print("Unable to open markup processor: " +
29 config.markup_processor)
30 sys.exit("Unable to open markup processor: " + config.markup_processor)
31 text = p.communicate(text.encode('UTF-8'))[0]
32 return(text.decode('UTF-8'))