post_db in db.py. Working check, wip, publish, but some works to do arount.

This commit is contained in:
Cyrille L 2023-02-07 14:55:58 +01:00
parent 4d604acb91
commit 796a580507
9 changed files with 405 additions and 270 deletions

View File

@ -60,6 +60,11 @@ arguments = (
'again' 'again'
) )
pass_actions = (
'domain'
)
option = '' option = ''
target = '' target = ''

View File

@ -26,8 +26,6 @@ import time
import logs, db, tyto import logs, db, tyto
post_err = False post_err = False
date_wip = hash_wip = date_www = hash_www = ''
#=========================# #=========================#
# Manage Argument 'check' # # Manage Argument 'check' #
@ -37,39 +35,80 @@ def manage_check(target, option):
# target needed # target needed
if not target: logs.out("5", '', True) if not target: logs.out("5", '', True)
global post_bottom, article_bottom
global post_words
# Article exists + has DB ?
db_exists = tyto.get_db_post(target)
# Manage option # Manage option
#--------------
if option == 'Edit': if option == 'Edit':
tyto.edit_file(tyto.uri_file) tyto.edit_file(db.uri_file)
return return
elif option == 'Show': elif option == 'Show':
article_raw = open(tyto.uri_file).read() article_raw = open(db.uri_file).read()
for line in article_raw.rsplit('\n'): for line in article_raw.rsplit('\n'):
print(line) print(line)
return return
if db_exists:
# Just read the DB from command # Just read the DB from command
if option == 'DB': elif option == 'DB':
article_db = open(tyto.post_db).read() if db.db_exists:
article_db = open(db.post_db).read()
for line in article_db.rsplit('\n'): for line in article_db.rsplit('\n'):
print(line) print(line)
return return
else:
logs.out("25", db.uri_file, True)
try: # Article has DB
exec(open(tyto.post_db).read(),globals()) if db.db_exists:
if hash_chk == tyto.hash_post and not option == 'Force': # ... but domain needs to be active and ready
logs.out("20", date_chk, True) if not db.domain_active: sys.exit(1)
finally: pass if db.incomplete_domain: sys.exit(1)
# Start processes # ... was already check and not changed
file_to_string(tyto.uri_file) if db.hash_chk == db.hash_post and not option == 'Force':
logs.out("20", db.date_chk, True)
# ... Set values for wip and www from DB
global date_wip, hash_wip, date_www, hash_www
date_wip = hash_wip = date_www = hash_www = ''
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
# Get extension from target, set short uris
ext_src = os.path.splitext(target)
# Get uri after articles/ (no starting / in value)
global src_post_short_uri, srv_post_short_uri
global srv_post_wip_uri, srv_post_www_uri
src_post_short_uri = db.uri_file.rsplit(db.domain_articles)[1]
srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html')
srv_post_wip_uri = db.srv_wip + srv_post_short_uri
srv_post_www_uri = db.srv_www + srv_post_short_uri
# Get sub_uri for HTML
global sub_uri
sub_uri = db.uri_file.rsplit('articles/')[1]
sub_nbr = sub_uri.count('/')
if sub_nbr == 0 : sub_uri = './'
else: sub_uri = sub_nbr * '../'
# Set HTTP link for wip and www
global http_www, http_wip
if srv_post_short_uri.endswith('index.html'):
http_www = "%s/"%db.domain_www_url
http_wip = '%s/'%db.domain_wip_url
else:
http_www = "%s%s"%(db.domain_www_url, srv_post_short_uri)
http_wip = '%s%s'%(db.domain_wip_url, srv_post_short_uri)
# Start checking processes
#-------------------------
file_to_string(db.uri_file)
# Specific to inline-code: check markers on same line # Specific to inline-code: check markers on same line
check_icodes(article.rsplit('\n')) check_icodes(article.rsplit('\n'))
@ -614,7 +653,7 @@ def check_content(post_bottom):
ptag = '_%s'%htag ptag = '_%s'%htag
if line.startswith(ptag): if line.startswith(ptag):
ptag_set = line.rsplit(':', 1)[1].lstrip() # Get set tag ptag_set = line.rsplit(':', 1)[1].lstrip().rsplit(' ')[0]
if ptag_set in set_tags: continue if ptag_set in set_tags: continue
for hline in post_header: for hline in post_header:
if re.search(r"^%s\s+%s$"%(htag,ptag_set), hline): if re.search(r"^%s\s+%s$"%(htag,ptag_set), hline):
@ -641,19 +680,19 @@ def check_content(post_bottom):
#-----------------------------------------------# #-----------------------------------------------#
def create_database(): def create_database():
database = '# Post Configuration for Tyto\n' + \ database = '# Post Configuration for Tyto\n' + \
'post_id = "%s"\n'%tyto.uri_id + \ 'post_id = "%s"\n'%db.uri_id + \
'post_src = "%s"\n'%tyto.uti_file + \ 'post_src = "%s"\n'%db.uri_file + \
'post_wip = "%s"\n'%tyto.srv_post_wip_uri + \ 'post_wip = "%s"\n'%srv_post_wip_uri + \
'post_www = "%s"\n'%tyto.srv_post_www_uri + \ 'post_www = "%s"\n'%srv_post_www_uri + \
'\n' + \ '\n' + \
'short_src = "%s"\n'%tyto.src_post_short_uri + \ 'short_src = "%s"\n'%src_post_short_uri + \
'short_srv = "%s"\n'%tyto.srv_post_short_uri + \ 'short_srv = "%s"\n'%srv_post_short_uri + \
'sub_uri = "%s"\n'%tyto.sub_uri + \ 'sub_uri = "%s"\n'%sub_uri + \
'http_wip = "%s"\n'%tyto.http_wip + \ 'http_wip = "%s"\n'%http_wip + \
'http_www = "%s"\n'%tyto.http_www + \ 'http_www = "%s"\n'%http_www + \
'\n' + \ '\n' + \
'date_chk = "%s"\n'%tyto.nowdate() + \ 'date_chk = "%s"\n'%tyto.nowdate() + \
'hash_chk = "%s"\n'%tyto.hash_post + \ 'hash_chk = "%s"\n'%db.hash_post + \
'date_wip = "%s"\n'%date_wip + \ 'date_wip = "%s"\n'%date_wip + \
'hash_wip = "%s"\n'%hash_wip + \ 'hash_wip = "%s"\n'%hash_wip + \
'date_www = "%s"\n'%date_www + \ 'date_www = "%s"\n'%date_www + \
@ -726,5 +765,5 @@ def create_database():
'stat_lists = %d\n'%post_lists 'stat_lists = %d\n'%post_lists
database = '%s\n%s'%(database, db_stats) database = '%s\n%s'%(database, db_stats)
tyto.set_file(tyto.post_db, 'new', database) tyto.set_file(db.post_db, 'new', database)
logs.out("21", '', True) logs.out("21", '', True)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Name: Tyto - Littérateur # Name: Tyto - Littérateur
# Type: DBs tools # Type: DBs tools
# Description: Search DBs and exec # Description: Search DBs (domain + post) and exec
# file: db.py # file: db.py
# Folder: /var/lib/tyto/program/ # Folder: /var/lib/tyto/program/
# By echolib (XMPP: im@echolib.re) # By echolib (XMPP: im@echolib.re)
@ -18,7 +18,7 @@
#********************************************************************** #**********************************************************************
import os, sys import os, sys
import args, logs import args, logs, tyto
# Settings # Settings
#--------- #---------
@ -39,7 +39,7 @@ domain_values = (
'domain_articles', 'domain_articles',
'domain_files', 'domain_files',
'domain_images', 'domain_images',
'domain_db', 'articles_db',
'html_db', 'html_db',
'navbars_dir', 'navbars_dir',
'navbar_load', 'navbar_load',
@ -109,8 +109,12 @@ domain_conf = '%s/tyto_domain.conf'%domain_conf
if os.path.exists(domain_conf): domain_exists = True if os.path.exists(domain_conf): domain_exists = True
else: domain_exists = False else: domain_exists = False
# Check if domain is set
#----------------------- #======================================================================
#------------------------#
# Check if domain is set #
#------------------------#
#======================================================================
stdout = '%s %s domain "%s" in %s' # Show domain status stdout = '%s %s domain "%s" in %s' # Show domain status
if domain_exists: if domain_exists:
@ -137,3 +141,38 @@ if domain_exists:
else: else:
logs.out("43", domain_conf, False) logs.out("43", domain_conf, False)
#======================================================================
#--------------------------------#
# Get post DB from target #
# Get some post settings fom uri #
#--------------------------------#
#======================================================================
if args.target:
if not sys.argv[1] in args.pass_actions:
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
uri_id = tyto.get_filesum(uri_file, False)
hash_post = tyto.get_filesum(uri_file, True)
if domain_exists and not incomplete_domain:
# 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:
if os.stat(post_db).st_size < 1000:
os.remove(post_db)
logs.out('23', post_db, False)
db_exists = False
else:
db_exists = True
# Load post database
if db_exists:
exec(open(post_db).read(),globals())

View File

@ -20,6 +20,7 @@
import os, sys, locale import os, sys, locale
import logs, db, tyto, html import logs, db, tyto, html
#==========================# #==========================#
# Manage Argument 'domain' # # Manage Argument 'domain' #
#--------------------------# #--------------------------#
@ -87,7 +88,11 @@ def create_domain(target, option):
valid_url = ('http://', 'https://') valid_url = ('http://', 'https://')
ask = '' ask = ''
try:
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url) ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not ask.startswith(valid_url): if not ask.startswith(valid_url):
logs.out("2", 'http(s)://...', True) logs.out("2", 'http(s)://...', True)
@ -113,7 +118,11 @@ def create_domain(target, option):
except: domain_wip_url = try_wip_url except: domain_wip_url = try_wip_url
ask = '' ask = ''
try:
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url) ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
isurl(ask) isurl(ask)
domain_wip_url = ask domain_wip_url = ask
@ -128,7 +137,7 @@ def create_domain(target, option):
'domain_articles = "%sarticles/"\n'%db.conf_dir + \ 'domain_articles = "%sarticles/"\n'%db.conf_dir + \
'domain_files = "%sarticles/files/"\n'%db.conf_dir + \ 'domain_files = "%sarticles/files/"\n'%db.conf_dir + \
'domain_images = "%sarticles/images/"\n'%db.conf_dir + \ 'domain_images = "%sarticles/images/"\n'%db.conf_dir + \
'domain_db = "%sarticles/"\n'%db_dir + \ 'articles_db = "%sarticles/"\n'%db_dir + \
'html_db = "%s"\n'%db_dir_html + \ 'html_db = "%s"\n'%db_dir_html + \
'navbars_dir = "%s"\n'%navbars_conf + \ 'navbars_dir = "%s"\n'%navbars_conf + \
'navbar_load = "%styto.navbar"\n'%navbars_conf + \ 'navbar_load = "%styto.navbar"\n'%navbars_conf + \
@ -152,7 +161,11 @@ def create_domain(target, option):
except: domain_srv = '/var/www' except: domain_srv = '/var/www'
ask = '' ask = ''
try:
ask = input(' ├ System server ? ("%s") '%domain_srv) ask = input(' ├ System server ? ("%s") '%domain_srv)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not os.path.exists(srv): logs.out("1", ask, True) if not os.path.exists(srv): logs.out("1", ask, True)
elif not domain_srv: logs.out("255", '', True) elif not domain_srv: logs.out("255", '', True)
@ -190,7 +203,11 @@ def create_domain(target, option):
except: domain_title = '' except: domain_title = ''
ask = '' ask = ''
try:
ask = input(' ├ Domain title ? ("%s") '%domain_title) ask = input(' ├ Domain title ? ("%s") '%domain_title)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_title = ask if ask: domain_title = ask
elif not domain_title: logs.out("255", '', True) elif not domain_title: logs.out("255", '', True)
if '"' in domain_title: if '"' in domain_title:
@ -208,7 +225,11 @@ def create_domain(target, option):
except: domain_about = '' except: domain_about = ''
ask = '' ask = ''
try:
ask = input(' ├ Domain Description ? ("%s") '%domain_about) ask = input(' ├ Domain Description ? ("%s") '%domain_about)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_about = ask if ask: domain_about = ask
elif not domain_about: logs.out("255", '', True) elif not domain_about: logs.out("255", '', True)
if '"' in domain_about: if '"' in domain_about:
@ -225,7 +246,11 @@ def create_domain(target, option):
except: domain_lang = locale.getdefaultlocale()[0].split('_')[0] except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
ask = '' ask = ''
try:
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang) ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if len(ask) == 2: domain_lang = ask if len(ask) == 2: domain_lang = ask
else: logs.out("3", ask, True) else: logs.out("3", ask, True)
@ -242,7 +267,11 @@ def create_domain(target, option):
except: domain_mail = '' except: domain_mail = ''
ask = '' ask = ''
try:
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail) ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not "@" in ask and not "." in ask: logs.out("3", ask, True) if not "@" in ask and not "." in ask: logs.out("3", ask, True)
domain_mail = ask domain_mail = ask
@ -259,7 +288,11 @@ def create_domain(target, option):
except: domain_tags = '' except: domain_tags = ''
ask = '' ask = ''
try:
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags) ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_tags = ask if ask: domain_tags = ask
elif not domain_tags: logs.out("255", '', True) elif not domain_tags: logs.out("255", '', True)
@ -274,7 +307,11 @@ def create_domain(target, option):
except: domain_logo = 'logo.png' except: domain_logo = 'logo.png'
ask = '' ask = ''
try:
ask = input(' ├ logo filename ? ("%s") '%domain_logo) ask = input(' ├ logo filename ? ("%s") '%domain_logo)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_logo = ask if ask: domain_logo = ask
tyto.set_file(db.domain_conf, False, tyto.set_file(db.domain_conf, False,
@ -290,7 +327,11 @@ def create_domain(target, option):
except: domain_license = 'CC BY-NC-SA' except: domain_license = 'CC BY-NC-SA'
ask = '' ask = ''
try:
ask = input(' ├ Domain License ? ("%s") '%domain_license) ask = input(' ├ Domain License ? ("%s") '%domain_license)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_license = ask if ask: domain_license = ask
elif not domain_license: logs.out("255", '', True) elif not domain_license: logs.out("255", '', True)
if '"' in domain_license: if '"' in domain_license:
@ -307,7 +348,11 @@ def create_domain(target, option):
except: domain_licurl = '' except: domain_licurl = ''
ask = '' ask = ''
try:
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl) ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not ask.startswith('http'): logs.out("3", ask, True) if not ask.startswith('http'): logs.out("3", ask, True)
domain_licurl = ask domain_licurl = ask
@ -323,7 +368,11 @@ def create_domain(target, option):
except: domain_css = 'tyto' except: domain_css = 'tyto'
ask = '' ask = ''
try:
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css) ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not ask.isalnum(): logs.out("3", ask, True) if not ask.isalnum(): logs.out("3", ask, True)
domain_css = ask.lower() domain_css = ask.lower()
@ -339,7 +388,11 @@ def create_domain(target, option):
except: domain_sep = "-" except: domain_sep = "-"
ask = '' ask = ''
try:
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep) ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not len(ask) == 1: logs.out("3", ask, True) if not len(ask) == 1: logs.out("3", ask, True)
domain_sep = ask domain_sep = ask
@ -355,7 +408,11 @@ def create_domain(target, option):
except: domain_relme = '' except: domain_relme = ''
ask = '' ask = ''
try:
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme) ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not ask.startswith('http'): logs.out("3", ask, True) if not ask.startswith('http'): logs.out("3", ask, True)
domain_relme = ask domain_relme = ask
@ -371,7 +428,11 @@ def create_domain(target, option):
except: sidebar_title = tyto.trans[0][tyto.n] except: sidebar_title = tyto.trans[0][tyto.n]
ask = '' ask = ''
try:
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title) ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: sidebar_title = ask if ask: sidebar_title = ask
if '"' in sidebar_title: if '"' in sidebar_title:
sidebar_title = sidebar_title.replace('"', '') sidebar_title = sidebar_title.replace('"', '')
@ -387,7 +448,11 @@ def create_domain(target, option):
except: sidebar_items = "6" except: sidebar_items = "6"
ask = '' ask = ''
try:
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items) ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: if ask:
if not ask.isdigit(): logs.out("3", ask, True) if not ask.isdigit(): logs.out("3", ask, True)
elif int(ask) in range(1,17): sidebar_items = int(ask) elif int(ask) in range(1,17): sidebar_items = int(ask)
@ -413,7 +478,11 @@ def create_domain(target, option):
for line in file.rsplit('\n'): for line in file.rsplit('\n'):
print('', line) print('', line)
try:
ask = input(' ├ Activate and prepare domain ? ') ask = input(' ├ Activate and prepare domain ? ')
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in ['y', 'Y']: if not ask in ['y', 'Y']:
tyto.set_file(db.domain_conf, False, '\ndomain_active = False') tyto.set_file(db.domain_conf, False, '\ndomain_active = False')
logs.out("255", '', True) logs.out("255", '', True)
@ -443,7 +512,6 @@ def create_domain(target, option):
# Create in _configs files # Create in _configs files
# Force will ask to create in template # Force will ask to create in template
print('') print('')
#create_sidebar(option)
html.manage_configs('sidebar', 'Force') html.manage_configs('sidebar', 'Force')
html.manage_configs('navbar', 'Force') html.manage_configs('navbar', 'Force')
html.manage_configs('metas', 'Force') html.manage_configs('metas', 'Force')
@ -535,7 +603,11 @@ def create_sidebar(option):
log = ' ├ Create file: %s'%db.sidebar_load log = ' ├ Create file: %s'%db.sidebar_load
res = '' res = ''
if os.path.exists(db.sidebar_load): if os.path.exists(db.sidebar_load):
try:
res = input(ask) res = input(ask)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(db.sidebar_load, 'new', sdb_load) tyto.set_file(db.sidebar_load, 'new', sdb_load)
@ -637,7 +709,11 @@ def create_navbar(option):
log = ' ├ Create file: %s'%db.navbar_load log = ' ├ Create file: %s'%db.navbar_load
res = '' res = ''
if os.path.exists(db.navbar_load): if os.path.exists(db.navbar_load):
try:
res = input(ask) res = input(ask)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(db.navbar_load, 'new', nvb_load) tyto.set_file(db.navbar_load, 'new', nvb_load)

