# (c) 2017 Aaron Taylor <ataylor at subgeniuskitty dot com>
# See LICENSE file for copyright and license details.
import os
, sys
, subprocess
, configparser
import debug
, config
, template
# Accepts a string containing a filesystem path to a text file.
# Returns a string containing the contents of that file.
if debug
.print_to_browser
: print("Unable to open " + path
+ " for reading.")
sys
.exit("Unable to open " + path
+ " for reading.")
# Accepts a string containing markup'ed text
# Returns a string containing HTML'ed text
def process_markup(text
):
p
= subprocess
.Popen(config
.markup_processor
,
stdout
=subprocess
.PIPE
,stdin
=subprocess
.PIPE
)
if debug
.print_to_browser
: print("Unable to open 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 strip_page_metadata(content
):
keyword
= template
.add_delimiter("END_PAGE_METADATA")
index
= content
.find(keyword
)
return content
[index
+len(keyword
):]
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
)
page_file
= page_file
[len(keyword_begin
):index
]
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
]