some new "try" and fixes

This commit is contained in:
Cyrille L 2023-03-07 13:05:47 +01:00
parent 616fed7a8e
commit 337fee3c8c
1 changed files with 46 additions and 26 deletions

View File

@ -131,11 +131,11 @@ titles_tags = ('#1 ', '#2 ', '#3 ', '#4 ', '#5 ', '#6 ')
# Tags for quote # Tags for quote
quote_tags = [ quote_tags = [
('_cite:', 'author'), ('_cite:', 'author'),
('_date:', 'date'), ('_date:', 'date'),
('_link:', 'link'), ('_link:', 'link'),
('_book:', 'book'), ('_book:', 'book'),
('_lang:', 'lang') ('_lang:', 'lang')
] ]
# Tags to check in header in content _TAG # Tags to check in header in content _TAG
@ -154,7 +154,7 @@ def get_filesum(path, src):
file_sum = blake2b(digest_size=4) file_sum = blake2b(digest_size=4)
if src: file_sum.update(open(path, 'rb').read()) 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() return file_sum.hexdigest()
@ -182,13 +182,16 @@ def edit_file(edit_file):
if not os.path.exists(edit_file): if not os.path.exists(edit_file):
logs.out("1", edit_file, True) logs.out("1", edit_file, True)
file_edit = subprocess.run( try:
[ file_edit = subprocess.run(
'/usr/bin/nano', [
'--linenumbers', '/usr/bin/nano',
edit_file '--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): def protect_bcodes_quotes(process, post_bottom, article_bottom):
global protect_article global protect_article
global nbr_titles, nbr_bcodes, nbr_quotes # Stats for DB 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 = '' protect_article = ''
temp_article = article_bottom temp_article = article_bottom
nbr_titles = nbr_bcodes = nbr_quotes = 0 nbr_titles = nbr_bcodes = nbr_quotes = 0
bcode = quote = '' bcode = quote = ''
end_bcode = end_quote = False
for line in post_bottom: for line in post_bottom:
# Bcode # Bcode
@ -379,6 +384,7 @@ def protect_bcodes_quotes(process, post_bottom, article_bottom):
def b64(action, content, before, after): def b64(action, content, before, after):
if action == 'Encode': if action == 'Encode':
global b64_content global b64_content
b64_base64 = '' b64_base64 = ''
content_bytes = content.encode("utf8") content_bytes = content.encode("utf8")
base64_bytes = base64.b64encode(content_bytes) base64_bytes = base64.b64encode(content_bytes)
@ -387,6 +393,7 @@ def b64(action, content, before, after):
elif action == 'Decode': elif action == 'Decode':
global src_content global src_content
src_content = '' src_content = ''
content_bytes = content.encode("utf8") content_bytes = content.encode("utf8")
base64_bytes = base64.b64decode(content_bytes) base64_bytes = base64.b64decode(content_bytes)
@ -404,8 +411,12 @@ def b64(action, content, before, after):
# to replace hash and date when done # # to replace hash and date when done #
#------------------------------------# #------------------------------------#
def replace_in_db(post_db, process, hash_post): def replace_in_db(post_db, process, hash_post):
file_db = open(post_db, "r") try:
lines = file_db.readlines() file_db = open(post_db, "r")
lines = file_db.readlines()
except:
logs.out("1", post_db, True)
new_file = '' new_file = ''
for line in lines: 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) if new_file: new_file = '%s%s'%(new_file, line)
else: new_file = line else: new_file = line
file = open(post_db, 'w') try:
file.write(new_file) file = open(post_db, 'w')
file.close() 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 # Create folder and subfolders
f_uri = uri.split("/")[-1] f_uri = uri.split("/")[-1]
f_uri = uri.rsplit(f_uri)[0] 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) try:
logs.out("33", f_dst, False) shutil.copy2(f_src, f_dst)
logs.out("33", f_dst, False)
except:
logs.out('4', f_dst, True)