From 3e736f88324233e3ae52dc90d676f1f59ec5f1ec Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Thu, 16 Mar 2023 14:55:02 +0100 Subject: [PATCH] added check all argument --- src/var/lib/tyto/program/check.py | 107 +++++++++++++++++++++--------- src/var/lib/tyto/program/logs.py | 5 +- src/var/lib/tyto/program/wip.py | 1 - 3 files changed, 78 insertions(+), 35 deletions(-) diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 260c201..6276619 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -21,9 +21,9 @@ import sys, os, re, datetime from datetime import datetime from time import gmtime, strftime -import time +import time, importlib -import logs, db, tyto +import args, logs, db, domain, tyto post_err = False @@ -32,39 +32,83 @@ post_err = False # Start checking article # #-------------------------#-------------------------------------------- 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 \ + and db.hash_chk == db.hash_post: + logs.out("20", db.date_chk, False) + ask = ' ├ Check again this article ? ' + try: + res = input(ask) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) + if not res in ['y', 'Y']: + return + check_process(target) + + elif target == "all": + check_all() + + else: + check_process(target) - global date_wip, hash_wip, date_www, hash_www, post_bottom - date_wip = hash_wip = date_www = hash_www = '' + if post_err and not target == 'all': + logs.out("7", '', True) + - # Article has DB - if db.db_exists: - # ... but domain needs to be active and ready - if not db.domain_active: sys.exit(1) - if db.incomplete_domain: sys.exit(1) +#==============================================# +# Argument all # +# check all realdy checkded articles # +# but check only if article source has changed # +#----------------------------------------------# +def check_all(): + found = False - # ... was already check and not changed - if db.hash_chk == db.hash_post: - logs.out("20", db.date_chk, False) - ask = ' ├ Check again this article ? ' - try: - res = input(ask) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - if not res in ['y', 'Y']: return + for post_db in os.listdir(db.articles_db): + if post_db.endswith('.conf'): + # Load DB + post_db = '%s%s'%(db.articles_db, post_db) + 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: + continue + + found = True + print(':> [%s] | %s'%(db.title, db.post_src)) + check_process(args.target) + + if post_err: + logs.out("44", args.target, False) + + if not found: + logs.out("28", '(check)', True) - # ... Set values for wip and www from DB + +#========================# +# Check articles process # +#------------------------# +def check_process(target): + global post_bottom, article_bottom + global post_words + global date_wip, hash_wip, date_www, hash_www, post_bottom + global post_err + date_wip = hash_wip = date_www = hash_www = '' + post_err = False + + # Set values for wip and www from DB + if db.db_exists: date_wip = db.date_wip hash_wip = db.hash_wip date_www = db.date_www - hash_www = db.hash_wip - - # Set variables - #-------------- - global post_bottom, article_bottom - global post_words + hash_www = db.hash_www # Get extension from target, set short uris ext_src = os.path.splitext(target) @@ -127,7 +171,8 @@ def manage_check(target): if post_err: if db.db_exists and os.path.exists(db.post_db): os.remove(db.post_db) - logs.out("7", '', True) + #logs.out("7", '', False) + return # No error create_database() @@ -787,12 +832,10 @@ def create_database(): 'stat_quotes = %d\n'%nbr_quotes + \ 'stat_lists = %d\n'%post_lists - ''' - - ''' + database = '%s\n%s'%(database, db_stats) tyto.set_file(db.post_db, 'new', database) - logs.out("21", '', True) + logs.out("21", '', False) #=====================# diff --git a/src/var/lib/tyto/program/logs.py b/src/var/lib/tyto/program/logs.py index 1180267..937c4c1 100644 --- a/src/var/lib/tyto/program/logs.py +++ b/src/var/lib/tyto/program/logs.py @@ -36,8 +36,8 @@ def out(nbr, value, out): '4' : ':< %sUnable to create file%s: %s'%(CR, CS, value), '5' : ':< %sUnused argument%s: [file]'%(CR, CS), '6' : ':< %sUnused "%s"%s in article'%(CR, value, CS), - '7' : ':< Article %snot valid yet%s'%(CR, CS), - '8' : ':< %sNot paired%s: %s'%(CR, CS, value), + '7' : ':< Article %snot yet valid%s'%(CR, CS), + '8' : ':< %sNot paired%s %s'%(CR, CS, value), '9' : ':< Article %shas changed%s. Check it first'%(CR, CS), '10' : ':< %sUnused domain configuration%s: %s'%(CR, CS, value), '11' : ':< %sUnused argument%s: %s'%(CR, CS, value), @@ -64,6 +64,7 @@ def out(nbr, value, out): '41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value), '42' : ':D %sActive%s domain "%s"'%(CG, CS, value), '43' : ':? %sNo domain%s configured here: %s'%(CY, CS, value), + '44' : ':! %sCheck again manually%s "tyto check %s"'%(CY, CS, value), '51' : ':? %sIncomplete data%s: %s'%(CY, CS, value), '255' : ';) Maybe later...' } diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 2f55292..284541f 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -101,7 +101,6 @@ def wip_all(process): logs.out("25", db.uri_file, False) continue wip_article(db.post_src) - return #===================#