diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index c7ffdd8..c5513c6 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -50,9 +50,14 @@ def manage_check(target, option): return if db_exists: - exec(open(tyto.post_db).read(),globals()) - if hash_chk == tyto.hash_post and not option == 'Force': - tyto.exiting("20", date_chk, True) + try: + exec(open(tyto.post_db).read(),globals()) + try: + if hash_chk == tyto.hash_post and not option == 'Force': + tyto.exiting("20", date_chk, True) + except: pass + except: pass + # Start processes file_to_string(tyto.uri_root) @@ -604,12 +609,12 @@ def create_database(): 'wip_uri = "%s%s"\n'%(srv_wip, web_uri) + \ 'www_uri = "%s%s"\n'%(srv_www, web_uri) + \ 'http_uri = "%s"\n'%tyto.web_uri + \ - 'hash_wip = ""\n' + \ - 'date_www = ""\n' + \ - 'hash_www = ""\n' + \ 'date_chk = "%s"\n'%tyto.nowdate() + \ 'hash_chk = "%s"\n'%tyto.hash_post + \ 'date_wip = ""\n' + \ + 'hash_wip = ""\n' + \ + 'date_www = ""\n' + \ + 'hash_www = ""\n' + \ '\n# Post configuration from needed tags\n' + \ 'title = "%s"\n'%title + \ 'about = "%s"\n'%about + \ diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index b790dda..9c7340a 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -232,6 +232,12 @@ def get_db_post(target): if os.path.exists(post_db): db_exists = True else : db_exists = False + # Check if null byte + if db_exists and os.stat(post_db).st_size < 1000: + os.remove(post_db) + exiting('23', post_db, False) + db_exists = False + return(db_exists) @@ -449,6 +455,33 @@ def b64(action, content, before, after): sys.exit(1) +# +# Replace in post_db +# Used for wip and publish +# to replace hash and date when done +# +def replace_in_db(post_db, process, hash_post): + file_db = open(post_db, "r") + lines = file_db.readlines() + new_file = '' + + for line in lines: + if line.startswith('hash_%s'%process): + line = line.replace(line, 'hash_%s = "%s"'%(process, hash_post)) + new_file = '%s%s\n'%(new_file, line) + elif line.startswith('date_%s'%process): + line = line.replace(line, 'date_%s = "%s"'%(process, nowdate())) + new_file = '%s%s\n'%(new_file, line) + else: + if new_file: new_file = '%s%s'%(new_file, line) + else: new_file = line + + file = open(post_db, 'w') + file.write(new_file) + file.close() + + + #================================# # Exit from program with message # #--------------------------------# @@ -467,6 +500,7 @@ def exiting(nbr, value, out): '20' : ':D Article already up-to-date on: %s'%value, '21' : ':D \033[1;32mArticle is valid\033[0;0m and ready to wip', '22' : ':? Symbols: %s \033[1;33mnot paired\033[0;0m'%value, + '23' : ':< \033[1;33mDatabase was corrupt\033[0;0m: %s'%value, '255' : ':| Maybe later...' } diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 754c943..2821494 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -96,6 +96,7 @@ def wip_article(target): # Result (temp display) print(article_bottom) + tyto.replace_in_db(tyto.post_db, 'wip', tyto.hash_post) #=================================#