View File

@ -176,7 +176,7 @@ def create_main_page(target, article_bottom):
'\n' + \ '\n' + \
' <article id="article_main">\n' + \ ' <article id="article_main">\n' + \
' <section id="article_infos">\n' + \ ' <section id="article_infos">\n' + \
'%s\n'%html_infos + \ '%s\n'%post_pub + \
' </section>\n' + \ ' </section>\n' + \
'%s\n'%article_bottom + \ '%s\n'%article_bottom + \
' </article>\n' + \ ' </article>\n' + \
@ -192,7 +192,9 @@ def create_main_page(target, article_bottom):
# when wip, and publish # # when wip, and publish #
#--------------------------------------------# #--------------------------------------------#
def create_html_infos_section(process): def create_html_infos_section(process):
global html_infos # Need to reload the DB to get last time updated
exec(open(db.post_db).read(), globals())
global post_pub
if process == 'wip': if process == 'wip':
date_raw = date_wip # <time datetime= date_raw = date_wip # <time datetime=
@ -207,7 +209,7 @@ def create_html_infos_section(process):
date_new = date_pub.rsplit('-') date_new = date_pub.rsplit('-')
date_pub = date_new[2] + '/' + date_new[1] + '/' + date_new[0] date_pub = date_new[2] + '/' + date_new[1] + '/' + date_new[0]
html_infos = '%s<p>'%(8 * ' ') + \ post_pub = '%s<p>'%(8 * ' ') + \
'<span id="article_title" title="%s">Article</span> '%( '<span id="article_title" title="%s">Article</span> '%(
title title
) + \ ) + \

