From 29ee8cc704e8ecbce9fb1968e8a95d5eb5f25761 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Sun, 2 Apr 2023 15:59:06 +0200 Subject: [PATCH] New processes and updated codes --- src/usr/bin/tyto | 2 +- src/var/lib/tyto/program/args.py | 109 ++++++---- src/var/lib/tyto/program/check.py | 37 ++-- src/var/lib/tyto/program/db.py | 4 +- src/var/lib/tyto/program/dom.py | 258 +++++++++++++---------- src/var/lib/tyto/program/form.py | 192 +++++++++-------- src/var/lib/tyto/program/html.py | 159 +++++++------- src/var/lib/tyto/program/infos.py | 52 +---- src/var/lib/tyto/program/logs.py | 8 +- src/var/lib/tyto/program/show.py | 35 +-- src/var/lib/tyto/program/status.py | 34 ++- src/var/lib/tyto/program/tyto.py | 98 ++++----- src/var/lib/tyto/program/wip.py | 60 ++---- src/var/lib/tyto/translations/logs_en.py | 15 +- src/var/lib/tyto/translations/logs_fr.py | 13 +- src/var/lib/tyto/translations/site_en.py | 62 ++++++ src/var/lib/tyto/translations/site_fr.py | 64 +++++- src/var/lib/tyto/tyto_domain.default | 75 +++++++ 18 files changed, 742 insertions(+), 535 deletions(-) create mode 100644 src/var/lib/tyto/tyto_domain.default diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 8144919..f4c9f0f 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -64,7 +64,7 @@ actions = { 'show-www' : show.manage, 'status' : status.check, 'template' : publish.manage_publish, - 'wip' : wip.manage_wip, + 'wip' : wip.manage, } diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py index 2c9a86c..86bba91 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -1,11 +1,27 @@ #!/usr/bin/env python3 -# Name: Tyto - Littérateur -# Type: Command arguments -# Description: Check arguments -# file: args.py -# Folder: /var/lib/tyto/program/ -# By echolib (XMPP: im@echolib.re) -# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 +# Tyto - Littérateur +# +# Copyright (C) 2023 Cyrille Louarn +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of the +# License, or of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +#---------------------------------------------------------------------- +# XMPP: echolib (im@echolib.re) +# +# Description: Manage arguments from command line +# File: /var/lib/tyto/program/args.py +#---------------------------------------------------------------------- #------------ # funny stats @@ -20,27 +36,28 @@ import sys import infos, logs + # Arguments from command line # tyto [action] [target] #---------------------------- actions = \ ( - 'check', - 'edit', - 'edit-about', - 'edit-db', - 'edit-wip', - 'edit-www', - 'help', - 'new', - 'show', - 'show-about', - 'show-db', - 'show-wip', - 'show-www', - 'status', - 'wip', - 'publish' +'check', +'edit', +'edit-about', +'edit-db', +'edit-wip', +'edit-www', +'help', +'new', +'show', +'show-about', +'show-db', +'show-wip', +'show-www', +'status', +'wip', +'publish' ) pass_actions = ( @@ -51,35 +68,35 @@ pass_actions = ( # Actions that needs to check for article's database pass_db = \ ( - 'check', - 'edit', - 'edit-db', - 'edit-wip', - 'edit-www', - 'publish', - 'show', - 'show-about', - 'show-db', - 'show-wip', - 'show-www', - 'wip', +'check', +'edit', +'edit-db', +'edit-wip', +'edit-www', +'publish', +'show', +'show-about', +'show-db', +'show-wip', +'show-www', +'wip', ) pass_targets = \ ( - 'all', - 'again', - 'newer', - 'domain', - 'footer', - 'metas', - 'navbar', - 'sidebar', - 'stats', - 'template' +'all', +'again', +'newer', +'domain', +'footer', +'metas', +'navbar', +'sidebar', +'stats', +'template' ) -multi_chk = ('all', 'again') +multi_chk = ('all', 'again', 'newer') action = '' target = '' diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 73f7a96..3d9bc0c 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -38,7 +38,6 @@ import time, importlib, sys, os, re, datetime from datetime import datetime from time import gmtime, strftime - import args, dom, logs, status, db, form, tyto, langs post_err = False @@ -53,27 +52,23 @@ def manage(target): # target needed if not target: - logs.out("5", args.action, True) + logs.out("5", '[target]', True) + + elif target in args.multi_chk: + check_all(target) + + elif not db.post: + logs.out("1", db.uri_file, True) # Already check - elif not target in args.multi_chk \ - and db.exists \ + elif db.exists \ and not db.old_chk: logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False) answer = form.asking(' ├ %s%s '%( langs.site.check_a, langs.site.q - ), True) - + ), True) check_process(target) - # All - elif target in args.multi_chk: - check_all(target) - - # No file found - elif not db.post: - sys.exit(1) - else: check_process(target) @@ -98,7 +93,7 @@ def check_all(option): importlib.reload(db) #print(':> [%s] - %s'%(db.title, db.post_src)) - if not db.exists: continue + if not db.exists: continue if option == 'all' and not db.old_chk: continue found = True @@ -367,9 +362,10 @@ def check_needed_tags(post_header): # Create False date_check # #--------------------------------# def check_date(date): - global post_err + global post_err, date_tr # Check if article date is valid (True) + date_tr = date fmt_article = "%Y-%m-%d" try: @@ -387,10 +383,9 @@ def check_date(date): # Set franch format in post DB if dom.lang_site == 'fr': - date = date.rsplit('-') - date = date[2] + '/' + date[1] + '/' + date[0] - - date = (date, date_check) + date = date.rsplit('-') + date_tr = date[2] + '/' + date[1] + '/' + date[0] + print("> Convert date in FR >", date_tr) #===========================================# @@ -750,7 +745,7 @@ def create_database(): 'about = "%s"\n'%about + \ 'author = "%s"\n'%author + \ 'tags = "%s"\n'%tags + \ - 'date = "%s"\n'%date + \ + 'date = "%s"\n'%date_tr + \ 'snpic = "%s"\n'%snpic_url + \ '\n# Used files\n' + \ 'uris = %s'%str(files_post) diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py index df750ac..8ed7559 100644 --- a/src/var/lib/tyto/program/db.py +++ b/src/var/lib/tyto/program/db.py @@ -18,7 +18,6 @@ #********************************************************************** import os - import args, logs, dom, form, tyto remove = exists = post = corrupt = False @@ -26,6 +25,7 @@ remove = exists = post = corrupt = False try: in_dir = os.getcwd() except: logs.out("13", '', True) + # target needs db (file). # action like show, wip, edit-db # not domain, all, again... @@ -52,9 +52,7 @@ if args.target \ post = True hash_post = tyto.get_filesum(uri_file, True) else: - post = False remove = True - logs.out("1", uri_file, False) # Check if database config is valid (contains values) if exists: diff --git a/src/var/lib/tyto/program/dom.py b/src/var/lib/tyto/program/dom.py index a3f7c97..b5d0b8f 100644 --- a/src/var/lib/tyto/program/dom.py +++ b/src/var/lib/tyto/program/dom.py @@ -1,11 +1,27 @@ #!/usr/bin/env python3 -# Name: Tyto - Littérateur -# Type: DB for domain -# Description: Search domain datas and get statuses -# file: dom.py -# Folder: /var/lib/tyto/program/ -# By echolib (XMPP: im@echolib.re) -# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 +# Tyto - Littérateur +# +# Copyright (C) 2023 Cyrille Louarn +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of the +# License, or of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +#---------------------------------------------------------------------- +# XMPP: echolib (im@echolib.re) +# +# Description: Manage domain configuration +# File: /var/lib/tyto/program/dom.py +#---------------------------------------------------------------------- #------------ # funny stats @@ -17,17 +33,99 @@ #********************************************************************** -import os, sys, importlib, locale +import os, sys, importlib, langs lib = 'tyto_domain' exists = incomplete = active = ready = shortname = False -local_user = articles_db = activated = False +local_user = articles_db_d = False hole = False # Set current directory try: in_dir = os.getcwd() except: hole = True +# Settings for domain, check if db is not corrupted +dom_values = \ +( +'directory', +'database', +'local_user', +'lang_sys', +'lang_logs', +'articles_db_d', +'articles_d', +'files_d', +'images_d', +'modules_d', +'navbar_f', +'sidebar_f', +'metas_f', +'footer_f', +'footer_about_f', +'shortname', +'www_url', +'wip_url', +'srv_root', +'srv_domain', +'srv_wip', +'srv_wip_tpl_d', +'srv_wip_images_d', +'srv_wip_files_d', +'srv_www', +'srv_www_tpl_d', +'srv_www_images_d', +'srv_www_files_d', +'wip_css_f', +'wip_logo_f', +'wip_navbar_f', +'wip_sidebar_f', +'wip_metas_f', +'wip_footer_f', +'www_css_f', +'www_navbar_f', +'www_sidebar_f', +'www_metas_f', +'www_footer_f', +'www_logo_f', +'www_rss_f', +'logo', +'rss', +'rss_items', +'title', +'date', +'about', +'lang_site', +'mail', +'tags', +'license', +'license_url', +'legal_url', +'terms_url', +'css', +'sep', +'article_code', +'relme', +'sidebar_title', +'sidebar_items', +'activated' +) + +create_files = \ +( +'navbar_f', +'sidebar_f', +'metas_f', +'footer_f', +'footer_about_f' +) + +err_val = (()) # Make a list from values error +file_unu = (()) # Make a list for files to check +file_mod = (()) # male a list for modules files to create +dir_new = (()) # Make a list for directories created +dir_unu = (()) # Not created, unused + + if not hole: home_dir = os.path.expanduser('~') @@ -39,7 +137,7 @@ if not hole: # Set configuration domain file config = '%s/tyto_domain.py'%folder - # Set exists if configuration file + # Set exists if configuration file if os.path.exists(config): exists = True exec(open(config).read()) @@ -48,112 +146,52 @@ if not hole: try: shortname except: shortname = config - if activated: - active = True - # Settings for domain, check if db is not corrupted - dom_values = \ - ( - 'directory', - 'database', - 'local_user', - 'lang_sys', - 'lang_logs', - 'articles_db_d', - 'articles_d', - 'files_d', - 'images_d', - 'modules_d', - 'navbar_f', - 'sidebar_f', - 'metas_f', - 'footer_f', - 'footer_about_f', - 'shortname', - 'www_url', - 'wip_url', - 'srv_root', - 'srv_domain', - 'srv_wip', - 'srv_wip_tpl_d', - 'srv_wip_images_d', - 'srv_wip_files_d', - 'srv_www', - 'srv_www_tpl_d', - 'srv_www_images_d', - 'srv_www_files_d', - 'wip_navbar_f', - 'wip_sidebar_f', - 'wip_metas_f', - 'wip_footer_f', - 'www_navbar_f', - 'www_sidebar_f', - 'www_metas_f', - 'www_footer_f', - 'wip_logo_f', - 'www_logo_f', - 'www_rss_f', - 'logo', - 'rss', - 'rss_items', - 'title', - 'date', - 'about', - 'lang_site', - 'mail', - 'tags', - 'license', - 'license_url', - 'legal_url', - 'terms_url', - 'css', - 'sep', - 'article_code', - 'relme', - 'sidebar_title', - 'sidebar_items', - 'activated' - ) + try: active = activated + except: pass + + for value in dom_values: + try: + eval(str(value)) + value_set = True + except: + err_val = err_val + ((value),) + value_set = False + incomplete = True + active = False - create_files = \ - ( - 'navbar_f', - 'sidebar_f', - 'metas_f', - 'footer_f', - 'footer_about_f' - ) - err_val = (()) # Make a list from values error - dir_new = (()) # Make a list for directories to create - file_new = (()) # Make a list for files to check - file_mod = (()) # male a list for modules files to create - for value in dom_values: - try: - eval(str(value)) - except: - err_val = err_val + ((value),) - incomplete = True - active = False + if value.endswith('_d'): + if value_set: + if not os.path.exists(eval(str(value))): + try: + os.makedirs(eval(str(value)), exist_ok=True) + dir_new = dir_new + ((eval(str(value))),) + except: + dir_unu = dir_unu + ((eval(str(value))),) + + elif value.endswith('_f'): + if value_set: + if not os.path.exists(eval(str(value))): + if value in create_files: + file_mod = file_mod + ((value),) + else: + file_unu = file_unu + ((eval(str(value))),) + + #==============================================# # When an active and complete domain is needed # #----------------------------------------------# - if not incomplete and active: - ready = True - for value in dom_values: - # Check if directory exists and create it - if value.endswith('_d') and \ - not os.path.exists(eval(str(value))): - os.makedirs(eval(str(value)), exist_ok=True) - dir_new = dir_new + ((eval(str(value))),) - - # Check if file exists - if value.endswith('_f') and \ - not os.path.exists(eval(str(value))): - if value in create_files: - file_mod = file_mod + ((value),) - else: - file_new = file_new + ((eval(str(value))),) + if not incomplete: + wip_html_mods = \ + ( + eval(str('wip_navbar_f')), + eval(str('wip_sidebar_f')), + eval(str('wip_metas_f')), + eval(str('wip_footer_f')) + ) + if active: + ready = True #====================================# diff --git a/src/var/lib/tyto/program/form.py b/src/var/lib/tyto/program/form.py index 3e5aad9..82b472c 100644 --- a/src/var/lib/tyto/program/form.py +++ b/src/var/lib/tyto/program/form.py @@ -36,7 +36,7 @@ #********************************************************************** from datetime import datetime -import os, sys, locale, importlib +import os, sys, re, locale, importlib import logs, dom, tyto, html, show, langs @@ -85,7 +85,6 @@ def asking(question, yes_no): # target: 3rd argument # #--------------------------# def manage(target): - if not dom.exists: logs.out("43", '', False) create_domain(target) @@ -100,16 +99,17 @@ def manage(target): # Create a new domain # #---------------------# def create_domain(target): - if target and not target.startswith('http'): + valid_url = ('http://', 'https://') + invalid = False + + if target and not target.startswith(valid_url): logs.out("51", '"%s" -> http(s)://...'%target, False) target = '' print(langs.site.form_start) # Get complete URL from target or ask - #------------------------------------ - valid_url = ('http://', 'https://') - + #------------------------------------ try: www_url = dom.www_url except: @@ -153,7 +153,7 @@ def create_domain(target): answer = asking(' ├ [http(s)://...] %s%s {%s} '%( langs.site.form_wip, langs.site.q, wip_url - ), False) + ), False) if answer: if answer.startswith(valid_url): wip_url = answer else: logs.out("2", '"http(s)://www-wip.%s"%s'%( @@ -172,11 +172,11 @@ def create_domain(target): answer = asking(' ├ %s%s {%s} '%( langs.site.form_trlog, langs.site.q, lang_logs - ), False) + ), False) if answer: if len(answer) == 2: lang_logs = answer.lower() - else: logs.out("3", answer, True) + else: logs.out("3", answer, False) if not tyto.exists('%s/logs_%s.py'%(trans_dir, lang_logs)): lang_logs = 'en' @@ -220,23 +220,37 @@ def create_domain(target): # Get srv root #------------- - try: - srv = dom.srv - except: - if tyto.exists('/var/www') : srv = '/var/www' - else: srv = '' + try: srv = dom.srv + except: srv = '/var/www' answer = asking(' ├ %s%s {%s} '%( langs.site.form_srv, langs.site.q, srv ), False) - if answer: - if tyto.exists(answer): srv = answer - else: logs.out("1", srv, True) - elif not srv: - logs.out("255", '', True) - if srvl[-1] == "/": srv = srv[:-1] + if answer: srv = answer + if not tyto.exists(srv): + logs.out("1", srv, False) + srv = '' + invalid = True + elif srv[-1] == "/": + srv = srv[:-1] + + # Get logo's website + #------------------- + try: logo = dom.logo + except: logo = 'logo.png' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_logo, langs.site.q, logo + ), False) + + if answer: logo = answer + if not logo: logo='logo.png' + + + # Set config's directories for servers + #------------------------------------- root_srv_dom = '%s/%s'%(srv, shortname) srv_wip_tpl = "%s/wip/template/"%root_srv_dom srv_www_tpl = "%s/www/template/"%root_srv_dom @@ -252,11 +266,17 @@ def create_domain(target): 'srv_www_images_d = "%s/www/images/"\n'%root_srv_dom + \ 'srv_www_files_d = "%s/www/files/"\n'%root_srv_dom + \ '\n' + \ - '# Servers files\n' + \ + '# Servers files (wip)\n' + \ + 'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \ + 'wip_css_f = "%sstyles.css"\n'%srv_wip_tpl + \ 'wip_navbar_f = "%snavbar.html"\n'%srv_wip_tpl + \ 'wip_sidebar_f = "%ssidebar.html"\n'%srv_wip_tpl + \ 'wip_metas_f = "%smetas.html"\n'%srv_wip_tpl + \ 'wip_footer_f = "%sfooter.html"\n'%srv_wip_tpl + \ + '\n' + \ + '# Servers files (www)\n' + \ + 'www_logo_f = "%s%s"\n'%(srv_www_tpl, logo) + \ + 'www_css_f = "%sstyles.css"\n'%srv_www_tpl + \ 'www_navbar_f = "%snavbar.html"\n'%srv_www_tpl + \ 'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \ 'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \ @@ -265,23 +285,6 @@ def create_domain(target): tyto.set_file(dom.config, False, set_f) - # Get logo's website - #------------------- - try: logo = dom.logo - except: logo = 'logo.png' - - answer = asking(' ├ %s%s {%s} '%( - langs.site.form_logo, langs.site.q, logo - ), False) - - if answer: logo = answer - - set_f = 'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \ - 'www_logo_f = "%s%s"'%(srv_www_tpl, logo) - - tyto.set_file(dom.config, False, set_f) - - # RSS/Atom filename #------------------ try: rss = dom.rss @@ -304,15 +307,15 @@ def create_domain(target): # RSS/Atom max items #------------------- try: rss_items = dom.rss_items - except: rss_items = "100" + except: rss_items = 100 answer = asking(' ├ %s%s {%s} '%( langs.site.form_rss_i, langs.site.q, rss_items ), False) - if answer: - if answer.isdigit() and int(answer) > 1: rss_items = answer - else: logs.out("3", answer, True) + if answer: rss_items = answer + if not str(rss_items).isdigit() or not int(rss_items) > 1: + rss_items = 100 set_f = 'rss_items = %d'%int(rss_items) tyto.set_file(dom.config, False, set_f) @@ -324,14 +327,13 @@ def create_domain(target): except: title = '' answer = asking(' ├ %s%s {%s} '%( - langs.site.form_title, langs.site.q, title - ), False) + langs.site.form_title, langs.site.q, title + ), False) if answer: title = answer - elif not title: logs.out("255", '', True) - - if '"' in title: title = title.replace('"', '') - + if not title: invalid = True + elif '"' in title: title = title.replace('"', '') + set_f = 'title = "%s"'%title tyto.set_file(dom.config, False, set_f) @@ -360,24 +362,26 @@ def create_domain(target): langs.site.form_about, langs.site.q, about ), False) - if answer: about = answer - elif not about: logs.out("255", '', True) - - if '"' in about: about = about.replace('"', '') - + if answer: about = answer + if not about: invalid = True + elif '"' in about: about = about.replace('"', '') + set_f = 'about = "%s"'%about tyto.set_file(dom.config, False, set_f) # Get Lang domain for web pages #------------------------------ + try: lang_site + except: lang_site = lang_sys + answer = asking(' ├ %s%s {%s} '%( langs.site.form_trsite, langs.site.q, lang_site ), False) if answer: if len(answer) == 2: lang_site = answer.lower() - else: logs.out("3", answer, True) + else: logs.out("3", answer, False) if not tyto.exists('%s/site_%s.py'%(trans_dir, lang_site)): lang_site = 'en' @@ -395,11 +399,10 @@ def create_domain(target): langs.site.form_mail, langs.site.q, mail ), False) - if answer: mail = answer - elif not mail: logs.out("255", '', True) - + if answer: mail = answer if not re.search('^\w+@\w+.\w+$', mail): - logs.out("3", mail, True) + logs.out("3", mail, False) + invalid = True set_f = 'mail = "%s"'%mail tyto.set_file(dom.config, False, set_f) @@ -414,10 +417,9 @@ def create_domain(target): langs.site.form_tags, langs.site.q, tags ), False) - if answer: tags = answer - elif not tags: logs.out("255", '', True) - - if '"' in tags: tags = tags.replace('"', '') + if answer: tags = answer + if not tags: invalid = True + elif '"' in tags: tags = tags.replace('"', '') set_f = 'tags = "%s"'%tags tyto.set_file(dom.config, False, set_f) @@ -432,9 +434,7 @@ def create_domain(target): langs.site.form_lic, langs.site.q, domlicense ), False) - if answer: domlicense = answer - elif not domlicense: logs.out("255", '', True) - + if answer: domlicense = answer if '"' in domlicense: domlicense = domlicense.replace('"', '') set_f = 'license = "%s"'%domlicense @@ -451,9 +451,11 @@ def create_domain(target): langs.site.q, licurl ), False) - if answer: - if answer.startswith(valid_url): licurl = answer - else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) + if answer: licurl = answer + if not licurl.startswith(valid_url): + if answer: + logs.out("2", '"http(s)://%s"%s'%(licurl, langs.site.q), False) + licurl = '' set_f = 'license_url = "%s"'%licurl tyto.set_file(dom.config, False, set_f) @@ -469,9 +471,11 @@ def create_domain(target): langs.site.q, legalurl ), False) - if answer: - if answer.startswith(valid_url): legalurl = answer - else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) + if answer: legalurl = answer + if not legalurl.startswith(valid_url): + if answer: + logs.out("2", '"http(s)://%s"%s'%(legalurl, langs.site.q), False) + legalurl = '' set_f = 'legal_url = "%s"'%legalurl tyto.set_file(dom.config, False, set_f) @@ -487,9 +491,11 @@ def create_domain(target): langs.site.q, termsurl ), False) - if answer: - if answer.startswith(valid_url): termsurl = answer - else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) + if answer: termsurl = answer + if not termsurl.startswith(valid_url): + if answer: + logs.out("2", '"http(s)://%s"%s'%(termsurl, langs.site.q), False) + termsurl = '' set_f = 'terms_url = "%s"'%termsurl tyto.set_file(dom.config, False, set_f) @@ -505,7 +511,9 @@ def create_domain(target): ), False) if answer: css = answer.lower() - if not css.isalnum(): logs.out("3", css, True) + if not css.isalnum(): + logs.out("3", css, False) + css = 'tyto' set_f = 'css = "%s"'%css tyto.set_file(dom.config, False, set_f) @@ -521,8 +529,10 @@ def create_domain(target): ), False) if answer: sep = answer - if not len(sep) == 1: logs.out("3", answer, True) - + if not len(sep) == 1: + logs.out("3", answer, False) + sep = "-" + set_f = 'sep = "%s"'%sep tyto.set_file(dom.config, False, set_f) @@ -557,9 +567,11 @@ def create_domain(target): langs.site.q, relme ), False) - if answer: - if answer.startswith(valid_url): relme = answer - else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) + if answer: relme = answer + if not relme.startswith(valid_url): + if answer: + logs.out("2", '"http(s)://%s"%s'%(relme, langs.site.q), False) + relmel = '' set_f = 'relme = "%s"'%relme tyto.set_file(dom.config, False, set_f) @@ -576,7 +588,10 @@ def create_domain(target): ), False) if answer: sdb_title = answer - if '"' in sdb_title: sdb_title = sdb_title.replace('"', '') + if not sdb_title: + sdb_title = '' + invalid = True + elif '"' in sdb_title: sdb_title = sdb_title.replace('"', '') set_f = 'sidebar_title = "%s"'%sdb_title tyto.set_file(dom.config, False, set_f) @@ -585,22 +600,27 @@ def create_domain(target): # Sidebar Items #-------------- try: sdb_items = dom.sidebar_items - except: sdb_items = "6" + except: sdb_items = 6 answer = asking(' ├ [max=16] %s. %s%s {%s} '%( langs.site.sidebar, langs.site.form_sdb_i, langs.site.q, sdb_items ), False) - if answer: - if answer.isdigit() and int(answer) in range(1,17): - sdb_items = int(answer) - else: logs.out("3", answer, True) + if answer: sdb_items = answer + if not str(sdb_items).isdigit() or not int(sdb_items) in range(1,17): + sdb_items = 6 set_f = 'sidebar_items = %d'%int(sdb_items) tyto.set_file(dom.config, False, set_f) + # Domain config invalid, do not activate + if invalid: + tyto.set_file(dom.config, False, '\nactivated = False') + print(langs.site.form_inv) + logs.out("2", dom.config, True) + # Resumed configuration #----------------------- try: active = dom.activated diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 0818534..f4fdcea 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -19,7 +19,7 @@ # XMPP: echolib (im@echolib.re) # # Description: Create HTML page -# File: /var/lib/tyto/program/show.py +# File: /var/lib/tyto/program/html.py #---------------------------------------------------------------------- #------------ @@ -33,7 +33,6 @@ #********************************************************************** import os, sys, importlib - import logs, db, dom, tyto, form, langs # Publish option can be @@ -62,8 +61,7 @@ def create_metas_page(): metas_page = '' scale = 'width=device-width, initial-scale=1.0' all_tags = dom.tags + ',' + db.tags - css_file = 'styles.css' - css_ref = 'href="%stemplate/%s"'%(db.sub_uri, css_file) + css_ref = 'href="%stemplate/%s"'%(db.sub_uri, dom.css) rss_ref = 'type="application/rss+xml" ' + \ 'href="%s%s" title="RSS 2.0. %s %s %s"'%( db.sub_uri, dom.rss, @@ -80,7 +78,7 @@ def create_metas_page(): ) # Create author and date publish section infos - create_html_infos_section('wip') + create_html_time_meta('wip') # Set all raw HTML metas #----------------------- @@ -117,28 +115,34 @@ def create_metas_page(): # Set main page, with all HTML sections # #---------------------------------------# def create_main_page(target, article_bottom): - global main_page - - if not tyto.exists(dom.wip_footer_f): - logs.out("1", dom.wip_footer_f, True) - - if not tyto.exists(dom.wip_metas_f): - logs.out("24", '(HTML metas): %s'%dom.wip_metas_f, False) + global main_page, post_html_code # Create link for website's logo #------------------------------- - logo_html = '\n'%(11 * " ") + \ - '%s\n'%(15 * " ") + \ - '%s'%(8 * " ") - + logo_html = \ + '\n'%(11 * " ") + \ + '%s\n'%(15 * " ") + \ + '%s'%(8 * " ") + + post_html_code = '' + if dom.article_code: + post_html_code = \ + ' ' + \ + ' {%s}\n'%( + langs.site.tyto_psrc, + langs.site.source_code + ) + #-----------------------# # Create main HTML Page # #-----------------------# @@ -156,7 +160,7 @@ def create_main_page(target, article_bottom): '\n' + \ '
\n' + \ ' \n' + \ '

%s

\n'%dom.title + \ '
\n' + \ @@ -167,7 +171,17 @@ def create_main_page(target, article_bottom): '\n' + \ '
\n' + \ '
\n' + \ - '%s\n'%post_pub + \ + '

\n' + \ + ' %s\n'%( + title, langs.site.w_written, db.date, langs.site.by, + db.author, + langs.site.article + ) + \ + '%s'%post_html_code + \ + '%s\n'%time_html_pub + \ + ' %s\n'%db.author + \ + '

\n' + \ '
\n' + \ '%s\n'%article_bottom + \ '
\n' + \ @@ -182,11 +196,12 @@ def create_main_page(target, article_bottom): # Create HTML line for article infos section # # when wip, and publish # #--------------------------------------------# -def create_html_infos_section(process): +def create_html_time_meta(process): # Need to reload the DB to get last time updated exec(open(db.config).read(), globals()) - global post_pub, meta_pub, date_raw + global time_html_pub, meta_pub, date_raw + if process == 'wip': date_raw = date_wip #