post_db in db.py. Working check, wip, publish, but some works to do arount.
This commit is contained in:
parent
4d604acb91
commit
796a580507
|
@ -60,6 +60,11 @@ arguments = (
|
|||
'again'
|
||||
)
|
||||
|
||||
|
||||
pass_actions = (
|
||||
'domain'
|
||||
)
|
||||
|
||||
option = ''
|
||||
target = ''
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ import time
|
|||
import logs, db, tyto
|
||||
|
||||
post_err = False
|
||||
date_wip = hash_wip = date_www = hash_www = ''
|
||||
|
||||
|
||||
#=========================#
|
||||
# Manage Argument 'check' #
|
||||
|
@ -37,39 +35,80 @@ def manage_check(target, option):
|
|||
# target needed
|
||||
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
|
||||
#--------------
|
||||
if option == 'Edit':
|
||||
tyto.edit_file(tyto.uri_file)
|
||||
tyto.edit_file(db.uri_file)
|
||||
return
|
||||
elif option == 'Show':
|
||||
article_raw = open(tyto.uri_file).read()
|
||||
article_raw = open(db.uri_file).read()
|
||||
for line in article_raw.rsplit('\n'):
|
||||
print(line)
|
||||
return
|
||||
|
||||
if db_exists:
|
||||
# Just read the DB from command
|
||||
if option == 'DB':
|
||||
article_db = open(tyto.post_db).read()
|
||||
# Just read the DB from command
|
||||
elif option == 'DB':
|
||||
if db.db_exists:
|
||||
article_db = open(db.post_db).read()
|
||||
for line in article_db.rsplit('\n'):
|
||||
print(line)
|
||||
return
|
||||
else:
|
||||
logs.out("25", db.uri_file, True)
|
||||
|
||||
try:
|
||||
exec(open(tyto.post_db).read(),globals())
|
||||
if hash_chk == tyto.hash_post and not option == 'Force':
|
||||
logs.out("20", date_chk, True)
|
||||
finally: pass
|
||||
# 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)
|
||||
|
||||
# Start processes
|
||||
file_to_string(tyto.uri_file)
|
||||
# ... was already check and not changed
|
||||
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
|
||||
check_icodes(article.rsplit('\n'))
|
||||
|
@ -614,7 +653,7 @@ def check_content(post_bottom):
|
|||
ptag = '_%s'%htag
|
||||
|
||||
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
|
||||
for hline in post_header:
|
||||
if re.search(r"^%s\s+%s$"%(htag,ptag_set), hline):
|
||||
|
@ -641,19 +680,19 @@ def check_content(post_bottom):
|
|||
#-----------------------------------------------#
|
||||
def create_database():
|
||||
database = '# Post Configuration for Tyto\n' + \
|
||||
'post_id = "%s"\n'%tyto.uri_id + \
|
||||
'post_src = "%s"\n'%tyto.uti_file + \
|
||||
'post_wip = "%s"\n'%tyto.srv_post_wip_uri + \
|
||||
'post_www = "%s"\n'%tyto.srv_post_www_uri + \
|
||||
'post_id = "%s"\n'%db.uri_id + \
|
||||
'post_src = "%s"\n'%db.uri_file + \
|
||||
'post_wip = "%s"\n'%srv_post_wip_uri + \
|
||||
'post_www = "%s"\n'%srv_post_www_uri + \
|
||||
'\n' + \
|
||||
'short_src = "%s"\n'%tyto.src_post_short_uri + \
|
||||
'short_srv = "%s"\n'%tyto.srv_post_short_uri + \
|
||||
'sub_uri = "%s"\n'%tyto.sub_uri + \
|
||||
'http_wip = "%s"\n'%tyto.http_wip + \
|
||||
'http_www = "%s"\n'%tyto.http_www + \
|
||||
'short_src = "%s"\n'%src_post_short_uri + \
|
||||
'short_srv = "%s"\n'%srv_post_short_uri + \
|
||||
'sub_uri = "%s"\n'%sub_uri + \
|
||||
'http_wip = "%s"\n'%http_wip + \
|
||||
'http_www = "%s"\n'%http_www + \
|
||||
'\n' + \
|
||||
'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 + \
|
||||
'hash_wip = "%s"\n'%hash_wip + \
|
||||
'date_www = "%s"\n'%date_www + \
|
||||
|
@ -726,5 +765,5 @@ def create_database():
|
|||
'stat_lists = %d\n'%post_lists
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: DBs tools
|
||||
# Description: Search DBs and exec
|
||||
# Description: Search DBs (domain + post) and exec
|
||||
# file: db.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
import os, sys
|
||||
import args, logs
|
||||
import args, logs, tyto
|
||||
|
||||
# Settings
|
||||
#---------
|
||||
|
@ -39,7 +39,7 @@ domain_values = (
|
|||
'domain_articles',
|
||||
'domain_files',
|
||||
'domain_images',
|
||||
'domain_db',
|
||||
'articles_db',
|
||||
'html_db',
|
||||
'navbars_dir',
|
||||
'navbar_load',
|
||||
|
@ -109,8 +109,12 @@ domain_conf = '%s/tyto_domain.conf'%domain_conf
|
|||
if os.path.exists(domain_conf): domain_exists = True
|
||||
else: domain_exists = False
|
||||
|
||||
# Check if domain is set
|
||||
#-----------------------
|
||||
|
||||
#======================================================================
|
||||
#------------------------#
|
||||
# Check if domain is set #
|
||||
#------------------------#
|
||||
#======================================================================
|
||||
stdout = '%s %s domain "%s" in %s' # Show domain status
|
||||
|
||||
if domain_exists:
|
||||
|
@ -137,3 +141,38 @@ if domain_exists:
|
|||
else:
|
||||
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())
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
import os, sys, locale
|
||||
import logs, db, tyto, html
|
||||
|
||||
|
||||
#==========================#
|
||||
# Manage Argument 'domain' #
|
||||
#--------------------------#
|
||||
|
@ -87,7 +88,11 @@ def create_domain(target, option):
|
|||
|
||||
valid_url = ('http://', 'https://')
|
||||
ask = ''
|
||||
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url)
|
||||
try:
|
||||
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not ask.startswith(valid_url):
|
||||
logs.out("2", 'http(s)://...', True)
|
||||
|
@ -113,7 +118,11 @@ def create_domain(target, option):
|
|||
except: domain_wip_url = try_wip_url
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url)
|
||||
try:
|
||||
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
isurl(ask)
|
||||
domain_wip_url = ask
|
||||
|
@ -128,7 +137,7 @@ def create_domain(target, option):
|
|||
'domain_articles = "%sarticles/"\n'%db.conf_dir + \
|
||||
'domain_files = "%sarticles/files/"\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 + \
|
||||
'navbars_dir = "%s"\n'%navbars_conf + \
|
||||
'navbar_load = "%styto.navbar"\n'%navbars_conf + \
|
||||
|
@ -152,7 +161,11 @@ def create_domain(target, option):
|
|||
except: domain_srv = '/var/www'
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ System server ? ("%s") '%domain_srv)
|
||||
try:
|
||||
ask = input(' ├ System server ? ("%s") '%domain_srv)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not os.path.exists(srv): logs.out("1", ask, True)
|
||||
elif not domain_srv: logs.out("255", '', True)
|
||||
|
@ -190,7 +203,11 @@ def create_domain(target, option):
|
|||
except: domain_title = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Domain title ? ("%s") '%domain_title)
|
||||
try:
|
||||
ask = input(' ├ Domain title ? ("%s") '%domain_title)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: domain_title = ask
|
||||
elif not domain_title: logs.out("255", '', True)
|
||||
if '"' in domain_title:
|
||||
|
@ -208,7 +225,11 @@ def create_domain(target, option):
|
|||
except: domain_about = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
|
||||
try:
|
||||
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: domain_about = ask
|
||||
elif not domain_about: logs.out("255", '', True)
|
||||
if '"' in domain_about:
|
||||
|
@ -225,7 +246,11 @@ def create_domain(target, option):
|
|||
except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
|
||||
try:
|
||||
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if len(ask) == 2: domain_lang = ask
|
||||
else: logs.out("3", ask, True)
|
||||
|
@ -242,7 +267,11 @@ def create_domain(target, option):
|
|||
except: domain_mail = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
|
||||
try:
|
||||
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not "@" in ask and not "." in ask: logs.out("3", ask, True)
|
||||
domain_mail = ask
|
||||
|
@ -259,7 +288,11 @@ def create_domain(target, option):
|
|||
except: domain_tags = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
|
||||
try:
|
||||
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: domain_tags = ask
|
||||
elif not domain_tags: logs.out("255", '', True)
|
||||
|
||||
|
@ -274,7 +307,11 @@ def create_domain(target, option):
|
|||
except: domain_logo = 'logo.png'
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ logo filename ? ("%s") '%domain_logo)
|
||||
try:
|
||||
ask = input(' ├ logo filename ? ("%s") '%domain_logo)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: domain_logo = ask
|
||||
|
||||
tyto.set_file(db.domain_conf, False,
|
||||
|
@ -290,7 +327,11 @@ def create_domain(target, option):
|
|||
except: domain_license = 'CC BY-NC-SA'
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Domain License ? ("%s") '%domain_license)
|
||||
try:
|
||||
ask = input(' ├ Domain License ? ("%s") '%domain_license)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: domain_license = ask
|
||||
elif not domain_license: logs.out("255", '', True)
|
||||
if '"' in domain_license:
|
||||
|
@ -307,7 +348,11 @@ def create_domain(target, option):
|
|||
except: domain_licurl = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
|
||||
try:
|
||||
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not ask.startswith('http'): logs.out("3", ask, True)
|
||||
domain_licurl = ask
|
||||
|
@ -323,7 +368,11 @@ def create_domain(target, option):
|
|||
except: domain_css = 'tyto'
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
|
||||
try:
|
||||
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not ask.isalnum(): logs.out("3", ask, True)
|
||||
domain_css = ask.lower()
|
||||
|
@ -339,7 +388,11 @@ def create_domain(target, option):
|
|||
except: domain_sep = "-"
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
|
||||
try:
|
||||
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not len(ask) == 1: logs.out("3", ask, True)
|
||||
domain_sep = ask
|
||||
|
@ -355,7 +408,11 @@ def create_domain(target, option):
|
|||
except: domain_relme = ''
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
|
||||
try:
|
||||
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not ask.startswith('http'): logs.out("3", ask, True)
|
||||
domain_relme = ask
|
||||
|
@ -371,7 +428,11 @@ def create_domain(target, option):
|
|||
except: sidebar_title = tyto.trans[0][tyto.n]
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
|
||||
try:
|
||||
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask: sidebar_title = ask
|
||||
if '"' in sidebar_title:
|
||||
sidebar_title = sidebar_title.replace('"', '')
|
||||
|
@ -387,7 +448,11 @@ def create_domain(target, option):
|
|||
except: sidebar_items = "6"
|
||||
|
||||
ask = ''
|
||||
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items)
|
||||
try:
|
||||
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if ask:
|
||||
if not ask.isdigit(): logs.out("3", ask, True)
|
||||
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'):
|
||||
print(' │', line)
|
||||
|
||||
ask = input(' ├ Activate and prepare domain ? ')
|
||||
try:
|
||||
ask = input(' ├ Activate and prepare domain ? ')
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if not ask in ['y', 'Y']:
|
||||
tyto.set_file(db.domain_conf, False, '\ndomain_active = False')
|
||||
logs.out("255", '', True)
|
||||
|
@ -443,7 +512,6 @@ def create_domain(target, option):
|
|||
# Create in _configs files
|
||||
# Force will ask to create in template
|
||||
print(' │')
|
||||
#create_sidebar(option)
|
||||
html.manage_configs('sidebar', 'Force')
|
||||
html.manage_configs('navbar', 'Force')
|
||||
html.manage_configs('metas', 'Force')
|
||||
|
@ -535,7 +603,11 @@ def create_sidebar(option):
|
|||
log = ' ├ Create file: %s'%db.sidebar_load
|
||||
res = ''
|
||||
if os.path.exists(db.sidebar_load):
|
||||
res = input(ask)
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
tyto.set_file(db.sidebar_load, 'new', sdb_load)
|
||||
|
@ -637,7 +709,11 @@ def create_navbar(option):
|
|||
log = ' ├ Create file: %s'%db.navbar_load
|
||||
res = ''
|
||||
if os.path.exists(db.navbar_load):
|
||||
res = input(ask)
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
tyto.set_file(db.navbar_load, 'new', nvb_load)
|
||||
|
|
|
@ -176,7 +176,7 @@ def create_main_page(target, article_bottom):
|
|||
'\n' + \
|
||||
' <article id="article_main">\n' + \
|
||||
' <section id="article_infos">\n' + \
|
||||
'%s\n'%html_infos + \
|
||||
'%s\n'%post_pub + \
|
||||
' </section>\n' + \
|
||||
'%s\n'%article_bottom + \
|
||||
' </article>\n' + \
|
||||
|
@ -192,7 +192,9 @@ def create_main_page(target, article_bottom):
|
|||
# when wip, and publish #
|
||||
#--------------------------------------------#
|
||||
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':
|
||||
date_raw = date_wip # <time datetime=
|
||||
|
@ -207,23 +209,23 @@ def create_html_infos_section(process):
|
|||
date_new = date_pub.rsplit('-')
|
||||
date_pub = date_new[2] + '/' + date_new[1] + '/' + date_new[0]
|
||||
|
||||
html_infos = '%s<p>'%(8 * ' ') + \
|
||||
'<span id="article_title" title="%s">Article</span> '%(
|
||||
title
|
||||
) + \
|
||||
'<span title="%s %s">%s</span> '%(
|
||||
tyto.trans[10][tyto.n], date[0], tyto.trans[7][tyto.n]
|
||||
) + \
|
||||
'<span id="article_author">%s</span>. %s '%(
|
||||
author, tyto.trans[8][tyto.n]
|
||||
) + \
|
||||
'<time datetime="%s">'%date_raw + \
|
||||
'<span id="article_date">%s</span> %s '%(
|
||||
date_pub, tyto.trans[9][tyto.n]
|
||||
) + \
|
||||
'<span id="article_time">%s</span>'%time_pub + \
|
||||
'</time>' + \
|
||||
'</p>'
|
||||
post_pub = '%s<p>'%(8 * ' ') + \
|
||||
'<span id="article_title" title="%s">Article</span> '%(
|
||||
title
|
||||
) + \
|
||||
'<span title="%s %s">%s</span> '%(
|
||||
tyto.trans[10][tyto.n], date[0], tyto.trans[7][tyto.n]
|
||||
) + \
|
||||
'<span id="article_author">%s</span>. %s '%(
|
||||
author, tyto.trans[8][tyto.n]
|
||||
) + \
|
||||
'<time datetime="%s">'%date_raw + \
|
||||
'<span id="article_date">%s</span> %s '%(
|
||||
date_pub, tyto.trans[9][tyto.n]
|
||||
) + \
|
||||
'<span id="article_time">%s</span>'%time_pub + \
|
||||
'</time>' + \
|
||||
'</p>'
|
||||
|
||||
|
||||
#========================================================#
|
||||
|
|
|
@ -55,6 +55,7 @@ def out(nbr, value, out):
|
|||
'30' : ':? Article %snot yet wip%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),
|
||||
'34' : ':D Publish %sfile change%s %s'%(CG, CS, value),
|
||||
'40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value),
|
||||
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),
|
||||
'42' : ':D %sActive%s domain "%s"'%(CG, CS, value),
|
||||
|
|
|
@ -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 #
|
||||
# check if publish can be done #
|
||||
#------------------------------#
|
||||
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
|
||||
if not db_exists: logs.out("25", tyto.uri_file, False)
|
||||
elif not tyto.hash_chk: logs.out("25", tyto.uri_file, False)
|
||||
elif not tyto.hash_wip: logs.out("30", tyto.uri_file, False)
|
||||
if not db.hash_chk:
|
||||
logs.out("25", db.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():
|
||||
# Testing html publis
|
||||
print('> Testing html publish')
|
||||
wip_html_post = open(post_wip, 'r').read()
|
||||
# Need to reload the DB to get last time updated
|
||||
exec(open(db.post_db).read(), globals())
|
||||
|
||||
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'):
|
||||
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)
|
||||
|
|
|
@ -26,10 +26,6 @@ home_dir = os.path.expanduser('~')
|
|||
in_dir = os.getcwd()
|
||||
domain_conf = in_dir
|
||||
|
||||
if db.domain_exists:
|
||||
db_dir = db.domain_db
|
||||
|
||||
|
||||
# Set translations: french, english
|
||||
#----------------------------------
|
||||
try: lang = domain_lang
|
||||
|
@ -170,70 +166,6 @@ def set_en_date(date):
|
|||
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 #
|
||||
#----------------------#
|
||||
|
@ -447,10 +379,10 @@ def replace_in_db(post_db, process, hash_post):
|
|||
|
||||
for line in lines:
|
||||
if line.startswith('hash_%s'%process):
|
||||
line = line.replace(line, 'hash_%s = "%s"'%(process, hash_post))
|
||||
line = line.replace(line, 'hash_%s = "%s"'%(process, hash_post))
|
||||
new_file = '%s%s\n'%(new_file, line)
|
||||
elif line.startswith('date_%s'%process):
|
||||
line = line.replace(line, 'date_%s = "%s"'%(process, nowdate()))
|
||||
line = line.replace(line, 'date_%s = "%s"'%(process, nowdate()))
|
||||
new_file = '%s%s\n'%(new_file, line)
|
||||
else:
|
||||
if new_file: new_file = '%s%s'%(new_file, line)
|
||||
|
|
|
@ -23,7 +23,9 @@ import logs, db, tyto, html
|
|||
def manage_wip(target, option):
|
||||
global post_db, hash_post
|
||||
|
||||
# Domain configuration must exist and active
|
||||
if not db.domain_exists: return
|
||||
if not db.domain_active: return
|
||||
|
||||
#-----------------------------------------
|
||||
# Option 'Again' to wip again, based on DB
|
||||
|
@ -50,34 +52,26 @@ def manage_wip(target, option):
|
|||
#------------------------
|
||||
# Per article with target
|
||||
#------------------------
|
||||
# Article exists + has DB ?
|
||||
db_exists = tyto.get_db_post(target)
|
||||
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())
|
||||
if not target: logs.out("5", '', True)
|
||||
if not db.db_exists: logs.out("25", db.uri_file, True)
|
||||
|
||||
# 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
|
||||
if option == 'Force':
|
||||
wip_article(target)
|
||||
wip_article(db.uri_file)
|
||||
return
|
||||
|
||||
# Compare and check file
|
||||
if hash_wip != hash_chk:
|
||||
wip_article(target)
|
||||
if db.hash_wip != db.hash_chk:
|
||||
wip_article(db.uri_file)
|
||||
else:
|
||||
if not os.path.exists(post_wip):
|
||||
logs.out("24", '(wip article): %s'%post_wip, False)
|
||||
wip_article(target)
|
||||
if not os.path.exists(db.post_wip):
|
||||
logs.out("24", '(wip article): %s'%db.post_wip, False)
|
||||
wip_article(db.uri_file)
|
||||
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)
|
||||
#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
|
||||
html.set_page(post_db, target, article_bottom)
|
||||
html.set_page(db.post_db, db.uri_file, article_bottom)
|
||||
#print(html.main_page)
|
||||
|
||||
# Create wip file
|
||||
tyto.set_file(post_wip, 'New', html.main_page)
|
||||
logs.out("33", post_wip, False)
|
||||
tyto.set_file(db.post_wip, 'New', html.main_page)
|
||||
logs.out("33", db.post_wip, False)
|
||||
|
||||
# Copy needed file to wip
|
||||
for uri in uris:
|
||||
for uri in db.uris:
|
||||
f_src = '%s%s'%(db.domain_articles, uri)
|
||||
f_wip = '%s%s'%(db.srv_wip, uri)
|
||||
shutil.copy2(f_src, f_wip)
|
||||
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 #
|
||||
|
@ -221,8 +215,8 @@ def wip_links():
|
|||
global article_bottom
|
||||
|
||||
# Doing files, first, becase of similar marker
|
||||
if uniq_files > 0:
|
||||
for i in range(1, uniq_files + 1):
|
||||
if db.uniq_files > 0:
|
||||
for i in range(1, db.uniq_files + 1):
|
||||
file = 'file_%s'%i
|
||||
article_bottom = article_bottom.replace(
|
||||
eval(file)[0]+'+', eval(file)[1]%('_blank')
|
||||
|
@ -231,8 +225,8 @@ def wip_links():
|
|||
eval(file)[0], eval(file)[1]%('_self')
|
||||
)
|
||||
|
||||
if uniq_links > 0:
|
||||
for i in range(1, uniq_links + 1):
|
||||
if db.uniq_links > 0:
|
||||
for i in range(1, db.uniq_links + 1):
|
||||
link = 'link_%s'%i
|
||||
article_bottom = article_bottom.replace(
|
||||
eval(link)[0]+'+', eval(link)[1]%('_blank')
|
||||
|
@ -246,13 +240,16 @@ def wip_links():
|
|||
# Convert Abbrs #
|
||||
#---------------#
|
||||
def wip_abbrs():
|
||||
if uniq_abbrs == 0: return
|
||||
if db.uniq_abbrs == 0: return
|
||||
|
||||
global article_bottom
|
||||
|
||||
for i in range(1, uniq_abbrs + 1):
|
||||
for i in range(1, db.uniq_abbrs + 1):
|
||||
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,77 +266,75 @@ def get_wh_image(value):
|
|||
# Convert _images:%name to HTML #
|
||||
#---------------------------------#
|
||||
def wip_images():
|
||||
if uniq_images == 0: return
|
||||
if db.uniq_images == 0: return
|
||||
|
||||
global article_bottom
|
||||
image_link = '<a class="%s" href="%s" title="%s">%s</a>'
|
||||
image_show = '<img class="%s" src="%s" alt="%s"%s />'
|
||||
|
||||
if uniq_images > 0:
|
||||
image_link = '<a class="%s" href="%s" title="%s">%s</a>'
|
||||
image_show = '<img class="%s" src="%s" alt="%s"%s />'
|
||||
# Check each line
|
||||
for ln, line in enumerate(article_bottom.rsplit('\n')):
|
||||
# match line
|
||||
if line.startswith('_image:'):
|
||||
values = line.rsplit(' ')
|
||||
|
||||
# Check each line
|
||||
for ln, line in enumerate(article_bottom.rsplit('\n')):
|
||||
# match line
|
||||
if line.startswith('_image:'):
|
||||
values = line.rsplit(' ')
|
||||
# search match tag in DB
|
||||
for i in range(1, db.uniq_images + 1):
|
||||
image = 'db.image_%s'%i
|
||||
target = width = height = False
|
||||
set_css = db.domain_css + '_image'
|
||||
imag_html = ''
|
||||
|
||||
# search match tag in DB
|
||||
for i in range(1, uniq_images + 1):
|
||||
image = 'image_%s'%i
|
||||
target = width = height = False
|
||||
set_css = db.domain_css + '_image'
|
||||
imag_html = ''
|
||||
if eval(image)[0] == values[0]:
|
||||
# Get parameters from match line
|
||||
for value in values:
|
||||
if 't=' in value:
|
||||
target = value.rsplit('=',1)[1]
|
||||
if target == "+":
|
||||
image_target = eval(image)[1]
|
||||
image_target = db.sub_uri + image_target[1:]
|
||||
else:
|
||||
image_target = target
|
||||
|
||||
if eval(image)[0] == values[0]:
|
||||
# Get parameters from match line
|
||||
for value in values:
|
||||
if 't=' in value:
|
||||
target = value.rsplit('=',1)[1]
|
||||
if target == "+":
|
||||
image_target = eval(image)[1]
|
||||
image_target = sub_uri + image_target[1:]
|
||||
else:
|
||||
image_target = target
|
||||
if 'c=' in value:
|
||||
set_css = value.rsplit('=', 1)[1]
|
||||
|
||||
if 'c=' in value:
|
||||
set_css = value.rsplit('=', 1)[1]
|
||||
if 'w=' in value:
|
||||
width = get_wh_image(value.rsplit('=',1)[1])
|
||||
|
||||
if 'w=' in value:
|
||||
width = get_wh_image(value.rsplit('=',1)[1])
|
||||
if 'h=' in value:
|
||||
height = get_wh_image(value.rsplit('=',1)[1])
|
||||
|
||||
if 'h=' in value:
|
||||
height = get_wh_image(value.rsplit('=',1)[1])
|
||||
if width and height:
|
||||
style = ' style="width:%s;height=%s"'%(width, height)
|
||||
elif width:
|
||||
style = ' style="width:%s"'%width
|
||||
elif height:
|
||||
style = ' style="height:%s"'%height
|
||||
else:
|
||||
style = ''
|
||||
|
||||
if width and height:
|
||||
style = ' style="width:%s;height=%s"'%(width, height)
|
||||
elif width:
|
||||
style = ' style="width:%s"'%width
|
||||
elif height:
|
||||
style = ' style="height:%s"'%height
|
||||
else:
|
||||
style = ''
|
||||
# set <img /> from parameter
|
||||
image_target = eval(image)[1]
|
||||
image_target = db.sub_uri + image_target[1:]
|
||||
image_src = image_show%(
|
||||
set_css, image_target, eval(image)[2], style
|
||||
)
|
||||
|
||||
# set <img /> from parameter
|
||||
image_target = eval(image)[1]
|
||||
image_target = sub_uri + image_target[1:]
|
||||
image_src = image_show%(
|
||||
set_css, image_target, eval(image)[2], style
|
||||
# Set link for image
|
||||
if target:
|
||||
image_tgt = image_link%(
|
||||
set_css, image_target, eval(image)[2], '%s'
|
||||
)
|
||||
else:
|
||||
image_tgt = '%s'
|
||||
|
||||
# Set link for image
|
||||
if target:
|
||||
image_tgt = image_link%(
|
||||
set_css, image_target, eval(image)[2], '%s'
|
||||
)
|
||||
else:
|
||||
image_tgt = '%s'
|
||||
# Set HTML to replace line number
|
||||
image_html = image_tgt%image_src
|
||||
|
||||
# Set HTML to replace line number
|
||||
image_html = image_tgt%image_src
|
||||
|
||||
article_bottom = article_bottom.replace(
|
||||
article_bottom.rsplit('\n')[ln], image_html
|
||||
)
|
||||
article_bottom = article_bottom.replace(
|
||||
article_bottom.rsplit('\n')[ln], image_html
|
||||
)
|
||||
|
||||
|
||||
#============================================#
|
||||
|
@ -355,7 +350,7 @@ def quote_params(qline):
|
|||
# Convert quote in article #
|
||||
#--------------------------#
|
||||
def wip_quotes() :
|
||||
if stat_quotes == 0: return
|
||||
if db.stat_quotes == 0: return
|
||||
|
||||
global article_bottom
|
||||
global author, link, lang, book, date
|
||||
|
@ -497,7 +492,7 @@ def wip_quotes() :
|
|||
# Content is HTML ready #
|
||||
#--------------------------#
|
||||
def wip_icodes():
|
||||
if stat_icodes == 0: return
|
||||
if db.stat_icodes == 0: return
|
||||
|
||||
global article_bottom
|
||||
|
||||
|
@ -513,7 +508,7 @@ def wip_icodes():
|
|||
# Content is raw, and have to be converted in HTML #
|
||||
#--------------------------------------------------#
|
||||
def wip_bcodes():
|
||||
if stat_bcodes == 0: return
|
||||
if db.stat_bcodes == 0: return
|
||||
|
||||
global article_bottom
|
||||
|
||||
|
@ -545,6 +540,8 @@ def wip_bcodes():
|
|||
# Check between titles to set div or not #
|
||||
#----------------------------------------#
|
||||
def wip_titles():
|
||||
if db.stat_titles == 0: return
|
||||
|
||||
global article_bottom
|
||||
article_temp = article_bottom
|
||||
article_tmp2 = '' # COnstruct article, without empty lines
|
||||
|
@ -595,9 +592,6 @@ def wip_titles():
|
|||
)
|
||||
indiv = False
|
||||
|
||||
#if line.startswith('<h'):
|
||||
|
||||
|
||||
if article_tmp2.rsplit('\n')[ln + 1].startswith('<div'):
|
||||
indiv = True
|
||||
continue
|
||||
|
@ -613,12 +607,12 @@ def wip_titles():
|
|||
# Convert raw file to HTML with <pre> + <code> #
|
||||
#----------------------------------------------#
|
||||
def wip_raws(target):
|
||||
if uniq_raws == 0: return
|
||||
if db.uniq_raws == 0: return
|
||||
|
||||
global article_bottom
|
||||
|
||||
for i in range(1, uniq_raws + 1):
|
||||
raw = 'raw_%s'%i
|
||||
raw = 'db.raw_%s'%i
|
||||
raw_file = open(
|
||||
'%s%s'%(
|
||||
db.domain_articles, eval(raw)[1]
|
||||
|
@ -638,9 +632,9 @@ def wip_raws(target):
|
|||
eval(raw)[0], raw_html
|
||||
)
|
||||
|
||||
#
|
||||
# Make HTML tabulations
|
||||
#
|
||||
#=======================#
|
||||
# Make HTML tabulations #
|
||||
#-----------------------#
|
||||
def wip_tabs():
|
||||
global article_bottom
|
||||
article_temp = ''
|
||||
|
|
Loading…
Reference in New Issue