From 57875365cd67b6a1354984a6262c6c7e220056ec Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Sun, 23 Dec 2012 13:31:16 +0100 Subject: [PATCH] Moved comment section code to a separate file, making replacement/removement easier --- comment_section.py | 40 ++++++++++++++++++++++++++++++++++++++++ pylog.py | 27 +++++++++++++++++---------- pylog_config.py | 36 ++++-------------------------------- 3 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 comment_section.py diff --git a/comment_section.py b/comment_section.py new file mode 100644 index 0000000..7aaf585 --- /dev/null +++ b/comment_section.py @@ -0,0 +1,40 @@ +import urllib, os +import pylog_config as cfg + +__commentanchor="#disqus_thread" #The anchor name of the comment section + +def comments_init(): + print """""" + +def disp_comments(file): + """
+ + + blog comments powered by Disqus""" + + +def disp_num_of_comments(file): + sys.stdout.write('') diff --git a/pylog.py b/pylog.py index 20e71d8..e3863fe 100755 --- a/pylog.py +++ b/pylog.py @@ -11,6 +11,7 @@ from datetime import datetime from pylog_action import * import pylog_config as cfg +import comment_section __version = "v0.1-(2012-03-15)" @@ -71,6 +72,10 @@ def disp_list(path): files = {} for f in os.listdir(path): f = os.path.normpath(os.path.join(path,f)) + + if get_valid_path(f)==cfg.contentdir: + continue + if not os.path.isdir(f): if not os.path.getmtime(f) in files: files[os.path.getmtime(f)]=[f] @@ -99,9 +104,9 @@ def disp_file_dict(d,keys): print name+' - ', print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt), print ' ' - sys.stdout.write('') + + comment_section.disp_num_of_comments(f) + print '' prev_actions[typ](f) @@ -150,7 +155,7 @@ def get_newest(n): def get_valid_path(path): if '..' in path or os.path.normpath(path)=='.': return cfg.contentdir - valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789' + valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_-0123456789' for c in path: if not c in valid_chars: return cfg.contentdir @@ -228,6 +233,7 @@ print '' print (''+cfg.title+'').encode(cfg.encoding) print '' print cfg.header.encode(cfg.encoding) +comment_section.comments_init() print '' print '' print ('

'+cfg.blogtitle+'

').encode(cfg.encoding) @@ -257,7 +263,13 @@ try: ).strftime(cfg.datefmt), print '' - disp_actions[typ](validdisp) + comment_section.disp_actions[typ](validdisp) + + print '
' + print '' else: disp_list(path) except OSError as ose: @@ -266,11 +278,6 @@ except OSError as ose: print '' - print cfg.footer - print '' print '' print '' diff --git a/pylog_config.py b/pylog_config.py index 91bd973..d2d53db 100644 --- a/pylog_config.py +++ b/pylog_config.py @@ -2,42 +2,14 @@ title = 'PyLog' # Title displayed on the browser window/tab blogtitle= 'Plog' # The blog's title subtitle=u'produced py Powertomato \xb0\u0DF4\xb0' # The text to be displayed under the blog title +# This header will be printed in the section of the html file header=""" +""" - -""" # This header will be printed in the section of the html file - -footer=""" -
- - -blog comments powered by Disqus -""" # This footer will be printed at the end of the tag - -commentanchor="#disqus_thread" #The anchor name of the comment section +# This footer will be printed at the end of the tag +footer="" datefmt='%Y-%m-%d' # format of the date which is displayed next to the entry # See pythons manual reference for time.strptime for details