View File

@ -55,6 +55,7 @@ def out(nbr, value, out):
'30' : ':? Article %snot yet wip%s: %s'%(CY, CS, value), '30' : ':? Article %snot yet wip%s: %s'%(CY, CS, value),
'31' : ':? Not included. %sMax items reached%s %s'%(CY, CS, value), '31' : ':? Not included. %sMax items reached%s %s'%(CY, CS, value),
'33' : ':D %sCreated file%s: %s'%(CG, CS, value), '33' : ':D %sCreated file%s: %s'%(CG, CS, value),
'34' : ':D Publish %sfile change%s %s'%(CG, CS, value),
'40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value), '40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value),
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value), '41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),
'42' : ':D %sActive%s domain "%s"'%(CG, CS, value), '42' : ':D %sActive%s domain "%s"'%(CG, CS, value),

View File

@ -17,28 +17,75 @@
#********************************************************************** #**********************************************************************
import db, logs, tyto import os, sys, shutil
import db, logs, html, tyto
err_pub = True # Default (do not publish)
#==============================# #==============================#
# Manage action, get post db # # Manage action, get post db #
# check if publish can be done # # check if publish can be done #
#------------------------------# #------------------------------#
def manage_publish(target, option): def manage_publish(target, option):
db_exists = tyto.get_db_post(target) err_pub = False # Default (publish)
if not db.db_exists:
logs.out("25", db.uri_file, True)
# Checking if article can be publish # Checking if article can be publish
if not db_exists: logs.out("25", tyto.uri_file, False) if not db.hash_chk:
elif not tyto.hash_chk: logs.out("25", tyto.uri_file, False) logs.out("25", db.uri_file, False)
elif not tyto.hash_wip: logs.out("30", tyto.uri_file, False) err_pub = True
elif not db.hash_wip:
logs.out("30", db.uri_file, False)
err_pub = True
if err_pub: logs.out("7", '', True) if db.hash_wip:
# wip and current article have different hash
if db.hash_post != db.hash_chk:
logs.out("25", db.uri_file, False)
err_pub = True
elif db.hash_post != db.hash_wip:
logs.out("30", db.uri_file, False)
err_pub = True
elif not os.path.exists(db.post_wip):
logs.out("1", db.post_wip, True)
if err_pub: sys.exit(1)
# Let's publish
#--------------
# Copy wip page to www page
shutil.copy2(db.post_wip, db.post_www)
logs.out("33", db.post_www, False)
# Copy files registred in article
for uri in db.uris:
f_src = '%s%s'%(db.srv_wip, uri)
f_www = '%s%s'%(db.srv_www, uri)
shutil.copy2(f_src, f_www)
logs.out("33", f_www, False)
# Replace in DB hash_wip and date_wip
tyto.replace_in_db(db.post_db, 'www', db.hash_post)
# Replace publish HTML line
replace_line_pub()
def replace_line_pub(): def replace_line_pub():
# Testing html publis # Need to reload the DB to get last time updated
print('> Testing html publish') exec(open(db.post_db).read(), globals())
wip_html_post = open(post_wip, 'r').read()
html.create_html_infos_section('publish')
new_line = html.post_pub
newfile = ''
wip_html_post = open(db.post_wip, 'r').read()
for line in wip_html_post.rsplit('\n'): for line in wip_html_post.rsplit('\n'):
if line.startswith('%s<p><span id="article_title"'%(8 * ' ')): print(line) if line.startswith('%s<p><span id="article_title"'%(8 * ' ')):
line = new_line
if not newfile: newfile = line
else: newfile = '%s\n%s'%(newfile, line)
tyto.set_file(db.post_www, 'new', newfile)
logs.out("34", '(date: %s): %s'%(date_www, db.post_www), False)

View File

@ -26,10 +26,6 @@ home_dir = os.path.expanduser('~')
in_dir = os.getcwd() in_dir = os.getcwd()
domain_conf = in_dir domain_conf = in_dir
if db.domain_exists:
db_dir = db.domain_db
# Set translations: french, english # Set translations: french, english
#---------------------------------- #----------------------------------
try: lang = domain_lang try: lang = domain_lang
@ -170,70 +166,6 @@ def set_en_date(date):
return('%s-%s-%s'%(udate[2], udate[1], udate[0])) return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
#=======================#
# Check if article file #
# Check if article DB #
#-----------------------#
def get_db_post(target):
# Check if target file exists
global uri_file
uri_file = '%s/%s'%(in_dir, target)
if not os.path.exists(uri_file):
logs.out("1", uri_file, True)
# Get extension from target, set short uris
ext_src = os.path.splitext(target)
# Get uri after articles/ (no /...)
src_noslah_uri = uri_file.rsplit(db.domain_articles)[1]
global src_post_short_uri, srv_post_short_uri
src_post_short_uri = '/' + uri_file.rsplit(db.domain_articles)[1]
srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html')
global srv_post_wip_uri, srv_post_www_uri
srv_post_wip_uri = db.srv_wip + src_noslah_uri.replace(ext_src[1], '.html')
srv_post_www_uri = db.srv_www + src_noslah_uri.replace(ext_src[1], '.html')
# Hash from content file
global hash_post
hash_post = get_filesum(uri_file, True)
# Hash from URI file
global uri_id
uri_id = get_filesum(uri_file, False) # From URI file
# Set DB file for this post
global post_db
post_db = '%s/%s.conf'%(db_dir, uri_id)
if os.path.exists(post_db): db_exists = True
else : db_exists = False
# Get sub_uri for HTML
global sub_uri
sub_uri = uri_file.rsplit('articles/')[1]
sub_nbr = sub_uri.count('/')
if sub_nbr == 0 : sub_uri = './'
else: sub_uri = sub_nbr * '../'
# Set HTTP link for wip and www
global http_www, http_wip
if srv_post_short_uri.endswith('index.html'):
http_www = "%s/"%db.domain_www_url
http_wip = '%s/'%db.domain_wip_url
else:
http_www = "%s%s"%(db.domain_www_url, srv_post_short_uri)
http_wip = '%s%s'%(db.domain_wip_url, srv_post_short_uri)
# Check if null byte
if db_exists and os.stat(post_db).st_size < 1000:
os.remove(post_db)
logs.out('23', post_db, False)
db_exists = False
return(db_exists)
#======================# #======================#
# Open and edit a file # # Open and edit a file #
#----------------------# #----------------------#

