Bug corrections

This commit is contained in:
Phyks 2013-10-22 23:42:21 +02:00
parent 548ad16f7b
commit b2bef345f2
2 changed files with 37 additions and 28 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*~ *~
*.swp *.swp
blog/

View File

@ -135,7 +135,7 @@ def replace_tags(article, search_list, replace_list):
# Set locale # Set locale
locale.set_locale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
# ======================== # ========================
@ -166,6 +166,8 @@ for opt, arg in opts:
# Set parameters with params file # Set parameters with params file
search_list = [] search_list = []
replace_list = [] replace_list = []
months = ["January", "February", "March", "April", "May", "Juin", "July",
"August", "September", "October", "November", "December"]
try: try:
with open("raw/params", "r") as params_fh: with open("raw/params", "r") as params_fh:
params = {} params = {}
@ -174,9 +176,11 @@ try:
continue continue
option, value = line.split("=", 1) option, value = line.split("=", 1)
if option == "SEARCH": if option == "SEARCH":
search_list = value.strip().split(",") search_list = [i.strip() for i in value.split(",")]
elif option == "REPLACE": elif option == "REPLACE":
replace_list = value.strip().split(",") replace_list = [i.strip() for i in value.split(",")]
elif option == "MONTHS":
months = [i.strip() for i in value.split(",")]
else: else:
params[option.strip()] = value.strip() params[option.strip()] = value.strip()
@ -360,8 +364,7 @@ for filename in added_files:
for filename in modified_files: for filename in modified_files:
try: try:
with open(filename, 'r') as fh: tags = get_tags(filename)
tags = get_tags(fh)
except IOError: except IOError:
sys.exit("[ERROR] Unable to open file "+filename[4:]+".") sys.exit("[ERROR] Unable to open file "+filename[4:]+".")
@ -392,21 +395,22 @@ for filename in modified_files:
print("[INFO] (TAGS) Deleted tag " + print("[INFO] (TAGS) Deleted tag " +
tag[:tag.index(".tmp")]+" in modified article " + tag[:tag.index(".tmp")]+" in modified article " +
filename[4:]+".") filename[4:]+".")
else:
try:
os.unlink(tag)
print("[INFO] (TAGS) No more article with tag " +
tag[8:-4]+", deleting it.")
except FileNotFoundError:
print("[INFO] (TAGS) "+tag+" was found to be empty "
"but there was an error during deletion. "
"You should check manually.")
tags.remove(tag_file[9:]) tags.remove(tag_file[9:])
except IOError: except IOError:
sys.exit("[ERROR] (TAGS) An error occurred when parsing tags " sys.exit("[ERROR] (TAGS) An error occurred when parsing tags "
" of article "+filename[4:]+".") " of article "+filename[4:]+".")
if not tag_file_write:
try:
os.unlink(tag)
print("[INFO] (TAGS) No more article with tag " +
tag[8:-4]+", deleting it.")
except FileNotFoundError:
print("[INFO] (TAGS) "+tag+" was found to be empty "
"but there was an error during deletion. "
"You should check manually.")
for tag in tags: # New tags created for tag in tags: # New tags created
try: try:
auto_dir("gen/tags/"+tag+".tmp") auto_dir("gen/tags/"+tag+".tmp")
@ -500,6 +504,8 @@ for filename in added_files+modified_files:
date_readable = ("Le "+date[0:2]+"/"+date[2:4]+"/"+date[4:8] + date_readable = ("Le "+date[0:2]+"/"+date[2:4]+"/"+date[4:8] +
" à "+date[9:11]+":"+date[11:13]) " à "+date[9:11]+":"+date[11:13])
day_aside = date[0:2]
month_aside = months[int(date[2:4]) - 1]
# Write generated HTML for this article in gen / # Write generated HTML for this article in gen /
article = replace_tags(article, search_list, replace_list) article = replace_tags(article, search_list, replace_list)
@ -507,9 +513,12 @@ for filename in added_files+modified_files:
auto_dir("gen/"+filename[4:-5]+".gen") auto_dir("gen/"+filename[4:-5]+".gen")
with open("gen/"+filename[4:-5]+".gen", 'w') as article_file: with open("gen/"+filename[4:-5]+".gen", 'w') as article_file:
article_file.write("<article>\n" article_file.write("<article>\n"
"\t<nav class=\"aside_article\"></nav>\n" "\t<aside class=\"aside_article\">\n"
"\t\t<p class=\"day\">"+day_aside+"</p>\n"
"\t\t<p class=\"month\">"+month_aside+"</p>\n"
"\t</aside>\n"
"\t<div class=\"article\">\n" "\t<div class=\"article\">\n"
"\t\t<h1>"+title+"</h1>\n" "\t\t<h1 class=\"article_title\">"+title+"</h1>\n"
"\t\t"+article+"\n" "\t\t"+article+"\n"
"\t\t<p class=\"date\">"+date_readable+"</p>\n" "\t\t<p class=\"date\">"+date_readable+"</p>\n"
"\t</div>\n" "\t</div>\n"
@ -520,13 +529,12 @@ for filename in added_files+modified_files:
"article "+filename[4:]+".") "article "+filename[4:]+".")
# Starting to generate header file (except title) # Starting to generate header file (except title)
tags_header = "<ul>" tags_header = ""
for tag in tags_full_list: for tag in tags_full_list:
tags_header += "<li>" tags_header += "<div class=\"categories\">"
tags_header += ("<a href=\""+params["BLOG_URL"]+tag[4:-4]+".html\">" + tags_header += "<img alt=\"test\" src=\"tags/test.png\"/>"
tag[9:-4]+"</a>") tags_header += ("<span class=\"popup\">"+tag[9:-4]+"</span>")
tags_header += "</li>" tags_header += "</div>"
tags_header += "</ul>"
try: try:
with open("raw/header.html", "r") as header_fh: with open("raw/header.html", "r") as header_fh:
header = header_fh.read() header = header_fh.read()
@ -535,7 +543,7 @@ except IOError:
header = header.replace("@tags", tags_header, 1) header = header.replace("@tags", tags_header, 1)
header = header.replace("@blog_url", params["BLOG_URL"], 1) header = header.replace("@blog_url", params["BLOG_URL"], 1)
articles_header = "<ul>" articles_header = "<ul id=\"last_articles\">"
articles_index = "" articles_index = ""
rss = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" rss = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@ -691,7 +699,7 @@ for article in added_files+modified_files:
auto_dir("blog/"+article[4:]) auto_dir("blog/"+article[4:])
with open("blog/"+article[4:], "w") as article_fh: with open("blog/"+article[4:], "w") as article_fh:
article_fh.write(content) article_fh.write(content)
print("[INFO] (GEN ARTICLES) HTML file generated in blog dir for" print("[INFO] (GEN ARTICLES) HTML file generated in blog dir for "
"article "+article[4:]+".") "article "+article[4:]+".")
except IOError: except IOError:
sys.exit("[ERROR] Unable to write blog/"+article[4:]+" file.") sys.exit("[ERROR] Unable to write blog/"+article[4:]+" file.")