From 48cfe03254c67d1ba6fa2ac0da6dca9e0814e47b Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Thu, 16 Mar 2023 16:50:02 +0100 Subject: [PATCH] Important changes in checking article DB --- src/var/lib/tyto/program/check.py | 12 +++--- src/var/lib/tyto/program/db.py | 60 ++++++++++++++++------------- src/var/lib/tyto/program/publish.py | 16 ++++---- src/var/lib/tyto/program/wip.py | 7 ++-- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 6276619..0fc7009 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -35,8 +35,7 @@ def manage_check(target): domain.domain_needed() # target needed - if not target: - logs.out("5", '', True) + if not target: logs.out("5", '', True) elif not target == 'all' \ and db.db_exists \ @@ -77,8 +76,9 @@ def check_all(): exec(open(post_db).read(),globals()) args.target = post_src.rsplit('%s/'%db.in_dir)[1] importlib.reload(db) - - if db.hash_post == db.hash_chk: + + if not db.db_exists \ + or db.hash_post == db.hash_chk: continue found = True @@ -96,6 +96,8 @@ def check_all(): # Check articles process # #------------------------# def check_process(target): + if not db.post_exists: sys.exit(1) + global post_bottom, article_bottom global post_words global date_wip, hash_wip, date_www, hash_www, post_bottom @@ -104,7 +106,7 @@ def check_process(target): post_err = False # Set values for wip and www from DB - if db.db_exists: + if db.db_exists: date_wip = db.date_wip hash_wip = db.hash_wip date_www = db.date_www diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py index 881289c..a5f02d2 100644 --- a/src/var/lib/tyto/program/db.py +++ b/src/var/lib/tyto/program/db.py @@ -31,12 +31,12 @@ target = args.target #======================# # Settings #--------- -domain_active = False +domain_active = False incomplete_domain = False -db_exists = False -post_exists = False - -home_dir = os.path.expanduser('~') +db_exists = False +post_exists = False +db_remove = False +home_dir = os.path.expanduser('~') try: in_dir = os.getcwd() except: logs.out("13", '', True) @@ -164,36 +164,42 @@ else: # Conditions from command line # # Get some post settings fom uri # #--------------------------------# +# Domain must be valid +domain.domain_needed() + if args.target \ and args.action in args.pass_db \ and not args.target in args.pass_targets: uri_file = '%s/%s'%(in_dir, args.target) - - if not os.path.exists(uri_file): - logs.out("1", uri_file, True) - - # Get hash for uri and content file - post_exists = True - uri_id = tyto.get_filesum(uri_file, False) - hash_post = tyto.get_filesum(uri_file, True) + uri_id = tyto.get_filesum(uri_file, False) - # Domain must be valid - domain.domain_needed() - - # Set DB file for this post - post_db = '%s%s.conf'%(articles_db, uri_id) - if not os.path.exists(post_db): + # DB + post_db = '%s%s.conf'%(articles_db, uri_id) + if os.path.exists(post_db): + db_exists = True + else: db_exists = False - else: - if os.stat(post_db).st_size < 1000: - os.remove(post_db) + + # Article + if os.path.exists(uri_file): + post_exists = True + hash_post = tyto.get_filesum(uri_file, True) + else: + post_exists = False + logs.out("1", uri_file, False) + + # + if db_exists: + if not post_exists: + db_remove = True + elif os.stat(post_db).st_size < 1000: + db_remove = True logs.out('23', post_db, False) + + if db_remove: + os.remove(post_db) db_exists = False else: - db_exists = True - - # Load post database - if db_exists: - exec(open(post_db).read(),globals()) + exec(open(post_db).read(),globals()) diff --git a/src/var/lib/tyto/program/publish.py b/src/var/lib/tyto/program/publish.py index e762804..ea447d6 100644 --- a/src/var/lib/tyto/program/publish.py +++ b/src/var/lib/tyto/program/publish.py @@ -33,12 +33,12 @@ def manage_publish(target): #----------------------------------------- if target in args.pass_targets: do = { - 'all' : create_all, + 'all' : publish_all, 'sidebar' : html.create_sidebar, 'navbar' : html.create_navbar, 'metas' : html.create_user_metas, 'footer' : html.create_user_footer, - 'template' : create_template, + 'template' : publish_template, 'stats' : stats.manage_stats } @@ -46,8 +46,9 @@ def manage_publish(target): return # Database must exists... - if not db.db_exists: - logs.out("25", db.uri_file, True) + if not target: logs.out("5", '', True) + if not db.post_exists: sys.exit(1) + if not db.db_exists: logs.out("25", db.uri_file, True) # Publish in www server an article @@ -104,7 +105,7 @@ def replace_line_pub(): #================================# # Publish template in www server # #--------------------------------# -def create_template(option): +def publish_template(option): print( \ '! Note:\n', ' - footer, sidebar, metas, navbar\n', @@ -156,7 +157,7 @@ def create_template(option): #============================================# # Option 'all' to publish again, based on DB # #--------------------------------------------# -def create_all(option): +def publish_all(option): ask = '' try: ask = input(" ├ Publish again all already published articles ? ") @@ -178,7 +179,8 @@ def create_all(option): importlib.reload(db) # Conditions to publish - if not db.hash_www: + if not db.db_exists \ + or not db.hash_www: continue print(':> [%s] | %s'%(db.title, db.post_src)) diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 284541f..8e2d464 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -17,7 +17,7 @@ #********************************************************************** -import os, re, shutil, importlib +import os, re, sys, shutil, importlib import logs, args, db, tyto, html, domain, stats @@ -50,8 +50,9 @@ def manage_wip(target): # Per article with target #------------------------ - if not target: logs.out("5", '', True) - if not db.db_exists: logs.out("25", db.uri_file, True) + if not target: logs.out("5", '', True) + if not db.post_exists: sys.exit(1) + if not db.db_exists: logs.out("25", db.uri_file, True) # Exit if article has changed if db.hash_chk != db.hash_post: