[1.9.22] - cleaner code, updated DBs managements

This commit is contained in:
Cyrille L 2023-10-13 12:13:38 +02:00
parent 34afac630b
commit ea99dcd1ae
11 changed files with 236 additions and 205 deletions

View File

@ -9,11 +9,12 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.22] (Not Yet push)
## [1.9.22]
- new bcode process (html prepared for wip)
- new post database management values
- new icode process (html prepared for wip)
- bcodes and icodes are FIRST processed in text article
- generic check fonction for bcodes, quotes, lists, paragraphs
- lots more
## [1.9.21]

View File

@ -9,11 +9,10 @@ tyto
## ToDo next (working on)
- 'check' action processes
- - wip quotes
- - support for words tags (bolds...)
- - support lists, anchors
- - thinking about creating an auto top article menu from titles
- - stats for article words
- manage template post database
- - check valid database
- Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Version: 1.9.22
# Updated: 2023-10-11 1697039459
# Updated: 2023-10-13 1697190846
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -76,10 +76,12 @@ def is_article(target):
# When all is OK
# Will create post database, but now, show some values
print("Final texts string")
"""
for ln, line in enumerate(texts, post.head_lines + 1):
print(">", ln, line)
print()
"""
# Write to post database
cf_update_values()
@ -113,7 +115,7 @@ def valid(target):
# Text article
# ============
# Process bcodes and icodes first to protect their contents
post.error == 0 and bcodes() or tools.exit(targets, post.error)
post.error == 0 and sl_ptags(post.ptags[0]) or tools.exit(targets, post.error)
post.error == 0 and icodes() or tools.exit(targets, post.error)
# =============
@ -128,7 +130,10 @@ def valid(target):
# Text article
# ============
# Single tags
post.error == 0 and sl_tags() or tools.exit(targets, post.error)
post.error == 0 and sl_stags() or tools.exit(targets, post.error)
# Quotes
post.error == 0 and sl_ptags(post.ptags[1]) or tools.exit(targets, post.error)
return True
@ -467,22 +472,39 @@ def is_value2_file_exists(ln, tag, val2):
#=====================#
#=======================================#
# bcodes: first process ! #
# Check if opened and closed tags match #
# Count bcodes for stats #
# Remove bcodes lines #
# - Create new post "texts" contents #
# Return True/False #
#---------------------------------------#
def bcodes():
#=========================================#
# start line paired tags #
# Generic check for all paired markers #
# Check if opened and closed tags match #
# Count markers for stats #
# bcodes: remove lines from texts #
# Convert content between markers to html #
# (except for paragraphs) #
# convert html content to base64 #
# create sections, keys values to post DB #
# Return True/False #
#-----------------------------------------#
def sl_ptags(markers):
global texts
markers = post.bcodes
convert = {
"bcodes" : wip.bcode,
"quotes" : wip.quote,
}
index0 = index1 = -1
for ln, line in enumerate(texts, post.head_lines + 1):
# Marker is opened
if index0 >= 0 :
#print(">>>", ln, line)
bcode = "%s\n%s"%(bcode, line)
content = "%s\n%s"%(content, line)
if markers[2] == "bcodes":
texts[ln - 1 - post.head_lines] = ""
# Opened mark
@ -492,23 +514,23 @@ def bcodes():
# at the same position
if line.index(markers[0][0]) == index0:
post.error = \
debug.out(53, '%s...%s) "%s"'%(
tag_ln, ln, markers[1]
debug.out(53, '%s: %s...%s) "%s"'%(
markers[2], tag_ln, ln, markers[1]
), post.uri, True, 2, False)
return False
continue
index0 = line.index(markers[0][0])
tag_ln = ln
bcode = line
#print(">>>", ln, line)
content = line
if markers[2] == "bcodes":
texts[ln - 1 - post.head_lines] = ""
# Closed mark
if line.lstrip().startswith(markers[1]):
if index0 < 0:
post.error = \
debug.out(53, '%s) "%s"...'%(
ln, markers[0]
debug.out(53, '%s: %s) "%s"...'%(
markers[2], ln, markers[0]
), post.uri, True, 2, False)
return False
index1 = line.index(markers[1][0])
@ -516,55 +538,73 @@ def bcodes():
if index1 == index0:
index0 = index1 = -1
tag_ln = ""
post.stats_bcodes += 1
post.ptags_stats[markers[2]] += 1
# create ini values for this bcode
var_name = "bcode_%s"%post.stats_bcodes
val_raws = tools.b64_convert("encode", bcode)
var_html = "html_%s"%post.stats_bcodes
val_html = tools.b64_convert("encode", wip.bcode(bcode))
post.cf_set("BCODES", var_name, val_raws)
post.cf_set("BCODES", var_html, val_html)
# paragraphs don't need html wip yet
if markers[2] == "parags":
continue
# Generic db Keys and values
var_name = "%s_%s"%(markers[2][:-1], post.ptags_stats[markers[2]])
val_raws = tools.b64_convert("encode", content)
var_html = "html_%s"%post.ptags_stats[markers[2]]
# Specific values from marker
val_html = tools.b64_convert("encode", convert[markers[2]](content))
# Set keys, values to post database
post.cf_set(markers[2].upper(), var_name, val_raws)
post.cf_set(markers[2].upper(), var_html, val_html)
# bcode not opened, but closed tag found
elif index0 < 0:
tag_ln = ln
# Check if markers match
# ----------------------
if index1 >= 0 and index0 < 0:
post.error = \
debug.out(53, '%s) "%s"...'%(tag_ln, markers[0]), post.uri, True,2, False)
debug.out(53, '%s: %s) "%s"...'%(
markers[2], tag_ln, markers[0]
), post.uri, True,2, False)
return False
if index0 >= 0 and index1 < 0:
post.error = \
debug.out(53, '%s) ..."%s"'%(tag_ln, markers[1]), post.uri, True,2, False)
debug.out(53, '%s: %s) ..."%s"'%(
markers[2], tag_ln, markers[1]
), post.uri, True,2, False)
return False
if index0 != index1:
post.error = \
debug.out(53, '%s) "%s"..."%s"'%(
tag_ln, markers[0], markers[1]
debug.out(53, '%s: %s) "%s"..."%s"'%(
markers[2], tag_ln, markers[0], markers[1]
), post.uri, True,2, False)
return False
print(": stats", markers[2], post.ptags_stats[markers[2]])
return True
#
# icodes (SAME LINE)
#==========================================#
# icodes (SAME LINE) #
# Check if opened and closed markers match #
#
# Convert double marks, then single markes #
# replace icodes with "" in texts article #
# Add source text and html converted to DB #
#------------------------------------------#
def icodes():
global texts
markers = post.icodes
markers = post.words_markers
for ln, line in enumerate(texts, post.head_lines + 1):
# Search for opened, closed markers
# markers cannot be at same position on line
m0 = line.find(markers[0])
m1 = line.find(markers[1])
m0 = line.find(markers[1][0])
m1 = line.find(markers[1][1])
if m0 == m1:
continue
@ -574,7 +614,7 @@ def icodes():
if m1 < m0:
post.error = \
debug.out(53, '%s) "%s"..."%s"'%(
ln, markers[1], markers[0]
ln, markers[1][1], markers[1][0]
), post.uri, True,2, False)
return False
@ -582,7 +622,7 @@ def icodes():
if m0 >= 0 and m1 == -1:
post.error = \
debug.out(53, '%s) ..."%s"'%(
ln, markers[1]
ln, markers[1][1]
), post.uri, True,2, False)
return False
@ -590,51 +630,46 @@ def icodes():
elif m1 >= 0 and m0 == -1:
post.error = \
debug.out(53, '%s) "%s"...'%(
ln, markers[0]
ln, markers[1][0]
), post.uri, True,2, False)
return False
if post.words_markers[0][0] in line:
line = line.replace(post.words_markers[0][0], post.words_markers[0][4])
line = line.replace(post.words_markers[0][1], post.words_markers[0][5])
icodes = re.findall('%s(.*?)%s'%(
post.words_markers[0][4], post.words_markers[0][5]
), line)
if markers[0][0] in line:
# Double mark first
line = line.replace(markers[0][0], markers[0][4])
line = line.replace(markers[0][1], markers[0][5])
icodes = re.findall('%s(.*?)%s'%(markers[0][4], markers[0][5]), line)
for icode in icodes:
post.stats_text_icodes += 1
icnew = post.words_markers[0][4] + icode + post.words_markers[0][5]
icnew = markers[0][4] + icode + markers[0][5]
line = line.replace(icnew, "")
# Set HTML [ICODES] to post database
icode_var = "icode_%s"%post.stats_text_icodes
icleg = post.words_markers[0][0] + icode + post.words_markers[0][1]
icleg = markers[0][0] + icode + markers[0][1]
html_var = "html_%s"%post.stats_text_icodes
html_val = icnew.replace(post.words_markers[0][4],
post.words_markers[0][2]%css)
html_val = html_val.replace(post.words_markers[0][5],
post.words_markers[0][3])
html_val = icnew.replace(markers[0][4], markers[0][2]%css)
html_val = html_val.replace(markers[0][5], markers[0][3])
post.cf_set("ICODES", icode_var, icleg)
post.cf_set("ICODES", html_var, html_val)
line = line.replace(post.words_markers[1][0], post.words_markers[1][4])
line = line.replace(post.words_markers[1][1], post.words_markers[1][5])
icodes = re.findall('%s(.*?)%s'%(
post.words_markers[1][4], post.words_markers[1][5]
), line)
# Single mark
line = line.replace(markers[1][0], markers[1][4])
line = line.replace(markers[1][1], markers[1][5])
icodes = re.findall('%s(.*?)%s'%(markers[1][4], markers[1][5]), line)
for icode in icodes:
post.stats_text_icodes += 1
icnew = post.words_markers[1][4] + icode + post.words_markers[1][5]
icnew = markers[1][4] + icode + markers[1][5]
line = line.replace(icnew, "")
# Set HTML [ICODES] to post database
icode_var = "icode_%s"%post.stats_text_icodes
icleg = post.words_markers[1][0] + icode + post.words_markers[1][1]
icleg = markers[1][0] + icode + markers[1][1]
html_var = "html_%s"%post.stats_text_icodes
html_val = icnew.replace(post.words_markers[1][4],
post.words_markers[1][2]%css)
html_val = html_val.replace(post.words_markers[1][5],
post.words_markers[1][3])
html_val = icnew.replace(markers[1][4], markers[1][2]%css)
html_val = html_val.replace(markers[1][5], markers[1][3])
post.cf_set("ICODES", icode_var, icleg)
post.cf_set("ICODES", html_var, html_val)
@ -644,12 +679,13 @@ def icodes():
#============================#
# start line single tags #
# Check optional title tags #
# Count tyto + html comments #
# Add stat for _image:logo #
# Return True/False #
#----------------------------#
def sl_tags():
def sl_stags():
for ln, line in enumerate(texts, post.head_lines + 1):
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
@ -776,8 +812,9 @@ def cf_update_values():
post.cf_set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
post.cf_set("STATS_TEXTS", "html_coms", str(post.stats_html_coms))
post.cf_set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf_set("STATS_TEXTS", "bcodes", str(post.stats_bcodes))
post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))
#post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))
post.cf_set("STATS_TEXTS", "bcodes", str(post.ptags_stats["bcodes"]))
post.cf_set("STATS_TEXTS", "quotes", str(post.ptags_stats["quotes"]))
# Founds from header tags
post.cf_set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf_set("STATS_TEXTS", "files", str(post.stats_text_files))

View File

@ -255,12 +255,11 @@ def cf_update_values(write):
srv = cf_set("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/")
cf_set("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/")
cf_set("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/")
cf_set("SERVER", "domain", srv_name)
cf_set("SERVER", "wip", wip)
cf_set("SERVER", "www", www)
@ -268,12 +267,11 @@ def cf_update_values(write):
# ==========
global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/")
cf_set("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/")
cf_set("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/")
cf_set("WIP_DIRS", "template", wip_tpl)
cf_set("WIP_DIRS", "images", wip_images)
cf_set("WIP_DIRS", "files", wip_files)
@ -281,25 +279,22 @@ def cf_update_values(write):
# ==========
global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/")
cf_set("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/")
cf_set("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/")
cf_set("WWW_DIRS", "template", www_tpl)
cf_set("WWW_DIRS", "images", www_images)
cf_set("WWW_DIRS", "files", www_files)
# [WEBSITE]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set("WEBSITE", "wip_url", create_wip_url())
wip_url = cf_set("WEBSITE", "wip_url", "") or \
cf_set("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set("WEBSITE", "www_url", "https://%s/"%name)
www_url = cf_set("WEBSITE", "www_url", "") or \
cf_set("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set("WEBSITE", "lang", "")
if not lang:
@ -308,9 +303,8 @@ def cf_update_values(write):
lang = langs.get_sys_lang()
langs.load_website_lang()
css = cf_set("WEBSITE", "css", "")
if not css:
css = cf_set("WEBSITE", "css", "tyto")
css = cf_set("WEBSITE", "css", "") or \
cf_set("WEBSITE", "css", "tyto")
sep = cf_set("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
@ -328,10 +322,8 @@ def cf_update_values(write):
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title)
sidebar_title = cf_set("WEBSITE_MODULES", "sidebar_title", "") or \
cf_set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title)
sidebar_items = cf_set("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
@ -348,25 +340,20 @@ def cf_update_values(write):
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set("TEMPLATE_FILENAMES", "favicon", "favicon.png")
favicon = cf_set("TEMPLATE_FILENAMES", "favicon", "") or \
cf_set("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set("TEMPLATE_FILENAMES", "logo", "logo.png")
logo = cf_set("TEMPLATE_FILENAMES", "logo", "") or \
cf_set("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set("TEMPLATE_FILENAMES", "styles", "styles.css")
styles = cf_set("TEMPLATE_FILENAMES", "styles", "") or \
cf_set("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set("TEMPLATE_FILENAMES", "rss", "rss.xml")
rss = cf_set("TEMPLATE_FILENAMES", "rss", "") or \
cf_set("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
stats = cf_set("TEMPLATE_FILENAMES", "stats", "") or \
cf_set("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS]
@ -384,12 +371,11 @@ def cf_update_values(write):
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
cf_set("USER_TEMPLATE_FILES", "logo", wrk_logo)
cf_set("USER_TEMPLATE_FILES", "styles", wrk_styles)
@ -397,18 +383,15 @@ def cf_update_values(write):
# ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set("USER_MODULES_FILES", "metas", wrk_metas)
cf_set("USER_MODULES_FILES", "header", wrk_header)
cf_set("USER_MODULES_FILES", "navbar", wrk_navbar)
cf_set("USER_MODULES_FILES", "sidebar", wrk_sidebar)
cf_set("USER_MODULES_FILES", "footer", wrk_footer)
@ -416,34 +399,28 @@ def cf_update_values(write):
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo)
cf_set("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles)
cf_set("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss)
cf_set("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats)
cf_set("WIP_FILES", "favicon", wip_favicon)
cf_set("WIP_FILES", "logo", wip_logo)
cf_set("WIP_FILES", "styles", wip_styles)
cf_set("WIP_FILES", "rss", wip_rss)
cf_set("WIP_FILES", "stats", wip_stats)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html")
cf_set("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set("WIP_FILES", "metas", wip_metas)
cf_set("WIP_FILES", "header", wip_header)
cf_set("WIP_FILES", "navbar", wip_navbar)
cf_set("WIP_FILES", "sidebar", wip_sidebar)
cf_set("WIP_FILES", "footer", wip_footer)
@ -451,34 +428,28 @@ def cf_update_values(write):
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo)
cf_set("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles)
cf_set("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss)
cf_set("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats)
cf_set("WWW_FILES", "favicon", www_favicon)
cf_set("WWW_FILES", "logo", www_logo)
cf_set("WWW_FILES", "styles", www_styles)
cf_set("WWW_FILES", "rss", www_rss)
cf_set("WWW_FILES", "stats", www_stats)
global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html")
cf_set("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html")
cf_set("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html")
cf_set("WWW_FILES", "metas", www_metas)
cf_set("WWW_FILES", "header", www_header)
cf_set("WWW_FILES", "navbar", www_navbar)
cf_set("WWW_FILES", "sidebar", www_sidebar)
cf_set("WWW_FILES", "footer", www_footer)

View File

@ -318,6 +318,21 @@ quotes = ("[[", "]]")
parags = ("((", "))")
lists = ("<<", ">>", "=", "+")
# Paired markers
ptags = (
("{{", "}}", "bcodes"),
("[[", "]]", "quotes"),
("((", "))", "parags"),
("<<", ">>", "lists" ),
)
ptags_stats = {
"bcodes" : stats_bcodes,
"quotes" : stats_quotes,
"parags" : stats_parags,
"lists" : stats_lists,
}
# Tyto Titles #1 = <h2>
tyto_titles = ("#1", "#2", "#3", "#4", "#5")
html_titles = {
@ -335,10 +350,6 @@ text_comments = (";;", "<!--")
html_parag_start = (parags[0], '<p class="%s%s">')
html_parag_close = (parags[1], '</p>')
# IN-texts contents markers (bold, icodes...)
icodes = ("{_", "_}")
# Specifics convertion
words_markers = \
(
@ -374,6 +385,8 @@ ini_template = """[DOMAIN]
[BCODES]
[QUOTES]
[RAWS]
[CODES]

View File

@ -67,6 +67,16 @@ def bcode(lines):
return html_lines
#
#
#
def quote(lines):
print("wip!")
print(lines)
return lines
#============================#
# code #
# Used by check module that #