From 796a58050721ef44f73136c19f5bf94a89210c59 Mon Sep 17 00:00:00 2001
From: Cyrille L
Date: Tue, 7 Feb 2023 14:55:58 +0100
Subject: [PATCH] post_db in db.py. Working check, wip, publish, but some works
to do arount.
---
src/var/lib/tyto/program/args.py | 5 +
src/var/lib/tyto/program/check.py | 109 ++++++++++-----
src/var/lib/tyto/program/db.py | 49 ++++++-
src/var/lib/tyto/program/domain.py | 118 +++++++++++++---
src/var/lib/tyto/program/html.py | 42 +++---
src/var/lib/tyto/program/logs.py | 1 +
src/var/lib/tyto/program/publish.py | 69 +++++++--
src/var/lib/tyto/program/tyto.py | 72 +---------
src/var/lib/tyto/program/wip.py | 210 ++++++++++++++--------------
9 files changed, 405 insertions(+), 270 deletions(-)
diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py
index 0342b9e..d401a62 100644
--- a/src/var/lib/tyto/program/args.py
+++ b/src/var/lib/tyto/program/args.py
@@ -60,6 +60,11 @@ arguments = (
'again'
)
+
+pass_actions = (
+ 'domain'
+ )
+
option = ''
target = ''
diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py
index 2acde83..c67376a 100644
--- a/src/var/lib/tyto/program/check.py
+++ b/src/var/lib/tyto/program/check.py
@@ -26,8 +26,6 @@ import time
import logs, db, tyto
post_err = False
-date_wip = hash_wip = date_www = hash_www = ''
-
#=========================#
# Manage Argument 'check' #
@@ -36,40 +34,81 @@ date_wip = hash_wip = date_www = hash_www = ''
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)
+
+ # ... 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
- # Start processes
- file_to_string(tyto.uri_file)
+ # 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)
diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py
index b76d832..66be81d 100644
--- a/src/var/lib/tyto/program/db.py
+++ b/src/var/lib/tyto/program/db.py
@@ -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())
+
diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py
index 7d4ca55..b26bec3 100644
--- a/src/var/lib/tyto/program/domain.py
+++ b/src/var/lib/tyto/program/domain.py
@@ -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)
diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py
index 0afdf0c..65582cc 100644
--- a/src/var/lib/tyto/program/html.py
+++ b/src/var/lib/tyto/program/html.py
@@ -176,7 +176,7 @@ def create_main_page(target, article_bottom):
'\n' + \
' \n' + \
' \n' + \
- '%s\n'%html_infos + \
+ '%s\n'%post_pub + \
' \n' + \
'%s\n'%article_bottom + \
' \n' + \
@@ -191,8 +191,10 @@ def create_main_page(target, article_bottom):
# Create HTML line for article infos section #
# when wip, and publish #
#--------------------------------------------#
-def create_html_infos_section(process):
- global html_infos
+def create_html_infos_section(process):
+ # 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 #
'
+ post_pub = '%s'%(8 * ' ') + \
+ 'Article '%(
+ title
+ ) + \
+ '%s '%(
+ tyto.trans[10][tyto.n], date[0], tyto.trans[7][tyto.n]
+ ) + \
+ '%s. %s '%(
+ author, tyto.trans[8][tyto.n]
+ ) + \
+ ''%date_raw + \
+ '%s %s '%(
+ date_pub, tyto.trans[9][tyto.n]
+ ) + \
+ '%s'%time_pub + \
+ '' + \
+ '
'
#========================================================#
diff --git a/src/var/lib/tyto/program/logs.py b/src/var/lib/tyto/program/logs.py
index a504bbf..87d7d1e 100644
--- a/src/var/lib/tyto/program/logs.py
+++ b/src/var/lib/tyto/program/logs.py
@@ -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),
diff --git a/src/var/lib/tyto/program/publish.py b/src/var/lib/tyto/program/publish.py
index a95b0eb..51d3d78 100644
--- a/src/var/lib/tyto/program/publish.py
+++ b/src/var/lib/tyto/program/publish.py
@@ -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 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 = '%s'
+ image_show = ''
- if uniq_images > 0:
- image_link = '%s'
- image_show = ''
-
- # 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 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 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 HTML to replace line number
- image_html = image_tgt%image_src
+ if 'h=' in value:
+ height = get_wh_image(value.rsplit('=',1)[1])
- article_bottom = article_bottom.replace(
- article_bottom.rsplit('\n')[ln], image_html
- )
+ 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 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 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
+
+ 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
@@ -594,10 +591,7 @@ def wip_titles():
line, '\n%s'%line
)
indiv = False
-
- #if line.startswith(' + #
#----------------------------------------------#
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 = ''