diff --git a/.gitignore b/.gitignore index b72f9be..1cae0ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.swp +blog/ diff --git a/pre-commit.py b/pre-commit.py index 2a3274f..2a555e9 100755 --- a/pre-commit.py +++ b/pre-commit.py @@ -11,9 +11,9 @@ # ----------------------------------------------------------------------------- # "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42): # Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice -# you can do whatever you want with this stuff (and you can also do whatever -# you want with this stuff without retaining it, but that's not cool...). If -# we meet some day, and you think this stuff is worth it, you can buy me a +# you can do whatever you want with this stuff (and you can also do whatever +# you want with this stuff without retaining it, but that's not cool...). If +# we meet some day, and you think this stuff is worth it, you can buy me a # beer soda in return. # Phyks # ---------------------------------------------------------------------------- @@ -135,7 +135,7 @@ def replace_tags(article, search_list, replace_list): # 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 search_list = [] replace_list = [] +months = ["January", "February", "March", "April", "May", "Juin", "July", + "August", "September", "October", "November", "December"] try: with open("raw/params", "r") as params_fh: params = {} @@ -174,9 +176,11 @@ try: continue option, value = line.split("=", 1) if option == "SEARCH": - search_list = value.strip().split(",") + search_list = [i.strip() for i in value.split(",")] 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: params[option.strip()] = value.strip() @@ -360,8 +364,7 @@ for filename in added_files: for filename in modified_files: try: - with open(filename, 'r') as fh: - tags = get_tags(fh) + tags = get_tags(filename) except IOError: sys.exit("[ERROR] Unable to open file "+filename[4:]+".") @@ -392,21 +395,22 @@ for filename in modified_files: print("[INFO] (TAGS) Deleted tag " + tag[:tag.index(".tmp")]+" in modified article " + 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:]) + except IOError: sys.exit("[ERROR] (TAGS) An error occurred when parsing tags " " 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 try: 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[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 / 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") with open("gen/"+filename[4:-5]+".gen", 'w') as article_file: article_file.write("
\n" - "\t\n" + "\t\n" "\t
\n" - "\t\t

"+title+"

\n" + "\t\t

"+title+"

\n" "\t\t"+article+"\n" "\t\t

"+date_readable+"

\n" "\t
\n" @@ -520,13 +529,12 @@ for filename in added_files+modified_files: "article "+filename[4:]+".") # Starting to generate header file (except title) -tags_header = "" + tags_header += "
" + tags_header += "\"test\"" + tags_header += (""+tag[9:-4]+"") + tags_header += "
" try: with open("raw/header.html", "r") as header_fh: header = header_fh.read() @@ -535,7 +543,7 @@ except IOError: header = header.replace("@tags", tags_header, 1) header = header.replace("@blog_url", params["BLOG_URL"], 1) -articles_header = "