New user URI process

This commit is contained in:
Cyrille L 2023-04-10 02:01:24 +02:00
parent 7d36fb858d
commit 405cdde94d
12 changed files with 230 additions and 63 deletions

View File

@ -59,6 +59,7 @@ target = args.set_target()
import dom, status import dom, status
status.domain() status.domain()
# Command start argument # Command start argument
import check, form, html, new, publish, show, wip, infos import check, form, html, new, publish, show, wip, infos
actions = { actions = {

View File

@ -0,0 +1,138 @@
/*
* All class / ID used by Tyto - Littérateur in a page
* DOMAIN MUST be changed by domain css set in configuration
*/
/*
* Header
*/
header#header_page {
}
div#site_logo {
}
a#site_logo_link {
}
img#site_logo_image {
}
div#site_infos {
}
a#site_link {
}
h1#site_title {
}
p#site_about {
}
/*
* navbar
*/
nav#site_menu {
}
ul#site_menu_items {
}
li.site_menu_item {
}
a.site_menu_link {
}
/*
* article
*/
article#article_main {
}
h1#main_title {
}
h2.title_2 {
}
h3.title_3 {
}
h4.title_4 {
}
h5.title_5 {
}
h6.title_6 {
}
/* Between every <h2-6> IF CONTENTS */
div.contents {
}
/* Default if not set in post */
p.DOMAIN {
}
br.DOMAIN {
}
a.link {
}
a.anchor_link {
}
abbr.DOMAIN {
}
img.DOMAIN_image {
}
code.icode {
}
ul.DOMAIN {
}
li.DOMAIN
strong.strong {
}
b.bold {
}
em.em{
}
i.italic {
}
del.del {
}
u.underline {
}
cite.cite {
}
span.custom {
}
/* section for author and date */
section#article_infos {
}
span#article_author {
}
span#article_pub {
}
span#article_code {
}
a#article_code_link {
}
/*
* sidebar
*/
/*
* footer
*/

View File

@ -33,7 +33,7 @@
#********************************************************************** #**********************************************************************
import sys import os, sys
import infos, logs import infos, logs
@ -123,11 +123,6 @@ try: target = sys.argv[2]
except: target = '' except: target = ''
# Some conditions exiting
#if action == "check" and target == "newer":
# logs.out("11", '"%s" with "%s"'%(target, action), True)
# Set action and target for binary # Set action and target for binary
def set_action(): def set_action():
return(action) return(action)

View File

@ -40,7 +40,7 @@ from datetime import datetime
from time import gmtime, strftime from time import gmtime, strftime
import args, dom, logs, status, db, form, tyto, langs import args, dom, logs, status, db, form, tyto, langs
domain_dir = post_err = False domain_dir = post_err = multi_chk = False
#=========================# #=========================#
@ -68,8 +68,8 @@ def manage(target):
logs.out("1", db.uri_file, True) logs.out("1", db.uri_file, True)
# Already check # Already check
elif db.exists \ elif db.exists and not db.old_chk:
and not db.old_chk: print(' ├─ [%s] > %s'%(db.title, db.uri_file))
logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False) logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False)
answer = form.asking('%s%s '%( answer = form.asking('%s%s '%(
langs.site.check_a, langs.site.q langs.site.check_a, langs.site.q
@ -112,13 +112,15 @@ def check_module(target):
# but check only if article source has changed # # but check only if article source has changed #
#----------------------------------------------# #----------------------------------------------#
def check_all(option): def check_all(option):
global domain_dir global multi_chk
multi_chk = True
found = False found = False
# With [added], article must NOT have a DB
# Search every .tyto in domain from articles/
# Then Do a check, and return
#-----------------------------------------
if option == "added": if option == "added":
os.chdir(dom.articles_d)
domain_dir = True
for root, dirs, files in os.walk(dom.articles_d[:-1]): for root, dirs, files in os.walk(dom.articles_d[:-1]):
for file in files: for file in files:
if (file.endswith('.tyto')): if (file.endswith('.tyto')):
@ -134,14 +136,17 @@ def check_all(option):
print() print()
return return
# With [updated], Article must have changed
# with [again], force check
# Article must have a DB
#------------------------------------------
for post_db in os.listdir(dom.articles_db_d): for post_db in os.listdir(dom.articles_db_d):
if post_db.endswith('.config'): if post_db.endswith('.config'):
# Load DB # Load DB
post_db = '%s%s'%(dom.articles_db_d, post_db) post_db = '%s%s'%(dom.articles_db_d, post_db)
try: try:
exec(open(post_db).read(),globals()) exec(open(post_db).read(),globals())
args.target = post_src.rsplit('%s/'%db.in_dir)[1] args.target = short_src
importlib.reload(db) importlib.reload(db)
except: except:
continue continue
@ -161,7 +166,8 @@ def check_all(option):
# Check articles process # # Check articles process #
#------------------------# #------------------------#
def check_process(target): def check_process(target):
if not db.post: sys.exit(1) if not db.post:
logs.out("1", db.post, True)
global post_bottom, article_bottom global post_bottom, article_bottom
global date_wip, hash_wip, date_www, hash_www, post_bottom global date_wip, hash_wip, date_www, hash_www, post_bottom
@ -964,5 +970,7 @@ def create_database():
#--------------- #---------------
database = '%s\n%s\n%s'%(database, opt_tags, db_stats) database = '%s\n%s\n%s'%(database, opt_tags, db_stats)
tyto.set_file(db.config, 'New', database) tyto.set_file(db.config, 'New', database)
logs.out("21", db.uri_file, False)
if not multi_chk:
logs.out("21", db.uri_file, False)

View File

@ -34,16 +34,12 @@
#********************************************************************** #**********************************************************************
import os import os
import args, logs, dom, form, tyto, check import args, logs, dom, form, tyto, check, publish
remove = exists = post = corrupt = False remove = exists = post = corrupt = False
try: if dom.hole:
# with check newer, use domain root directory logs.out("13", '', True)
if check.domain_dir:
os.chdir(dom.articles_d)
in_dir = os.getcwd()
except: logs.out("13", '', True)
# target needs db (file). # target needs db (file).
@ -56,7 +52,7 @@ if args.target \
# Domain must be valid # Domain must be valid
if not dom.exists: logs.out("10", '', True) if not dom.exists: logs.out("10", '', True)
uri_file = '%s/%s'%(in_dir, args.target) uri_file = '%s%s'%(dom.articles_d, args.target)
uri_id = tyto.get_filesum(uri_file, False) uri_id = tyto.get_filesum(uri_file, False)
# Set DB file # Set DB file

View File

@ -34,15 +34,21 @@
#********************************************************************** #**********************************************************************
import os, sys, importlib, langs import os, sys, importlib, langs
import args
lib = 'tyto_domain' lib = 'tyto_domain'
exists = incomplete = active = ready = shortname = corrupt = False exists = incomplete = active = ready = shortname = corrupt = False
local_user = articles_db_d = False local_user = articles_db_d = False
hole = False hole = False
# Set current directory # Set current directory
try: in_dir = os.getcwd() try:
except: hole = True user_dir
except:
try:
user_dir = os.getcwd() + "/"
except:
hole = True
# Settings for domain, check if db is not corrupted # Settings for domain, check if db is not corrupted
dom_values = \ dom_values = \
@ -133,12 +139,12 @@ if not hole:
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
# Set configuration domain directory # Set configuration domain directory
folder = in_dir root_dir = user_dir
if '/articles' in in_dir: if '/articles' in user_dir:
folder = in_dir.rsplit('/articles')[0] root_dir = user_dir.rsplit('/articles')[0] + "/"
# Set configuration domain file # Set configuration domain file
config = '%s/tyto_domain.py'%folder config = '%styto_domain.py'%root_dir
shortname = config shortname = config
# Set exists if configuration file # Set exists if configuration file
@ -146,8 +152,16 @@ if not hole:
exists = True exists = True
try: try:
exec(open(config).read()) exec(open(config).read())
try:
os.path.exists(articles_d)
user_uri_dir = user_dir.rsplit(articles_d)[1]
os.chdir(articles_d)
except: corrupt = True
except: except:
corrupt = True corrupt = True
if not args.target in args.pass_targets:
args.target = user_uri_dir + args.target
# For logs: show uri if not shortname known # For logs: show uri if not shortname known
try: shortname try: shortname

View File

@ -165,8 +165,8 @@ def create_main_page(target, article_bottom):
' </a>\n' + \ ' </a>\n' + \
' <p id="site_about">%s</p>\n'%dom.about + \ ' <p id="site_about">%s</p>\n'%dom.about + \
' </div>\n' + \ ' </div>\n' + \
'<!--# include virtual="/template/navbar.html"-->\n' + \
' </header>\n' + \ ' </header>\n' + \
'<!--# include virtual="/template/navbar.html"-->\n' + \
'\n' + \ '\n' + \
' <article id="article_main">\n' + \ ' <article id="article_main">\n' + \
' <h1 id="main_title"\n' + \ ' <h1 id="main_title"\n' + \
@ -295,8 +295,8 @@ def create_navbar(option):
# Set first HTML line # Set first HTML line
menu_html = \ menu_html = \
'%s<nav id="site_menu">\n'%(6 * ' ') + \ '%s<nav id="site_menu">\n'%(4 * ' ') + \
'%s<ul id="site_menu_items">'%(8 * ' ') '%s<ul id="site_menu_items">'%(6 * ' ')
navbar_lines = open(dom.navbar_f, 'r').read() navbar_lines = open(dom.navbar_f, 'r').read()
@ -353,13 +353,13 @@ def create_navbar(option):
# Add link to HTML structure # Add link to HTML structure
navbar_items = True navbar_items = True
menu_item = \ menu_item = \
'\n%s<li class="site_menu_item">\n'%(10 * ' ') + \ '\n%s<li class="site_menu_item">\n'%(8 * ' ') + \
'%s<a class="site_menu_link"\n'%(12 * ' ') + \ '%s<a class="site_menu_link"\n'%(10 * ' ') + \
'%s'%title + \ '%s'%title + \
'%shref="/%s/">%s</a>\n'%( '%shref="/%s/">%s</a>\n'%(
15 * ' ', direc, direc 15 * ' ', direc, direc
) + \ ) + \
'%s</li>'%(10 * ' ') '%s</li>'%(8 * ' ')
menu_html = '%s%s'%(menu_html, menu_item) menu_html = '%s%s'%(menu_html, menu_item)

View File

@ -50,7 +50,7 @@ def manage_publish(target):
#----------------------------------------- #-----------------------------------------
if target in args.pass_targets: if target in args.pass_targets:
do = { do = {
'updated' : publish_all, 'updated' : publish_all,
'again' : publish_all, 'again' : publish_all,
'added' : publish_all, 'added' : publish_all,
'sidebar' : html.create_sidebar, 'sidebar' : html.create_sidebar,
@ -82,8 +82,8 @@ def manage_publish(target):
#---------------# #---------------#
def publish_article(): def publish_article():
# Copy wip page to www page # Copy wip page to www page
os.makedirs('%s%s'%(dom.srv_www, db.direc_src), exist_ok=True) if not os.makedirs('%s%s'%(dom.srv_www, db.direc_src), exist_ok=True):
logs.out("33", '%s%s'%(dom.srv_www, db.direc_src), False) logs.out("33", '%s%s'%(dom.srv_www, db.direc_src), False)
# Replace in DB hash_wip and date_wip # Replace in DB hash_wip and date_wip
tyto.replace_in_db(db.config, 'www', db.hash_post) tyto.replace_in_db(db.config, 'www', db.hash_post)
@ -188,10 +188,20 @@ def publish_template(option):
#--------------------------------------------# #--------------------------------------------#
def publish_all(option): def publish_all(option):
# Ask or show what to do # Ask or show what to do
tyto.process_all('Publish') if args.target == "again":
form.asking("%s%s "%(
langs.site.wip_again, langs.site.q
), True)
elif args.target == "addedd":
print('%s'%langs.site.wip_older)
#os.chdir(dom.articles_d)
elif args.target == "updated":
print('%s'%langs.site.wip_newer)
# Sort by newer articles (created by last check) # Sort by newer articles (created by last check)
db_articles = sorted(Path(db.articles_db).iterdir(), db_articles = sorted(Path(dom.articles_db_d).iterdir(),
key=os.path.getmtime key=os.path.getmtime
) )
@ -199,18 +209,17 @@ def publish_all(option):
option = args.target option = args.target
found = False found = False
for post_db in db_articles: for post_db in db_articles:
if not str(post_db).endswith('.conf'): continue if not str(post_db).endswith('.config'): continue
# Load DB # Load DB
exec(open(post_db).read(),globals()) exec(open(post_db).read(),globals())
args.target = post_src.rsplit('%s/'%db.in_dir)[1] args.target = short_src
importlib.reload(db) importlib.reload(db)
if not db.hash_wip: continue if not db.hash_wip: continue
if option == "again" and not db.sync_srvs: continue if option == "again" and not db.sync_srvs: continue
if option == "added" and not db.old_www: continue if option == "added" and not db.old_www: continue
print(':> [%s] - %s'%(db.title, db.post_src))
if db.old_chk: if db.old_chk:
logs.out("9", '', False) logs.out("9", '', False)
continue continue
@ -235,6 +244,8 @@ def check_to_publish(process):
global err_pub global err_pub
err_pub = False err_pub = False
print('\n ├─ [%s] > %s'%(db.title, db.post_src))
# Article was not checked or changed # Article was not checked or changed
if db.no_chk: if db.no_chk:
logs.out("25", db.uri_file, False) logs.out("25", db.uri_file, False)

View File

@ -33,16 +33,20 @@
#********************************************************************** #**********************************************************************
import dom, logs, tyto, form import args, dom, logs, tyto, form
print("")
def domain(): def domain():
if dom.hole: logs.out("13", '', True) if dom.hole: logs.out("13", '', True)
elif dom.corrupt: logs.out("39", dom.shortname, True) elif dom.corrupt: logs.out("39", dom.shortname, True)
#elif not dom.shortname: return
elif dom.incomplete: logs.out("41", dom.shortname, False) elif dom.incomplete: logs.out("41", dom.shortname, False)
elif dom.active: logs.out("42", dom.shortname, False) elif dom.active: logs.out("42", dom.shortname, False)
elif not dom.active: logs.out("40", dom.shortname, False) elif not dom.active: logs.out("40", dom.shortname, False)
# No backward in target
if "../" in args.target:
logs.out("11", '"../"', True)
# Show unused values # Show unused values
for err_val in dom.err_val: for err_val in dom.err_val:
logs.out("16", err_val, False) logs.out("16", err_val, False)

View File

@ -124,7 +124,7 @@ words_tags = [
# Tags that do not need to be paired # Tags that do not need to be paired
#----------------------------------- #-----------------------------------
single_tags = [ single_tags = [
('|', '<br />'), # New Line ('|', '<br class="%s" />'), # New Line
('->', '<a class="anchor_target" id="%s"></a>') # Anchors ('->', '<a class="anchor_target" id="%s"></a>') # Anchors
] ]
@ -521,8 +521,8 @@ def files_to_srv(server):
# Create sub-directories in server # Create sub-directories in server
try: try:
os.makedirs(d_dst, exist_ok=True) if os.makedirs(d_dst, exist_ok=True):
logs.out("33", d_dst, False) logs.out("33", d_dst, False)
except: except:
logs.out('4', d_dst, True) logs.out('4', d_dst, True)

View File

@ -126,7 +126,7 @@ def wip_all(process):
# Load DB # Load DB
try: try:
exec(open(post_db).read(),globals()) exec(open(post_db).read(),globals())
args.target = post_src.rsplit('%s/'%db.in_dir)[1] args.target = short_src
importlib.reload(db) importlib.reload(db)
except: except:
continue continue
@ -151,7 +151,7 @@ def wip_all(process):
found = True found = True
wip_article(db.post_src) wip_article(db.post_src)
if not found: logs.out("28", '(wip)', True) if not found: sys.exit(28)
#===================# #===================#
@ -201,8 +201,8 @@ def wip_article(target):
#print(html.main_page) #print(html.main_page)
# Create wip file # Create wip file
os.makedirs('%s%s'%(dom.srv_wip, db.direc_src), exist_ok=True) if os.makedirs('%s%s'%(dom.srv_wip, db.direc_src), exist_ok=True):
logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False) logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False)
tyto.set_file(db.post_wip, 'New', html.main_page) tyto.set_file(db.post_wip, 'New', html.main_page)
# Copy needed files (Also create sub-folders) # Copy needed files (Also create sub-folders)
@ -247,7 +247,7 @@ def replace_in_post(src, html):
def wip_single_tags(): def wip_single_tags():
# <br /> from "|" # <br /> from "|"
replace_in_post(tyto.single_tags[0][0], replace_in_post(tyto.single_tags[0][0],
tyto.single_tags[0][1] tyto.single_tags[0][1]%dom.css
) )
# Anchor source # Anchor source
@ -812,7 +812,7 @@ def wip_lists():
'<ul class="%s">'%css, 1 '<ul class="%s">'%css, 1
).replace('<li>', ).replace('<li>',
'<li class="%s">'%css '<li class="%s">'%css
) + '</ul>' )
replace_in_post(content_list, html_list) replace_in_post(content_list, html_list)
if in_list: if in_list:

View File

@ -41,7 +41,7 @@ file_e = "Fichier présent"
dir_c = "Dossier créé" dir_c = "Dossier créé"
dir_e = "Dossier présent" dir_e = "Dossier présent"
was_chk = "Article déjà vérifié" was_chk = "Article déjà vérifié"
was_wip = "Article déjà 'wip'" was_wip = "Article déjà 'wip'"
check_m = "Vérifier manuellement" check_m = "Vérifier manuellement"
post_inc = "Donnée manquante dans l'article" post_inc = "Donnée manquante dans l'article"