From 337fee3c8ce60223ee11d783b21fc3570590a627 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Tue, 7 Mar 2023 13:05:47 +0100 Subject: [PATCH] some new "try" and fixes --- src/var/lib/tyto/program/tyto.py | 72 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index b2e12cc..027af3f 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -131,11 +131,11 @@ titles_tags = ('#1 ', '#2 ', '#3 ', '#4 ', '#5 ', '#6 ') # Tags for quote quote_tags = [ - ('_cite:', 'author'), - ('_date:', 'date'), - ('_link:', 'link'), - ('_book:', 'book'), - ('_lang:', 'lang') +('_cite:', 'author'), +('_date:', 'date'), +('_link:', 'link'), +('_book:', 'book'), +('_lang:', 'lang') ] # Tags to check in header in content _TAG @@ -154,7 +154,7 @@ def get_filesum(path, src): file_sum = blake2b(digest_size=4) if src: file_sum.update(open(path, 'rb').read()) - else : file_sum.update(path.encode()) + else: file_sum.update(path.encode()) return file_sum.hexdigest() @@ -182,13 +182,16 @@ def edit_file(edit_file): if not os.path.exists(edit_file): logs.out("1", edit_file, True) - file_edit = subprocess.run( - [ - '/usr/bin/nano', - '--linenumbers', - edit_file - ] - ) + try: + file_edit = subprocess.run( + [ + '/usr/bin/nano', + '--linenumbers', + edit_file + ] + ) + except: + logs.out("1", "/usr/bin/nano", True) #=================# @@ -304,12 +307,14 @@ def protect_icodes(post_bottom, article_bottom): def protect_bcodes_quotes(process, post_bottom, article_bottom): global protect_article global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB - in_bcode = in_quote = False + + in_bcode = in_quote = False + end_bcode = end_quote = False protect_article = '' - temp_article = article_bottom - nbr_titles = nbr_bcodes = nbr_quotes = 0 - bcode = quote = '' - end_bcode = end_quote = False + temp_article = article_bottom + nbr_titles = nbr_bcodes = nbr_quotes = 0 + bcode = quote = '' + for line in post_bottom: # Bcode @@ -379,6 +384,7 @@ def protect_bcodes_quotes(process, post_bottom, article_bottom): def b64(action, content, before, after): if action == 'Encode': global b64_content + b64_base64 = '' content_bytes = content.encode("utf8") base64_bytes = base64.b64encode(content_bytes) @@ -387,6 +393,7 @@ def b64(action, content, before, after): elif action == 'Decode': global src_content + src_content = '' content_bytes = content.encode("utf8") base64_bytes = base64.b64decode(content_bytes) @@ -404,8 +411,12 @@ def b64(action, content, before, after): # 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() + try: + file_db = open(post_db, "r") + lines = file_db.readlines() + except: + logs.out("1", post_db, True) + new_file = '' for line in lines: @@ -419,9 +430,12 @@ def replace_in_db(post_db, process, hash_post): 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() + try: + file = open(post_db, 'w') + file.write(new_file) + file.close() + except: + logs.out("1", post_db, True) #===================================# @@ -437,7 +451,13 @@ def files_to_srv(server): # Create folder and subfolders f_uri = uri.split("/")[-1] f_uri = uri.rsplit(f_uri)[0] - os.makedirs('%s%s'%(f_dst, f_uri), exist_ok=True) + try: + os.makedirs('%s%s'%(f_dst, f_uri), exist_ok=True) + except: + logs.out('4', '%s%s'%(f_dst, f_uri), True) - shutil.copy2(f_src, f_dst) - logs.out("33", f_dst, False) + try: + shutil.copy2(f_src, f_dst) + logs.out("33", f_dst, False) + except: + logs.out('4', f_dst, True)