Use variable "tab" for tabs for better code style (part2)

This commit is contained in:
Stefan Ritter 2010-11-16 08:33:29 +01:00
parent 6697c76176
commit 9a8023158b

View File

@ -270,12 +270,12 @@ if feed_display == "atom":
document_header("atom") document_header("atom")
print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>' print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>'
print ' <author>' print tab + '<author>'
print ' <name>' + blog_title + '</name>' print tab*2 + '<name>' + blog_title + '</name>'
print ' </author>' print tab + '</author>'
print ' <title>' + blog_title + '</title>' print tab + '<title>' + blog_title + '</title>'
print ' <id>urn:uuid:' + blog_title_md5sum + '</id>' print tab + '<id>urn:uuid:' + blog_title_md5sum + '</id>'
print ' <updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>' print tab + '<updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>'
print '' print ''
j = len(entries) j = len(entries)
if j > 10: j = 10 if j > 10: j = 10
@ -283,44 +283,42 @@ if feed_display == "atom":
title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '') title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '')
date = entries[i][0] date = entries[i][0]
title_md5sum = generate_uuid(title) title_md5sum = generate_uuid(title)
print ' <entry>' print tab*2 + '<entry>'
print ' <title>' + title + '</title>' print tab*3 + '<title>' + title + '</title>'
print ' <link href="' + blog_url + '?p=' + title + '"/>' print tab*3 + '<link href="' + blog_url + '?p=' + title + '"/>'
print ' <id>urn:uuid:' + title_md5sum + '</id>' print tab*3 + '<id>urn:uuid:' + title_md5sum + '</id>'
print ' <updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>' print tab*3 + '<updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>'
print ' <summary>' print tab*3 + '<summary>'
content = open(str(entries[i][1]), 'r') content = open(str(entries[i][1]), 'r')
for h in xrange(0, int(feed_preview)): for h in xrange(0, int(feed_preview)):
rss_line = content.readline().strip() rss_line = content.readline().strip()
if rss_line != '': if rss_line != '':
print ' ' + rss_line print ' ' + rss_line
content.close() content.close()
print ' </summary>' print tab*3 + '</summary>'
print ' </entry>' print tab*2 + '</entry>'
print '</feed>' print '</feed>'
# Generate rss 2.0 feed # Generate rss 2.0 feed
elif feed_display == "rss": elif feed_display == "rss":
document_header("rss") document_header("rss")
print ' <channel>' print tab + '<channel>'
print ' <title>' + blog_title + '</title>' print tab*2 + '<title>' + blog_title + '</title>'
print ' <link>' + blog_url + '</link>' print tab*2 + '<link>' + blog_url + '</link>'
print ' <description>' + blog_subtitle + '</description>' print tab*2 + '<description>' + blog_subtitle + '</description>'
date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(time.mktime(entries[0][0]))) date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(time.mktime(entries[0][0])))
print ' <pubDate>' + date + '</pubDate>' print tab*2 + '<pubDate>' + date + '</pubDate>'
print '' print ''
j = len(entries) j = len(entries)
if j > 10: j = 10 if j > 10: j = 10
for i in xrange(0, j): for i in xrange(0, j):
title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '') title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '')
date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0]))) date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0])))
title_md5sum = generate_uuid(title) print tab*2 + '<item>'
print ' <item>' print tab*3 + '<title>' + title + '</title>'
print ' <title>' + title + '</title>' print tab*3 + '<link>' + blog_url + '?p=' + title + '</link>'
print ' <link>' + blog_url + '?p=' + title + '</link>' print tab*3 + '<guid>' + blog_url + '?p=' + title + '</guid>'
#print ' <guid>' + title_md5sum + '</guid>' print tab*3 + '<pubDate>' + date + '</pubDate>'
print ' <guid>' + blog_url + '?p=' + title + '</guid>'
print ' <pubDate>' + date + '</pubDate>'
content = open(str(entries[i][1]), 'r') content = open(str(entries[i][1]), 'r')
rss_description= '' rss_description= ''
for h in xrange(0, int(feed_preview)): for h in xrange(0, int(feed_preview)):
@ -328,9 +326,9 @@ elif feed_display == "rss":
if line: if line:
rss_description = rss_description + line + '<br />' rss_description = rss_description + line + '<br />'
content.close() content.close()
print ' <description><![CDATA[' + rss_description + ']]></description>' print tab*3 + '<description><![CDATA[' + rss_description + ']]></description>'
print ' </item>' print tab*2 + '</item>'
print ' </channel>' print tab + '</channel>'
print '</rss>' print '</rss>'
# Generate regular page # Generate regular page
@ -447,23 +445,23 @@ else:
# Staticpage # Staticpage
if static_display != "": if static_display != "":
content = open(staticpages_dir + static_display, "r") content = open(staticpages_dir + static_display, "r")
print ' <div class="entry">' print tab*3 + '<div class="entry">'
print ' <div class="entry_title">' + re.sub('^\.', '', re.sub('\d+?-', '', static_display)) + '</div>' print tab*4 + '<div class="entry_title">' + re.sub('^\.', '', re.sub('\d+?-', '', static_display)) + '</div>'
print ' <div class="entry_content">' print tab*4 + '<div class="entry_content">'
print ' <p>' print tab*5 + '<p>'
for line in content: for line in content:
if no_break.match(line): if no_break.match(line):
print ' ' + line.strip() print tab*5 + line.strip()
else: else:
print ' ' + line.strip() + '<br />' print tab*5 + line.strip() + '<br />'
print ' </p>' print tab*5 + '</p>'
print ' </div>' print tab*4 + '</div>'
print ' <div class="entry_footer"></div>' print tab*4 + '<div class="entry_footer"></div>'
print ' <div class="entry_border_left"></div>' print tab*4 + '<div class="entry_border_left"></div>'
print ' <div class="entry_border_right"></div>' print tab*4 + '<div class="entry_border_right"></div>'
print ' <div class="entry_border_top"></div>' print tab*4 + '<div class="entry_border_top"></div>'
print ' <div class="entry_border_bottom"></div>' print tab*4 + '<div class="entry_border_bottom"></div>'
print ' </div>' print tab*3 + '</div>'
print '' print ''
content.close() content.close()
@ -481,24 +479,24 @@ else:
if post_display == title.replace(' ', '-') or not post_display: if post_display == title.replace(' ', '-') or not post_display:
if allentries_display == "1" or entry_counter < entries_per_page: if allentries_display == "1" or entry_counter < entries_per_page:
content = open(entry, "r") content = open(entry, "r")
print ' <div class="entry">' print tab*3 + '<div class="entry">'
if permalinks: if permalinks:
print ' <div class="entry_title"><a href="?p=' + title.replace(' ', '-') + '" class="entry_title">' + title + '</a></div>' print tab*4 + '<div class="entry_title"><a href="?p=' + title.replace(' ', '-') + '" class="entry_title">' + title + '</a></div>'
else: else:
print ' <div class="entry_title">' + title + '</div>' print tab*4 + '<div class="entry_title">' + title + '</div>'
print ' <div class="entry_date">' + date + '</div>' print tab*4 + '<div class="entry_date">' + date + '</div>'
print ' <div class="entry_content">' print tab*4 + '<div class="entry_content">'
for line in content: for line in content:
if no_break.match(line): if no_break.match(line):
print ' ' + line.strip() print tab*5 + line.strip()
else: else:
print ' ' + line.strip() + '<br />' print tab*5 + line.strip() + '<br />'
print ' </div>' print tab*4 + '</div>'
print ' <div class="entry_footer"></div>' print tab*4 + '<div class="entry_footer"></div>'
print ' <div class="entry_border_left"></div>' print tab*4 + '<div class="entry_border_left"></div>'
print ' <div class="entry_border_right"></div>' print tab*4 + '<div class="entry_border_right"></div>'
print ' <div class="entry_border_top"></div>' print tab*4 + '<div class="entry_border_top"></div>'
print ' <div class="entry_border_bottom"></div>' print tab*4 + '<div class="entry_border_bottom"></div>'
# Comments... # Comments...
# ... are shown when post_display and comments_file isn't false # ... are shown when post_display and comments_file isn't false
@ -507,10 +505,10 @@ else:
if comments_file: if comments_file:
comments_file = glob.glob(entries_dir + title + '.comments') comments_file = glob.glob(entries_dir + title + '.comments')
comments_content = open(comments_file[0], "r") comments_content = open(comments_file[0], "r")
print ' </div>' print tab*3 + '</div>'
print ' </div>' print tab*2 + '</div>'
print '' print ''
print ' <div class="comments">' print tab*2 + '<div class="comments">'
notfirstline = 0 # Ugly fix for closing comment containers notfirstline = 0 # Ugly fix for closing comment containers
label_count = 0 label_count = 0
@ -518,83 +516,83 @@ else:
for line in comments_content: for line in comments_content:
if line_start_hyphen.match(line): if line_start_hyphen.match(line):
if notfirstline == 1: if notfirstline == 1:
print ' </div>' print tab*4 + '</div>'
print ' </div>' print tab*3 + '</div>'
notfirstline = 0; notfirstline = 0;
print ' <div class="comment">' print tab*3 + '<div class="comment">'
#Label for each comment #Label for each comment
label_count += 1 label_count += 1
print ' <a name="' + str(label_count) + '"></a>' print tab*4 + '<a name="' + str(label_count) + '"></a>'
print ' <div class="comment_author">' + line.split(".", 1)[1].strip() + '</div>' print tab*4 + '<div class="comment_author">' + line.split(".", 1)[1].strip() + '</div>'
elif line_start_plus.match(line): elif line_start_plus.match(line):
print ' <div class="comment_date">' + line.split(".", 1)[1].strip() + '</div>' print tab*4 + '<div class="comment_date">' + line.split(".", 1)[1].strip() + '</div>'
print ' <div class="comment_content">' print tab*4 + '<div class="comment_content">'
else: else:
notfirstline = 1; notfirstline = 1;
line = line.split(".", 1)[1] line = line.split(".", 1)[1]
print ' ' + line.strip() + '<br />' print tab*5 + line.strip() + '<br />'
print '' print ''
print ' </div>' print tab*4 + '</div>'
print ' </div>' print tab*3 + '</div>'
comments_content.close() comments_content.close()
else: else:
print ' </div>' print tab*3 + '</div>'
print ' </div>' print tab*2 + '</div>'
print ' <div class="comments">' print tab*2 + '<div class="comments">'
# Form for adding comments # Form for adding comments
if comments == "True": if comments == "True":
random_int_a = random.randint(1,9) random_int_a = random.randint(1,9)
random_int_b = random.randint(1,9) random_int_b = random.randint(1,9)
cquizv = random_int_a + random_int_b cquizv = random_int_a + random_int_b
print ' <div class="submit_comment">' print tab*3 + '<div class="submit_comment">'
print ' <form action="" method="post">' print tab*4 + '<form action="" method="post">'
print ' <input type="hidden" name="ctitle" value="' + title + '" />' print tab*5 + '<input type="hidden" name="ctitle" value="' + title + '" />'
print ' <input type="hidden" name="cquizv" value="' + str(cquizv) + '" />' print tab*5 + '<input type="hidden" name="cquizv" value="' + str(cquizv) + '" />'
print ' <label class="submit_comment_name">' + blog_locale[6] + ':</label><input class="submit_comment_name_input" type="text" id="cname" name="cname" />' print tab*5 + '<label class="submit_comment_name">' + blog_locale[6] + ':</label><input class="submit_comment_name_input" type="text" id="cname" name="cname" />'
print ' <br /><label class="submit_comment_text">' + blog_locale[7] + ':</label><textarea class="submit_comment_textarea" id="ctext" name="ctext"></textarea>' print tab*5 + '<br /><label class="submit_comment_text">' + blog_locale[7] + ':</label><textarea class="submit_comment_textarea" id="ctext" name="ctext"></textarea>'
print ' <br /><label class="submit_comment_quiz">' + str(random_int_a) + '+' + str(random_int_b) + '=</label><input class="submit_comment_quiz_input" type="text" id="cquiz" name="cquiz" />' print tab*5 + '<br /><label class="submit_comment_quiz">' + str(random_int_a) + '+' + str(random_int_b) + '=</label><input class="submit_comment_quiz_input" type="text" id="cquiz" name="cquiz" />'
print ' <br /><input class="submit_comment_button" type="submit" id="submit" value="' + blog_locale[8] + '" />' print tab*5 + '<br /><input class="submit_comment_button" type="submit" id="submit" value="' + blog_locale[8] + '" />'
print ' </form>' print tab*4 + '</form>'
print ' </div>' print tab*3 + '</div>'
else: else:
print ' <div class="submit_border_bottom"></div>' print tab*3 + '<div class="submit_border_bottom"></div>'
print '' print ''
if comments == "True": if comments == "True":
comments_file = glob.glob(entries_dir + title + '.comments') comments_file = glob.glob(entries_dir + title + '.comments')
if not comments_file and not post_display: if not comments_file and not post_display:
print ' <div class="entry_comment">' print tab*4 + '<div class="entry_comment">'
print ' <a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + blog_locale[3] + '</a>' print tab*5 + '<a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + blog_locale[3] + '</a>'
print ' </div>' print tab*4 + '</div>'
print ' </div>' print tab*3 + '</div>'
print '' print ''
elif comments_file and not post_display: elif comments_file and not post_display:
comments_content = open(comments_file[0], "r") comments_content = open(comments_file[0], "r")
comments_counter = 0 comments_counter = 0
for line in comments_content: for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1 if line.split(".", 1)[0] == "-": comments_counter += 1
print ' <div class="entry_comment">' print tab*4 + '<div class="entry_comment">'
print ' <a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">' + blog_locale[4] + ' (' + str(comments_counter) + ')</a>' print tab*5 + '<a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">' + blog_locale[4] + ' (' + str(comments_counter) + ')</a>'
print ' </div>' print tab*4 + '</div>'
print ' </div>' print tab*3 + '</div>'
print '' print ''
comments_content.close() comments_content.close()
else: else:
print ' </div>' print tab*3 + '</div>'
print '' print ''
content.close() content.close()
entry_counter += 1 entry_counter += 1
if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist
print ' <div class="entry"><a href="?a=1">' + blog_locale[5] + '</a></div>' print tab*3 + '<div class="entry"><a href="?a=1">' + blog_locale[5] + '</a></div>'
print ' </div>' print tab*2 + '</div>'
print '' print ''
print ' </body>' print tab + '</body>'
print '</html>' print '</html>'
# vim: set tw=0 ts=4: # vim: set tw=0 ts=4: