Important changes in checking article DB

This commit is contained in:
Cyrille L 2023-03-16 16:50:02 +01:00
parent 3e736f8832
commit 48cfe03254
4 changed files with 53 additions and 42 deletions

View File

@ -35,8 +35,7 @@ def manage_check(target):
domain.domain_needed() domain.domain_needed()
# target needed # target needed
if not target: if not target: logs.out("5", '', True)
logs.out("5", '', True)
elif not target == 'all' \ elif not target == 'all' \
and db.db_exists \ and db.db_exists \
@ -78,7 +77,8 @@ def check_all():
args.target = post_src.rsplit('%s/'%db.in_dir)[1] args.target = post_src.rsplit('%s/'%db.in_dir)[1]
importlib.reload(db) importlib.reload(db)
if db.hash_post == db.hash_chk: if not db.db_exists \
or db.hash_post == db.hash_chk:
continue continue
found = True found = True
@ -96,6 +96,8 @@ def check_all():
# Check articles process # # Check articles process #
#------------------------# #------------------------#
def check_process(target): def check_process(target):
if not db.post_exists: sys.exit(1)
global post_bottom, article_bottom global post_bottom, article_bottom
global post_words global post_words
global date_wip, hash_wip, date_www, hash_www, post_bottom global date_wip, hash_wip, date_www, hash_www, post_bottom

View File

@ -31,12 +31,12 @@ target = args.target
#======================# #======================#
# Settings # Settings
#--------- #---------
domain_active = False domain_active = False
incomplete_domain = False incomplete_domain = False
db_exists = False db_exists = False
post_exists = False post_exists = False
db_remove = False
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
try: in_dir = os.getcwd() try: in_dir = os.getcwd()
except: logs.out("13", '', True) except: logs.out("13", '', True)
@ -164,36 +164,42 @@ else:
# Conditions from command line # # Conditions from command line #
# Get some post settings fom uri # # Get some post settings fom uri #
#--------------------------------# #--------------------------------#
# Domain must be valid
domain.domain_needed()
if args.target \ if args.target \
and args.action in args.pass_db \ and args.action in args.pass_db \
and not args.target in args.pass_targets: and not args.target in args.pass_targets:
uri_file = '%s/%s'%(in_dir, args.target) uri_file = '%s/%s'%(in_dir, args.target)
uri_id = tyto.get_filesum(uri_file, False)
if not os.path.exists(uri_file): # DB
logs.out("1", uri_file, True) post_db = '%s%s.conf'%(articles_db, uri_id)
if os.path.exists(post_db):
# Get hash for uri and content file db_exists = True
post_exists = True
uri_id = tyto.get_filesum(uri_file, False)
hash_post = tyto.get_filesum(uri_file, True)
# 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_exists = False
else: else:
if os.stat(post_db).st_size < 1000: db_exists = False
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) logs.out('23', post_db, False)
if db_remove:
os.remove(post_db)
db_exists = False db_exists = False
else: else:
db_exists = True exec(open(post_db).read(),globals())
# Load post database
if db_exists:
exec(open(post_db).read(),globals())

View File

@ -33,12 +33,12 @@ def manage_publish(target):
#----------------------------------------- #-----------------------------------------
if target in args.pass_targets: if target in args.pass_targets:
do = { do = {
'all' : create_all, 'all' : publish_all,
'sidebar' : html.create_sidebar, 'sidebar' : html.create_sidebar,
'navbar' : html.create_navbar, 'navbar' : html.create_navbar,
'metas' : html.create_user_metas, 'metas' : html.create_user_metas,
'footer' : html.create_user_footer, 'footer' : html.create_user_footer,
'template' : create_template, 'template' : publish_template,
'stats' : stats.manage_stats 'stats' : stats.manage_stats
} }
@ -46,8 +46,9 @@ def manage_publish(target):
return return
# Database must exists... # Database must exists...
if not db.db_exists: if not target: logs.out("5", '', True)
logs.out("25", db.uri_file, 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 # Publish in www server an article
@ -104,7 +105,7 @@ def replace_line_pub():
#================================# #================================#
# Publish template in www server # # Publish template in www server #
#--------------------------------# #--------------------------------#
def create_template(option): def publish_template(option):
print( \ print( \
'! Note:\n', '! Note:\n',
' - footer, sidebar, metas, navbar\n', ' - footer, sidebar, metas, navbar\n',
@ -156,7 +157,7 @@ def create_template(option):
#============================================# #============================================#
# Option 'all' to publish again, based on DB # # Option 'all' to publish again, based on DB #
#--------------------------------------------# #--------------------------------------------#
def create_all(option): def publish_all(option):
ask = '' ask = ''
try: try:
ask = input(" ├ Publish again all already published articles ? ") ask = input(" ├ Publish again all already published articles ? ")
@ -178,7 +179,8 @@ def create_all(option):
importlib.reload(db) importlib.reload(db)
# Conditions to publish # Conditions to publish
if not db.hash_www: if not db.db_exists \
or not db.hash_www:
continue continue
print(':> [%s] | %s'%(db.title, db.post_src)) print(':> [%s] | %s'%(db.title, db.post_src))

View File

@ -17,7 +17,7 @@
#********************************************************************** #**********************************************************************
import os, re, shutil, importlib import os, re, sys, shutil, importlib
import logs, args, db, tyto, html, domain, stats import logs, args, db, tyto, html, domain, stats
@ -50,8 +50,9 @@ def manage_wip(target):
# Per article with target # Per article with target
#------------------------ #------------------------
if not target: logs.out("5", '', True) if not target: logs.out("5", '', True)
if not db.db_exists: logs.out("25", db.uri_file, 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 # Exit if article has changed
if db.hash_chk != db.hash_post: if db.hash_chk != db.hash_post: