X-Git-Url: http://git.subgeniuskitty.com/cmless/.git/blobdiff_plain/990c6f795837b53044174097e643466a19d6c232..1debf0347ff8e74bd56e18970fc43c4c8336462c:/bin/misc.py diff --git a/bin/misc.py b/bin/misc.py index 821ef34..846ebfe 100644 --- a/bin/misc.py +++ b/bin/misc.py @@ -2,10 +2,10 @@ # See LICENSE file for copyright and license details. # Python imports -import sys, subprocess +import os, sys, subprocess, configparser # CMless imports -import debug, config +import debug, config, template # Accepts a string containing a filesystem path to a text file. # Returns a string containing the contents of that file. @@ -30,3 +30,31 @@ def process_markup(text): sys.exit("Unable to open markup processor: " + config.markup_processor) text = p.communicate(text.encode('UTF-8'))[0] return(text.decode('UTF-8')) + +def strip_page_metadata(content): + keyword = template.add_delimiter("END_PAGE_METADATA") + index = content.find(keyword) + if index != -1: + return content[index+len(keyword):] + else: + return content + +def lookup_page_metadata(key): + page_file = load_file(config.site_data_prefix + os.environ['REQUEST_URI'] + + config.markup_file_extension) + + keyword_begin = template.add_delimiter("BEGIN_PAGE_METADATA") + keyword_end = template.add_delimiter("END_PAGE_METADATA") + index = page_file.find(keyword_end) + if index != -1: + page_file = page_file[len(keyword_begin):index] + else: + page_file = "" + + page_metadata = configparser.ConfigParser() + page_metadata.read_string(page_file) + + if 'DEFAULT' in page_metadata and key in page_metadata['DEFAULT']: + return page_metadata['DEFAULT'][key] + else: + return ""