View File

@ -23,7 +23,9 @@ import logs, db, tyto, html
def manage_wip(target, option): def manage_wip(target, option):
global post_db, hash_post global post_db, hash_post
# Domain configuration must exist and active
if not db.domain_exists: return if not db.domain_exists: return
if not db.domain_active: return
#----------------------------------------- #-----------------------------------------
# Option 'Again' to wip again, based on DB # Option 'Again' to wip again, based on DB
@ -50,34 +52,26 @@ def manage_wip(target, option):
#------------------------ #------------------------
# Per article with target # Per article with target
#------------------------ #------------------------
# Article exists + has DB ? if not target: logs.out("5", '', True)
db_exists = tyto.get_db_post(target) if not db.db_exists: logs.out("25", db.uri_file, True)
target = tyto.uri_file # tyto.uri_root
if not db_exists:
logs.out("25", target, True)
# Load DB
post_db = tyto.post_db
hash_post = tyto.hash_post
exec(open(post_db).read(),globals())
# Exit if article has changed # Exit if article has changed
if hash_chk != hash_post: logs.out("9", target, True) if db.hash_chk != db.hash_post: logs.out("9", target, True)
# In any case, if Force # In any case, if Force
if option == 'Force': if option == 'Force':
wip_article(target) wip_article(db.uri_file)
return return
# Compare and check file # Compare and check file
if hash_wip != hash_chk: if db.hash_wip != db.hash_chk:
wip_article(target) wip_article(db.uri_file)
else: else:
if not os.path.exists(post_wip): if not os.path.exists(db.post_wip):
logs.out("24", '(wip article): %s'%post_wip, False) logs.out("24", '(wip article): %s'%db.post_wip, False)
wip_article(target) wip_article(db.uri_file)
else: else:
logs.out("19", date_wip, True) logs.out("19", db.date_wip, True)
#===================# #===================#
@ -117,24 +111,24 @@ def wip_article(target):
# Result (temp display) # Result (temp display)
#print(article_bottom) #print(article_bottom)
# Replace in DB hash_wip and date_wip
tyto.replace_in_db(db.post_db, 'wip', db.hash_post)
# Get article DB in html.py # Get article DB in html.py
html.set_page(post_db, target, article_bottom) html.set_page(db.post_db, db.uri_file, article_bottom)
#print(html.main_page) #print(html.main_page)
# Create wip file # Create wip file
tyto.set_file(post_wip, 'New', html.main_page) tyto.set_file(db.post_wip, 'New', html.main_page)
logs.out("33", post_wip, False) logs.out("33", db.post_wip, False)
# Copy needed file to wip # Copy needed file to wip
for uri in uris: for uri in db.uris:
f_src = '%s%s'%(db.domain_articles, uri) f_src = '%s%s'%(db.domain_articles, uri)
f_wip = '%s%s'%(db.srv_wip, uri) f_wip = '%s%s'%(db.srv_wip, uri)
shutil.copy2(f_src, f_wip) shutil.copy2(f_src, f_wip)
logs.out("33", f_wip, False) logs.out("33", f_wip, False)
# Replace in DB hash_wip and date_wip
tyto.replace_in_db(post_db, 'wip', hash_post)
#=================================# #=================================#
# Create string article from file # # Create string article from file #
@ -221,8 +215,8 @@ def wip_links():
global article_bottom global article_bottom
# Doing files, first, becase of similar marker # Doing files, first, becase of similar marker
if uniq_files > 0: if db.uniq_files > 0:
for i in range(1, uniq_files + 1): for i in range(1, db.uniq_files + 1):
file = 'file_%s'%i file = 'file_%s'%i
article_bottom = article_bottom.replace( article_bottom = article_bottom.replace(
eval(file)[0]+'+', eval(file)[1]%('_blank') eval(file)[0]+'+', eval(file)[1]%('_blank')
@ -231,8 +225,8 @@ def wip_links():
eval(file)[0], eval(file)[1]%('_self') eval(file)[0], eval(file)[1]%('_self')
) )
if uniq_links > 0: if db.uniq_links > 0:
for i in range(1, uniq_links + 1): for i in range(1, db.uniq_links + 1):
link = 'link_%s'%i link = 'link_%s'%i
article_bottom = article_bottom.replace( article_bottom = article_bottom.replace(
eval(link)[0]+'+', eval(link)[1]%('_blank') eval(link)[0]+'+', eval(link)[1]%('_blank')
@ -246,13 +240,16 @@ def wip_links():
# Convert Abbrs # # Convert Abbrs #
#---------------# #---------------#
def wip_abbrs(): def wip_abbrs():
if uniq_abbrs == 0: return if db.uniq_abbrs == 0: return
global article_bottom global article_bottom
for i in range(1, uniq_abbrs + 1): for i in range(1, db.uniq_abbrs + 1):
abbr = 'abbr_%s'%i abbr = 'abbr_%s'%i
article_bottom = article_bottom.replace(eval(abbr)[0], eval(abbr)[1]) article_bottom = article_bottom.replace(
eval(abbr)[0],
eval(abbr)[1]
)
#-------------------------------------# #-------------------------------------#
@ -269,11 +266,9 @@ def get_wh_image(value):
# Convert _images:%name to HTML # # Convert _images:%name to HTML #
#---------------------------------# #---------------------------------#
def wip_images(): def wip_images():
if uniq_images == 0: return if db.uniq_images == 0: return
global article_bottom global article_bottom
if uniq_images > 0:
image_link = '<a class="%s" href="%s" title="%s">%s</a>' image_link = '<a class="%s" href="%s" title="%s">%s</a>'
image_show = '<img class="%s" src="%s" alt="%s"%s />' image_show = '<img class="%s" src="%s" alt="%s"%s />'
@ -284,8 +279,8 @@ def wip_images():
values = line.rsplit(' ') values = line.rsplit(' ')
# search match tag in DB # search match tag in DB
for i in range(1, uniq_images + 1): for i in range(1, db.uniq_images + 1):
image = 'image_%s'%i image = 'db.image_%s'%i
target = width = height = False target = width = height = False
set_css = db.domain_css + '_image' set_css = db.domain_css + '_image'
imag_html = '' imag_html = ''
@ -297,7 +292,7 @@ def wip_images():
target = value.rsplit('=',1)[1] target = value.rsplit('=',1)[1]
if target == "+": if target == "+":
image_target = eval(image)[1] image_target = eval(image)[1]
image_target = sub_uri + image_target[1:] image_target = db.sub_uri + image_target[1:]
else: else:
image_target = target image_target = target
@ -321,7 +316,7 @@ def wip_images():
# set <img /> from parameter # set <img /> from parameter
image_target = eval(image)[1] image_target = eval(image)[1]
image_target = sub_uri + image_target[1:] image_target = db.sub_uri + image_target[1:]
image_src = image_show%( image_src = image_show%(
set_css, image_target, eval(image)[2], style set_css, image_target, eval(image)[2], style
) )
@ -355,7 +350,7 @@ def quote_params(qline):
# Convert quote in article # # Convert quote in article #
#--------------------------# #--------------------------#
def wip_quotes() : def wip_quotes() :
if stat_quotes == 0: return if db.stat_quotes == 0: return
global article_bottom global article_bottom
global author, link, lang, book, date global author, link, lang, book, date
@ -497,7 +492,7 @@ def wip_quotes() :
# Content is HTML ready # # Content is HTML ready #
#--------------------------# #--------------------------#
def wip_icodes(): def wip_icodes():
if stat_icodes == 0: return if db.stat_icodes == 0: return
global article_bottom global article_bottom
@ -513,7 +508,7 @@ def wip_icodes():
# Content is raw, and have to be converted in HTML # # Content is raw, and have to be converted in HTML #
#--------------------------------------------------# #--------------------------------------------------#
def wip_bcodes(): def wip_bcodes():
if stat_bcodes == 0: return if db.stat_bcodes == 0: return
global article_bottom global article_bottom
@ -545,6 +540,8 @@ def wip_bcodes():
# Check between titles to set div or not # # Check between titles to set div or not #
#----------------------------------------# #----------------------------------------#
def wip_titles(): def wip_titles():
if db.stat_titles == 0: return
global article_bottom global article_bottom
article_temp = article_bottom article_temp = article_bottom
article_tmp2 = '' # COnstruct article, without empty lines article_tmp2 = '' # COnstruct article, without empty lines
@ -595,9 +592,6 @@ def wip_titles():
) )
indiv = False indiv = False
#if line.startswith('<h'):
if article_tmp2.rsplit('\n')[ln + 1].startswith('<div'): if article_tmp2.rsplit('\n')[ln + 1].startswith('<div'):
indiv = True indiv = True
continue continue
@ -613,12 +607,12 @@ def wip_titles():
# Convert raw file to HTML with <pre> + <code> # # Convert raw file to HTML with <pre> + <code> #
#----------------------------------------------# #----------------------------------------------#
def wip_raws(target): def wip_raws(target):
if uniq_raws == 0: return if db.uniq_raws == 0: return
global article_bottom global article_bottom
for i in range(1, uniq_raws + 1): for i in range(1, uniq_raws + 1):
raw = 'raw_%s'%i raw = 'db.raw_%s'%i
raw_file = open( raw_file = open(
'%s%s'%( '%s%s'%(
db.domain_articles, eval(raw)[1] db.domain_articles, eval(raw)[1]
@ -638,9 +632,9 @@ def wip_raws(target):
eval(raw)[0], raw_html eval(raw)[0], raw_html
) )
# #=======================#
# Make HTML tabulations # Make HTML tabulations #
# #-----------------------#
def wip_tabs(): def wip_tabs():
global article_bottom global article_bottom
article_temp = '' article_temp = ''