Added cmless.py which can serve a basic page and pass it through markup
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 6 Jan 2018 01:29:33 +0000 (17:29 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 6 Jan 2018 01:29:33 +0000 (17:29 -0800)
processor.

README.md
bin/cmless.py [new file with mode: 0755]

index 97ceff0..de0b9c0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,8 +13,8 @@ Status
 CMless is not yet functional. The stages required to reach basic functionality are:
 
 1. ~~Figure out deployment scheme~~
 CMless is not yet functional. The stages required to reach basic functionality are:
 
 1. ~~Figure out deployment scheme~~
-2. Interpret URL and locate/serve appropriate page
-3. Feed pages through a document processor
+2. ~~Interpret URL and locate/serve appropriate page~~
+3. ~~Feed pages through a document processor~~
 4. Feed pages through a template engine
 5. Generate menu based on directory structure
 
 4. Feed pages through a template engine
 5. Generate menu based on directory structure
 
diff --git a/bin/cmless.py b/bin/cmless.py
new file mode 100755 (executable)
index 0000000..ece2313
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/python3
+
+# (c) 2017 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# See LICENSE file for copyright and license details.
+
+# Python imports
+import os, sys, subprocess, cgi
+
+# CMless imports
+import debug, config
+
+# Accepts a string containing a filesystem path to a text file.
+# Returns a string containing the contents of that file.
+def load_file(path):
+    try:
+        with open(path) as f:
+            contents = f.read()
+    except:
+        if debug.print_to_browser: print("Unable to open " + path + " for reading.")
+        sys.exit("Unable to open " + path + " for reading.")
+    return contents
+
+# Accepts a string containing markup'ed text
+# Returns a string containing HTML'ed text
+def process_markup(text):
+    try:
+        p = subprocess.Popen(config.markup_processor,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
+    except:
+        if debug.print_to_browser: print("Unable to open markup processor: " + config.markup_processor)
+        sys.exit("Unable to open markup processor: " + config.markup_processor)
+    text = p.communicate(text.encode('UTF-8'))[0]
+    return(text.decode('UTF-8'))
+
+def main():
+    print("Content-Type: text/html;charset=utf-8\n")
+
+    text = load_file(config.site_path_prefix + os.environ['REQUEST_URI'] + config.markup_file_extension)
+    print(process_markup(text))
+
+if __name__ == "__main__":
+    sys.exit(main())