diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 5e02a6d..73f7a96 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -5,8 +5,8 @@ # # 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. +# 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 @@ -39,33 +39,7 @@ import time, importlib, sys, os, re, datetime from datetime import datetime from time import gmtime, strftime -import args, dom, logs, status, db, form, tyto - - -# load locale translation -trans_dir = '/var/lib/tyto/translations' -sys.path.insert(0, trans_dir) - - -# Get default system language -# or set "en" (english) if no translation file -try: - lang_site = locale.getdefaultlocale()[0].split('_')[0] - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) -except: - lang_site = 'en' - -lang_sys = lang_site - -# Set language site/form from configuration domain -# or set default english if not known -try: - dom.exists - lang_site = dom.lang_site - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) - tr = importlib.import_module('site_%s'%lang_site, package=None) -except: - tr = importlib.import_module('site_%s'%lang_site, package=None) +import args, dom, logs, status, db, form, tyto, langs post_err = False @@ -76,7 +50,7 @@ post_err = False #-------------------------#-------------------------------------------- def manage(target): dom.valid() - + # target needed if not target: logs.out("5", args.action, True) @@ -86,14 +60,10 @@ def manage(target): and db.exists \ and not db.old_chk: logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False) - ask = '' - try: - ask = input(' ├ %s%s '%(tr.check_a, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - if not ask in form.answer_yes: - return + answer = form.asking(' ├ %s%s '%( + langs.site.check_a, langs.site.q + ), True) + check_process(target) # All @@ -416,7 +386,7 @@ def check_date(date): date_check = time.mktime(time.strptime(date_check, fmt_check)) # Set franch format in post DB - if lang_site == 'fr': + if dom.lang_site == 'fr': date = date.rsplit('-') date = date[2] + '/' + date[1] + '/' + date[0] @@ -486,7 +456,7 @@ def check_3lines(tag, ln, line): if not name: logs.out("2", 'L=%s. "%s: %s" > %s'%( - ln, tag, tr.name, db.uri_file + ln, tag, langs.site.name, db.uri_file ), False) post_err = True diff --git a/src/var/lib/tyto/program/form.py b/src/var/lib/tyto/program/form.py index 501a85f..3e5aad9 100644 --- a/src/var/lib/tyto/program/form.py +++ b/src/var/lib/tyto/program/form.py @@ -1,11 +1,29 @@ #!/usr/bin/env python3 -# Name: Tyto - Littérateur -# Type: Global functions for domain -# Description: Create/edit a domain -# file: domain.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' argument. +# Create domain config from form +# Create config files for user to custom +# File: /var/lib/tyto/program/form.py +#---------------------------------------------------------------------- #------------ # funny stats @@ -20,57 +38,62 @@ from datetime import datetime import os, sys, locale, importlib -# load locale translation +import logs, dom, tyto, html, show, langs + +# locale translation directory trans_dir = '/var/lib/tyto/translations' -sys.path.insert(0, trans_dir) -import logs, dom, tyto, html, show - -# System language -try: lang_sys = locale.getdefaultlocale()[0].split('_')[0] -except: lang_sys = 'en' - -# Get default system language -# or set "en" (english) if no translation file +# Get default System language try: - lang_site = lang_sys - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) + lang_sys = locale.getdefaultlocale()[0].split('_')[0] + os.path.exists('%s/site_%s.py'%(trans_dir, lang_sys)) except: - lang_site = 'en' + lang_sys = 'en' -# Set language site/form from configuration domain -# or set default english if not known -try: - dom.exists - lang_site = dom.lang_site - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) - tr = importlib.import_module('site_%s'%lang_site, package=None) -except: - tr = importlib.import_module('site_%s'%lang_site, package=None) +lang_site = lang_sys +# Generic answer answer_yes = ('y', 'Y', 'yes', 'Yes', 'YES', 'o', 'O', 'oui', 'Oui', 'Oui' ) +#=======================================# +# Function called when asking something # +# Catch interruption # +# if logs.out True: sys exit # +# yes_no False: return answer # +# True: exit if not in yes # +#---------------------------------------# +def asking(question, yes_no): + try: + answer = input(question) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) + + if yes_no: + if not answer in answer_yes: + logs.out("255", '', True) + + else: + return(answer) + + #==========================# # Manage Argument 'domain' # # target: 3rd argument # #--------------------------# -def manage(target): +def manage(target): + if not dom.exists: logs.out("43", '', False) create_domain(target) elif dom.incomplete: create_domain(target) else: - try: - ask = input(' ├ %s%s '%(tr.form_edit, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - if ask in answer_yes: create_domain(target) - else: logs.out("255", '', True) + asking(' ├ %s%s '%(langs.site.form_edit, langs.site.q), True) + create_domain(target) #=====================# @@ -81,121 +104,115 @@ def create_domain(target): logs.out("51", '"%s" -> http(s)://...'%target, False) target = '' - print(tr.form_start) - - + print(langs.site.form_start) + # Get complete URL from target or ask #------------------------------------ + valid_url = ('http://', 'https://') + try: www_url = dom.www_url except: - if target: www_url = target - else: www_url = '' + if target: www_url = target + else: www_url = '' - valid_url = ('http://', 'https://') - ask = '' - try: - ask = input(' ├ [http(s)://...] %s%s {%s} '%( - tr.form_url, tr.q, www_url - ) - ) - except KeyboardInterrupt: - print('') + answer = asking(' ├ [http(s)://...] %s%s {%s} '%( + langs.site.form_url, langs.site.q, www_url + ), False) + + if answer: + if answer.startswith(valid_url): www_url = answer + else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) + elif not www_url: logs.out("255", '', True) - - if ask: - if not ask.startswith(valid_url): - logs.out("2", 'http(s)://%s'%ask, True) - www_url = ask - if not www_url: - logs.out("255", '', True) - - # Remove unused last / if exists - if www_url[-1] == "/": - www_url = www_url[:-1] + if www_url[-1] == "/": www_url = www_url[:-1] + protocol = www_url.rsplit('://')[0] shortname = www_url.rsplit('://')[1] - # Prefix wip - #----------- + # Prefix wip ; guess it if unknown + #--------------------------------- try: wip_url = dom.wip_url - except: + except: # Set domain with www-wip - wip_url = '' - wip_url = shortname.rsplit('.', 2) - if len(wip_url) > 2: - wip_url = '%s://www-wip.%s.%s'%(protocol, wip_url[1], wip_url[2]) - else: - wip_url = '%s://www-wip.%s.%s'%(protocol, wip_url[0], wip_url[1]) + try: + wip_url = shortname.rsplit('.', 2) + if len(wip_url) > 2: + wip_url = '%s://www-wip.%s.%s'%( + protocol, wip_url[1], wip_url[2] + ) + else: + wip_url = '%s://www-wip.%s.%s'%( + protocol, wip_url[0], wip_url[1] + ) + except: + wip_url = '' - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_wip, tr.q, wip_url)) - except KeyboardInterrupt: - print('') + answer = asking(' ├ [http(s)://...] %s%s {%s} '%( + langs.site.form_wip, langs.site.q, wip_url + ), False) + if answer: + if answer.startswith(valid_url): wip_url = answer + else: logs.out("2", '"http(s)://www-wip.%s"%s'%( + answer, langs.site.q + ), True) + elif not wip_url: logs.out("255", '', True) - - if ask: - if not ask.startswith(valid_url): - logs.out("2", '"%s" -> http(s)://...'%ask, True) - wip_url = ask - - # Remove unused last / if exists - if wip_url[-1] == "/": - wip_url = wip_url[:-1] + + if wip_url[-1] == "/": wip_url = wip_url[:-1] # Translations for logs #---------------------- try: lang_logs = dom.lang_logs except: lang_logs = lang_sys + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_trlog, langs.site.q, lang_logs + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_trlog, tr.q, lang_logs)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + if answer: + if len(answer) == 2: lang_logs = answer.lower() + else: logs.out("3", answer, True) - if ask: - if len(ask) == 2: lang_logs = ask.lower() - else: logs.out("3", ask, True) - if not tyto.exists('%s/logs_%s.py'%(trans_dir, lang_logs)): - lang_logs = 'en' + if not tyto.exists('%s/logs_%s.py'%(trans_dir, lang_logs)): + lang_logs = 'en' - # Register variables in domain database + # Start registering variables in domain database + #----------------------------------------------- global navbars_conf local_user = '%s/.local/tyto/%s/'%(dom.home_dir, shortname) modules_dir = '%s/articles/_configs/'%dom.folder footer_about_f = '%sfooter_about.html'%modules_dir - set_f = '# Home Domain\n' + \ - 'directory = "%s/"\n'%dom.folder + \ - 'database = "%s"\n'%dom.config + \ - '\n# Local user configuration\n' + \ - 'lang_sys = "%s"\n'%lang_sys + \ - 'local_user = "%s"\n'%local_user + \ - 'lang_logs = "%s"\n'%lang_logs + \ - 'articles_db_d = "%sarticles/"\n'%local_user + \ - '\n# Working directories\n' + \ - 'articles_d = "%s/articles/"\n'%dom.folder + \ - 'files_d = "%s/articles/files/"\n'%dom.folder + \ - 'images_d = "%s/articles/images/"\n'%dom.folder + \ - 'modules_d = "%s"\n'%modules_dir + \ - '\n# Modules files\n' + \ - 'navbar_f = "%styto.navbar"\n'%modules_dir + \ - 'sidebar_f = "%styto.sidebar"\n'%modules_dir + \ - 'metas_f = "%styto.metas.html"\n'%modules_dir + \ - 'footer_f = "%styto.footer.html"\n'%modules_dir + \ - 'footer_about_f = "%s"\n'%footer_about_f + \ - '\n# Domain\n' + \ - 'shortname = "%s"\n'%shortname + \ - 'www_url = "%s"\n'%www_url + \ - 'wip_url = "%s"\n'%wip_url + set_f = \ + '# Home Domain\n' + \ + 'directory = "%s/"\n'%dom.folder + \ + 'database = "%s"\n'%dom.config + \ + '\n# Local user configuration\n' + \ + 'lang_sys = "%s"\n'%lang_sys + \ + 'local_user = "%s"\n'%local_user + \ + 'lang_logs = "%s"\n'%lang_logs + \ + 'articles_db_d = "%sarticles/"\n'%local_user + \ + '\n# Working directories\n' + \ + 'articles_d = "%s/articles/"\n'%dom.folder + \ + 'files_d = "%s/articles/files/"\n'%dom.folder + \ + 'images_d = "%s/articles/images/"\n'%dom.folder + \ + 'modules_d = "%s"\n'%modules_dir + \ + '\n# Modules files\n' + \ + 'navbar_f = "%styto.navbar"\n'%modules_dir + \ + 'sidebar_f = "%styto.sidebar"\n'%modules_dir + \ + 'metas_f = "%styto.metas.html"\n'%modules_dir + \ + 'footer_f = "%styto.footer.html"\n'%modules_dir + \ + 'footer_about_f = "%s"\n'%footer_about_f + \ + '\n# Domain\n' + \ + 'shortname = "%s"\n'%shortname + \ + 'www_url = "%s"\n'%www_url + \ + 'wip_url = "%s"\n'%wip_url tyto.set_file(dom.config, True, set_f) logs.out("32", dom.config, False) @@ -203,20 +220,22 @@ def create_domain(target): # Get srv root #------------- - try: srv = dom.srv - except: srv = '/var/www' - - ask = '' try: - ask = input(' ├ %s%s {%s} '%(tr.form_srv, tr.q, srv)) - except KeyboardInterrupt: - print('') + srv = dom.srv + except: + if tyto.exists('/var/www') : srv = '/var/www' + else: srv = '' + + 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 ask: - srv = ask - if not tyto.exists(srv): logs.out("1", srv, True) - if srvl[-1] == "/": srv = srv[:-1] + if srvl[-1] == "/": srv = srv[:-1] root_srv_dom = '%s/%s'%(srv, shortname) srv_wip_tpl = "%s/wip/template/"%root_srv_dom @@ -250,15 +269,12 @@ def create_domain(target): #------------------- try: logo = dom.logo except: logo = 'logo.png' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_logo, langs.site.q, logo + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_logo, tr.q, logo)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: logo = ask + 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) @@ -270,15 +286,12 @@ def create_domain(target): #------------------ try: rss = dom.rss except: rss = 'rss.xml' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_rss_f, langs.site.q, rss + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_rss_f, tr.q, rss)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: www_rss = ask + if answer: www_rss = answer set_f = 'www_rss_f = "%s/www/%s"\n'%(root_srv_dom, rss) + \ '\n# Domain user\'s settings\n' + \ @@ -292,21 +305,16 @@ def create_domain(target): #------------------- try: rss_items = dom.rss_items except: rss_items = "100" + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_rss_i, langs.site.q, rss_items + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_rss_i, tr.q, rss_items)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not ask.isdigit() and int(ask) > 1: - logs.out("3", ask, True) - rss_items = ask - rss_items = int(rss_items) - - set_f = 'rss_items = %d'%rss_items + if answer: + if answer.isdigit() and int(answer) > 1: rss_items = answer + else: logs.out("3", answer, True) + + set_f = 'rss_items = %d'%int(rss_items) tyto.set_file(dom.config, False, set_f) @@ -314,16 +322,14 @@ def create_domain(target): #----------------- try: title = dom.title except: title = '' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_title, langs.site.q, title + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_title, tr.q, title)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + if answer: title = answer + elif not title: logs.out("255", '', True) - if ask: title = ask - if not title: logs.out("255", '', True) if '"' in title: title = title.replace('"', '') set_f = 'title = "%s"'%title @@ -335,14 +341,11 @@ def create_domain(target): try: date except: date = datetime.now().year - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_date, tr.q, date)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_date, langs.site.q, date + ), False) - if ask: date = ask + if answer: date = answer set_f = 'date = "%s"'%date tyto.set_file(dom.config, False, set_f) @@ -352,16 +355,14 @@ def create_domain(target): #----------------------- try: about = dom.about except: about = '' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_about, langs.site.q, about + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_about, tr.q, about)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + if answer: about = answer + elif not about: logs.out("255", '', True) - if ask: about = ask - elif not about: logs.out("255", '', True) if '"' in about: about = about.replace('"', '') set_f = 'about = "%s"'%about @@ -370,21 +371,14 @@ def create_domain(target): # Get Lang domain for web pages #------------------------------ - #try: lang_site = dom.lang_site - #except: pass # Already set lang_site - global lang_site - - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_trsite, tr.q, lang_site)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if len(ask) == 2: lang_site = ask.lower() - else: logs.out("3", ask, True) + 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) + if not tyto.exists('%s/site_%s.py'%(trans_dir, lang_site)): lang_site = 'en' @@ -396,18 +390,15 @@ def create_domain(target): #---------------- try: mail = dom.mail except: mail = '' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_mail, langs.site.q, mail + ), False) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_mail, tr.q, mail)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + if answer: mail = answer + elif not mail: logs.out("255", '', True) - if ask: mail = ask - if not mail: - logs.out("255", '', True) - elif not "@" in mail and not "." in mail: + if not re.search('^\w+@\w+.\w+$', mail): logs.out("3", mail, True) set_f = 'mail = "%s"'%mail @@ -418,16 +409,15 @@ def create_domain(target): #---------------- try: tags = dom.tags except: tags = '' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_tags, langs.site.q, tags + ), False) + + if answer: tags = answer + elif not tags: logs.out("255", '', True) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_tags, tr.q, tags)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: tags = ask - if not tags: logs.out("255", '', True) + if '"' in tags: tags = tags.replace('"', '') set_f = 'tags = "%s"'%tags tyto.set_file(dom.config, False, set_f) @@ -437,16 +427,14 @@ def create_domain(target): #------------------- try: domlicense = dom.license except: domlicense = 'CC BY-NC-SA 3.0' + + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_lic, langs.site.q, domlicense + ), False) + + if answer: domlicense = answer + elif not domlicense: logs.out("255", '', True) - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_lic, tr.q, domlicense)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: domlicense = ask - if not domlicense: logs.out("255", '', True) if '"' in domlicense: domlicense = domlicense.replace('"', '') set_f = 'license = "%s"'%domlicense @@ -457,20 +445,15 @@ def create_domain(target): #--------------------------- try: licurl = dom.license_url except: licurl = '' + + answer = asking(' ├ %s [http(s)://...] %s%s {%s} '%( + langs.site.form_opt, langs.site.form_licurl, + langs.site.q, licurl + ), False) - ask = '' - try: - ask = input(' ├ %s [http(s)://...] %s%s {%s} '%( - tr.form_opt, tr.form_licurl, tr.q, licurl - ) - ) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not ask.startswith('http'): logs.out("3", ask, True) - licurl = ask + if answer: + if answer.startswith(valid_url): licurl = answer + else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) set_f = 'license_url = "%s"'%licurl tyto.set_file(dom.config, False, set_f) @@ -481,19 +464,14 @@ def create_domain(target): try: legalurl = dom.legal_url except: legalurl = '' - ask = '' - try: - ask = input(' ├ %s [http(s)://...] %s%s {%s} '%( - tr.form_opt, tr.form_legal, tr.q, legalurl - ) - ) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not ask.startswith('http'): logs.out("3", ask, True) - legalurl = ask + answer = asking(' ├ %s [http(s)://...] %s%s {%s} '%( + langs.site.form_opt, langs.site.form_legal, + 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) set_f = 'legal_url = "%s"'%legalurl tyto.set_file(dom.config, False, set_f) @@ -504,19 +482,14 @@ def create_domain(target): try: termsurl = dom.terms_url except: termsurl = '' - ask = '' - try: - ask = input(' ├ %s [http(s)://...] %s%s {%s} '%( - tr.form_opt, tr.form_terms, tr.q, termsurl - ) - ) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not ask.startswith('http'): logs.out("3", ask, True) - domain_legalurl = ask + answer = asking(' ├ %s [http(s)://...] %s%s {%s} '%( + langs.site.form_opt, langs.site.form_terms, + 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) set_f = 'terms_url = "%s"'%termsurl tyto.set_file(dom.config, False, set_f) @@ -527,17 +500,13 @@ def create_domain(target): try: css = dom_css except: css = 'tyto' - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_css, tr.q, css)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not ask.isalnum(): logs.out("3", ask, True) - css = ask.lower() - + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_css, langs.site.q, css + ), False) + + if answer: css = answer.lower() + if not css.isalnum(): logs.out("3", css, True) + set_f = 'css = "%s"'%css tyto.set_file(dom.config, False, set_f) @@ -547,16 +516,12 @@ def create_domain(target): try: sep = dom.sep except: sep = "-" - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_sep, tr.q, sep)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if not len(ask) == 1: logs.out("3", ask, True) - sep = ask + answer = asking(' ├ %s%s {%s} '%( + langs.site.form_sep, langs.site.q, sep + ), False) + + if answer: sep = answer + if not len(sep) == 1: logs.out("3", answer, True) set_f = 'sep = "%s"'%sep tyto.set_file(dom.config, False, set_f) @@ -569,17 +534,14 @@ def create_domain(target): article_code = "True" except: article_code = "False" - - ask = '' - try: - ask = input(' ├ %s%s {%s} '%(tr.form_pscode, tr.q, article_code)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if ask: - if ask in answer_yes: article_code = "True" - else: article_code = "False" + + answer = (' ├ %s%s {%s} '%( + langs.site.form_pscode, langs.site.q, article_code + ), False) + + if answer: + if answer in answer_yes: article_code = "True" + else: article_code = "False" set_f = 'article_code = %s'%article_code tyto.set_file(dom.config, False, set_f) @@ -590,19 +552,14 @@ def create_domain(target): try: relme = dom.relme except: relme = '' - ask = '' - try: - ask = input(' ├ %s %s%s {%s} '%( - tr.form_opt, tr.form_relme, tr.q, relme - ) - ) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + answer = asking(' ├ %s [http(s)://...] %s%s {%s} '%( + langs.site.form_opt, langs.site.form_relme, + langs.site.q, relme + ), False) - if ask: - if not ask.startswith('http'): logs.out("3", ask, True) - relme = ask + if answer: + if answer.startswith(valid_url): relme = answer + else: logs.out("2", '"http(s)://%s"%s'%(answer, langs.site.q), True) set_f = 'relme = "%s"'%relme tyto.set_file(dom.config, False, set_f) @@ -611,19 +568,14 @@ def create_domain(target): # Sidebar Title #-------------- try: sdb_title = dom.sidebar_title - except: sdb_title = tr.site_sdb_t - - ask = '' - try: - ask = input(' ├ %s. %s%s {%s} '%( - tr.sidebar, tr.title, tr.q, sdb_title - ) - ) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + except: sdb_title = langs.site.site_sdb_t - if ask: sdb_title = ask + answer = asking(' ├ %s. %s%s {%s} '%( + langs.site.sidebar, langs.site.title, + langs.site.q, sdb_title + ), False) + + if answer: sdb_title = answer if '"' in sdb_title: sdb_title = sdb_title.replace('"', '') set_f = 'sidebar_title = "%s"'%sdb_title @@ -634,20 +586,16 @@ def create_domain(target): #-------------- try: sdb_items = dom.sidebar_items except: sdb_items = "6" - - ask = '' - try: - ask = input(' ├ [max=16] %s. %s%s {%s} '%( - tr.sidebar, tr.form_sdb_i, tr.q, sdb_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): sdb_items = int(ask) + + 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) set_f = 'sidebar_items = %d'%int(sdb_items) tyto.set_file(dom.config, False, set_f) @@ -658,29 +606,31 @@ def create_domain(target): try: active = dom.activated except: active = False - print(tr.form_warn) + print(langs.site.form_warn) show.read_lines(dom.config, False) + # Activate and prepare domain ? #------------------------------ - try: - ask = input(' ├ %s%s '%(tr.form_activ, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + answer = asking(' ├ %s%s '%( + langs.site.form_activ, langs.site.q + ), False) - if not ask in answer_yes: + if not answer in answer_yes: tyto.set_file(dom.config, False, '\nactivated = False') logs.out("255", '', True) - + + # Activate Domain #---------------- tyto.set_file(dom.config, False, '\nactivated = True') + # RELoad config #-------------- importlib.reload(dom) - + + # Create folders from configuration file #--------------------------------------- folders = \ @@ -704,44 +654,34 @@ def create_domain(target): # Create in _configs/ modules files #---------------------------------- - create_sidebar('form') - create_navbar('form') create_metas('form') + create_navbar('form') + create_sidebar('form') create_footer('form') create_footer_about('form') - print(tr.form_ready) + print(langs.site.form_ready) - - #========================# + +#=============================================================# +# # +# CREATE MODULES' USER FILE AND CREATE WIP FILES FROM MODULES # +# # +#=============================================================# +#========================# # metas_load source file # #------------------------# def create_metas(option): if not dom.ready: dom.valid() - # Defaut metas valuees when FIRST created - metas_srvs = \ - ' \n' + \ - ' \n' + \ - ' \n' + \ - ' ' - - # Create an empty html file in wip/www server if not exists - if not tyto.exists(dom.wip_metas_f): - tyto.set_file(dom.wip_metas_f, 'new', metas_srvs) - logs.out("32", dom.wip_metas_f, False) - - # Create new default config file, or ask if exists if tyto.exists(dom.metas_f): - ask = '' - try: - ask = input(' ├ %s. %s%s '%(tr.metas, tr.form_reset, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) + answer = asking(' ├ %s. %s%s '%( + langs.site.metas, langs.site.form_reset, + langs.site.q + ), False) - if not ask in answer_yes: + if not answer in answer_yes: if option == "form": return logs.out("255", '', True) @@ -762,13 +702,11 @@ def create_metas(option): '# - Do NOT copy this file to template directory\n' + \ '# - These tags are already set' - try: metas_lang = tr.metas_doc + try: metas_lang = langs.site.metas_doc except: metas_lang = metas_en metas_tags = \ - '%s'%metas_lang%(tyto.Tyto, - dom.metas_f - ) + \ + '%s'%metas_lang%(tyto.Tyto, dom.metas_f) + \ '\n' + \ '# %s)'%(9 * ' ', tr.source_code) + '%stitle="%s"\n'%(9 * ' ', langs.site.tyto_git_t%(tyto.Tyto)) + \ + '%sid="footer_item_link">%s)'%(9 * ' ', langs.site.source_code) tyto_show = \ '%s%s %s'%(9 * ' ', tyto.Tyto, Tytosrc) # Show copyright date from creation to now year @@ -964,7 +898,7 @@ def create_footer(option): # Simple link to home domain_home = \ '\n%s%s'%(9 * ' ', dom.title) # Insert content of footer_about_f or default if not exists @@ -988,14 +922,14 @@ def create_footer(option): if dom.legal_url: legal_link = \ '%s'%(11 * ' ', tr.legal_t) + '%stitle="%s - %s"\n'%(11 * ' ', langs.site.legal_t, dom.title) + \ + '%sclass="footer_item_link">%s'%(11 * ' ', langs.site.legal_t) if dom.terms_url: terms_link = \ '%s'%(11 * ' ', tr.terms_s) + '%stitle="%s - %s"\n'%(11 * ' ', langs.site.terms_t, dom.title) + \ + '%sclass="footer_item_link">%s'%(11 * ' ', langs.site.terms_s) # create laws links from terms and legal if exists footer_laws = '' @@ -1009,7 +943,9 @@ def create_footer(option): footer_laws_links = '' if footer_laws: footer_laws_links = \ - ' \n' @@ -1034,7 +970,7 @@ def create_footer(option): '# - Do NOT copy to template directory' '# %s\n'%(20 * "-") - try: footer_lang = tr.footer_doc + try: footer_lang = langs.site.footer_doc except: footer_lang = footer_en # Final HTML footer code @@ -1044,9 +980,9 @@ def create_footer(option): ' \n' + \ @@ -1054,17 +990,23 @@ def create_footer(option): ' \n' + \ ' \n' + \ '' - # Create an empty html file in wip/www server if not exists - if not tyto.exists(dom.wip_footer_f): - tyto.set_file(dom.wip_footer_f, 'new', '') - logs.out("32", dom.wip_footer_f, False) - # Create new default file, or ask if exists - ask = '' if tyto.exists(dom.footer_f): - try: - ask = input(' ├ %s. %s%s '%(tr.footer, tr.form_reset, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if not ask in answer_yes: + answer = asking(' ├ %s. %s%s '%( + langs.site.footer, langs.site.form_reset, + langs.site.q + ), False) + + if not answer in answer_yes: if option == "form": return logs.out("255", '', True) tyto.set_file(dom.footer_f, 'new', footer) logs.out("32", dom.footer_f, False) - + + # Create footer file in wip server if not exists + if not tyto.exists(dom.wip_footer_f): + html.create_user_footer('wip') + + # Generic HTML list in footer """ ' \n' - if not sidebar_new: - # Empty file - if not sidebar_has: - logs.out('29', '(sidebar): %s'%db.sidebar_load, False) + # Nothing to do + if not sidebar_items: + if not tyto.exists(target): + tyto.set_file(target, 'New', '') + logs.out("32", target, False) return - else: # Some items, but no one is valid - logs.out('28', '(sidebar)', False) - return - - # Create HTML complete sidebar - sidebar_temp = sidebar_html%(sidebar_title, sidebar_list) - - # Indent HTML code - sidebar_content = '' - for line in sidebar_temp.rsplit('\n'): - sidebar_content = sidebar_content + '%s%s\n'%(4 * ' ', line) - - # Create file if sidebar has content - if sidebar_new: - ask_html = ' ├ Replace %s ? '%target - res = '' - - if not option == 'pub' and tyto.exists(target): - res = input(ask_html) - if not res in ['y', 'Y']: - logs.out("255", '', True) - - tyto.set_file(target, True, sidebar_content) - logs.out("33", target, False) - - -#==================================# -# Create HTML navbar from config # -# If no index in src: STOP # -# For wip, create if no index.html # -# for publish all/navbar, STOP # -#----------------------------------# -def create_navbar(option): - domain.domain_needed() - - # more confitions to pass - try: - db.navbar_load - if not tyto.exists(db.navbar_load): - logs.out("1", db.navbar_load, True) - except: - logs.out("1", 'Navbar load file', True) - - # Set target from option - pub_opts = ('www', 'pub') - if option == 'wip': target = db.wip_navbar - elif option == 'www': target = db.www_navbar - elif option == 'pub': target = db.www_navbar - - # If content and error - navbar_new = False - navbar_has = False - e_src_index = False - e_www_index = False # If error, do not create file in www server - - # Set first HTML line - menu_html = '%s\n'%(menu_html, 8 * ' ', 6 * ' ') - tyto.set_file(target, 'New', menu_html) - logs.out("33", target, False) - - -#========================================================# -# Create metas.html from _configs/tyto.metas.html # -# Manage options Edit, New, Force, Create # -# Create DB file with hash from _configs/tyto.metas.html # -# To manage new creation if changes # -#--------------------------------------------------------# -def create_user_metas(option): - dom.valid() - - if option == 'wip': target = dom.wip_metas_f - elif option == 'www': target = dom.www_metas_f - elif option == 'pub': target = dom.www_metas_f - - # Create wip metas.html file according to option - #----------------------------------------------- - ask_html = ' ├ Replace %s ? '%target - user_metas = '' - metas_used = (' +# +# 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: Load translations file for log +# File: /var/lib/tyto/program/log.py +#---------------------------------------------------------------------- + +#------------ +# funny stats +#------------ +# lines: +# functions: +# comments: +#---------------------------------------------------------------------- + +#********************************************************************** + +import locale, sys, os, importlib +import dom + +# Import translation directory +trans_dir = '/var/lib/tyto/translations' +sys.path.insert(0, trans_dir) + + +# Get default system language +# or set "en" (english) if no translation file +try: + lang_sys = locale.getdefaultlocale()[0].split('_')[0] + os.path.exists('%s/logs_%s.py'%(trans_dir, lang_sys)) +except: + lang_sys = 'en' + + +# Set language logs from configuration domain +# or set default english if not known +try: + dom.exists + lang_logs = dom.lang_logs + os.path.exists('%s/logs_%s.py'%(trans_dir, lang_logs)) + log = importlib.import_module('logs_%s'%lang_logse, package=None) +except: + log = importlib.import_module('logs_%s'%lang_sys, package=None) +''' + exec(open('%s/logs_%s.py'%(trans_dir, lang.logs)).read()) +except: + exec(open('%s/logs_%s.py'%(trans_dir, lang_sys)).read()) +''' + +# Set language site/form from configuration domain +# or set default english if not known +try: + dom.exists + lang_site = dom.lang_site + os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) + site = importlib.import_module('site_%s'%lang_site, package=None) +except: + site = importlib.import_module('site_%s'%lang_sys, package=None) diff --git a/src/var/lib/tyto/program/logs.py b/src/var/lib/tyto/program/logs.py index d4eaff5..35d28f3 100644 --- a/src/var/lib/tyto/program/logs.py +++ b/src/var/lib/tyto/program/logs.py @@ -18,7 +18,7 @@ #********************************************************************** import os, sys -import lang +import langs # Set colors CS = '\033[0;0m' @@ -31,50 +31,49 @@ CG = '\033[1;32m' #--------------------------------# def out(nbr, value, out): logs = { - '1' : ' ╞ %s%s%s > %s'%(CR, lang.unused_r, CS, value), - '2' : ' ╞ %s%s%s > %s'%(CR, lang.data_inc, CS, value), - '3' : ' ╞ %s%s%s %s'%(CR, lang.data_inv, CS, value), + '1' : ' ╞ %s%s%s > %s'%(CR, langs.log.unused_r, CS, value), + '2' : ' ╞ %s%s%s > %s'%(CR, langs.log.data_inc, CS, value), + '3' : ' ╞ %s%s%s %s'%(CR, langs.log.data_inv, CS, value), '4' : ' ╘ %sUnable to create file%s: %s'%(CR, CS, value), - '5' : ' ╘ %s%s%s > "%s"'%(CR, lang.no_arg, CS, value), - '6' : ' ╞ %s%s%s > %s'%(CR, lang.sep_inv, CS, value), - '7' : ' ╘ %s%s%s > %s'%(CR, lang.post_inv, CS, value), - '8' : ' ╞ %s%s%s %s'%(CR, lang.mark_np, CS, value), + '5' : ' ╘ %s%s%s > "%s"'%(CR, langs.log.no_arg, CS, value), + '6' : ' ╞ %s%s%s > %s'%(CR, langs.log.sep_inv, CS, value), + '7' : ' ╘ %s%s%s > %s'%(CR, langs.log.post_inv, CS, value), + '8' : ' ╞ %s%s%s %s'%(CR, langs.log.mark_np, CS, value), '9' : ' ╞ Article %shas changed%s. Check it first'%(CR, CS), - '10' : ' ╘ %s%s%s'%(CR, lang.dom_no, CS), - '11' : ' ╘ %s%s%s > %s'%(CR, lang.err_arg, CS, value), - '12' : ' ╞ %s%s%s > %s'%(CR, lang.post_inc, CS, value), - '13' : ' ╞ %s%s%s'%(CR, lang.no_fidi, CS), + '10' : ' ╘ %s%s%s'%(CR, langs.log.dom_no, CS), + '11' : ' ╘ %s%s%s > %s'%(CR, langs.log.err_arg, CS, value), + '12' : ' ╞ %s%s%s > %s'%(CR, langs.log.post_inc, CS, value), + '13' : ' ╞ %s%s%s'%(CR, langs.log.no_fidi, CS), '14' : ' ╞ %sMismatch%s program start'%(CR, CS), - '15' : ' ╞ %s%s%s %s'%(CR, lang.anch_nu, CS, value), - '16' : ' ╞ %s%s%s "%s = ?"'%(CR, lang.unused_c, CS, value), - '17' : ' ╞ %s%s%s "%s ?"'%(CR, lang.unused_v, CS, value), - '18' : ' ╘ %s%s%s > %s'%(CR, lang.unused_p, CS, value), + '15' : ' ╞ %s%s%s %s'%(CR, langs.log.anch_nu, CS, value), + '16' : ' ╞ %s%s%s "%s = ?"'%(CR, langs.log.unused_c, CS, value), + '17' : ' ╞ %s%s%s "%s ?"'%(CR, langs.log.unused_v, CS, value), + '18' : ' ╘ %s%s%s > %s'%(CR, langs.log.unused_p, CS, value), '19' : ' ╞ Article %swip%s on: %s'%(CG, CS, value), - '20' : ' ╞ %s%s%s %s'%(CG, lang.check_on, CS, value), - '21' : ' ╘ %s%s%s > %s'%(CG, lang.post_val, CS, value), - '22' : ' ╞ %s%s%s %s'%(CY, lang.symb_np, CS, value), - '23' : ' ╞ %s%s%s > %s'%(CY, lang.db_inv, CS, value), - '24' : ' ╞ %s%s%s > %s'%(CY, lang.unused_r, CS, value), - '25' : ' ╞ Article %snot yet checked%s: %s'%(CY, CS, value), - '26' : ' ╞ %sNo index%s article %s'%(CY, CS, value), - '27' : ' ╞ %s%s%s %s'%(CY, lang.snpic_d, CS, value), - '28' : ' ╘ %s (%s)'%(lang.ntd, value), + '20' : ' ╞ %s%s%s %s'%(CG, langs.log.check_on, CS, value), + '21' : ' ╘ %s%s%s > %s'%(CG, langs.log.post_val, CS, value), + '22' : ' ╞ %s%s%s %s'%(CY, langs.log.symb_np, CS, value), + '23' : ' ╞ %s%s%s > %s'%(CY, langs.log.db_inv, CS, value), + '24' : ' ╞ %s%s%s > %s'%(CY, langs.log.unused_r, CS, value), + '25' : ' ╞ %s%s%s > %s'%(CY, langs.log.nycheck, CS, value), + '26' : ' ╞ %s%s%s %s'%(CY, langs.log.nyfile, CS, value), + '27' : ' ╞ %s%s%s %s'%(CY, langs.log.snpic_d, CS, value), + '28' : ' ╘ %s (%s)'%(langs.log.ntd, value), '29' : ' ╞ %sEmpty configuration%s %s'%(CY, CS, value), - '30' : ' ╞ Article %snot yet wip%s: %s'%(CY, CS, value), - '31' : ' ╞ Not included. %sMax items reached%s %s'%(CY, CS, value), - '32' : ' ╞══ %s%s%s > %s'%(CG, lang.file_c, CS, value), - '33' : ' ╞══ %s%s%s > %s'%(CG, lang.dir_c, CS, value), - '34' : ' ╞══ %s%s%s > %s'%(CG, lang.file_n, CS, value), - '35' : ' ╞ %sAdd item%s %s'%(CG, CS, value), - '36' : ' ╡ %s %s'%(lang.file_e, value), - '37' : ' ╡ %s %s'%(lang.dir_e, value), - '40' : ' ╒ %s%s%s > "%s"'%(CY, lang.dom_ina, CS, value), - '41' : ' ╒ %s%s%s > "%s"'%(CR, lang.dom_inc, CS, value), - '42' : ' ╒ %s%s%s > "%s"'%(CG, lang.dom_act, CS, value), - '43' : ' ╒ %s%s%s'%(CY, lang.dom_no, CS), - '44' : ' ╞ %s%s%s "tyto check %s"'%(CY, lang.check_m, CS, value), - '51' : ' ╞ %s%s%s > %s'%(CY, lang.data_inc, CS, value), - '255' : ' ╘ %s'%lang.laterout + '30' : ' ╞ %s%s%s > %s'%(CY, langs.log.nywip, CS, value), + '32' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_c, CS, value), + '33' : ' ╞══ %s%s%s > %s'%(CG, langs.log.dir_c, CS, value), + '34' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_n, CS, value), + '35' : ' ╞═ %s%s%s %s'%(CG, langs.log.add, CS, value), + '36' : ' ╡ %s %s'%(langs.log.file_e, value), + '37' : ' ╡ %s %s'%(langs.log.dir_e, value), + '40' : ' ╒ %s%s%s > "%s"'%(CY, langs.log.dom_ina, CS, value), + '41' : ' ╒ %s%s%s > "%s"'%(CR, langs.log.dom_inc, CS, value), + '42' : ' ╒ %s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value), + '43' : ' ╒ %s%s%s'%(CY, langs.log.dom_no, CS), + '44' : ' ╞ %s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value), + '51' : ' ╞ %s%s%s > %s'%(CY, langs.log.data_inc, CS, value), + '255' : ' ╘ %s'%langs.log.laterout } msg = logs[nbr] diff --git a/src/var/lib/tyto/program/show.py b/src/var/lib/tyto/program/show.py index b8febea..0625183 100644 --- a/src/var/lib/tyto/program/show.py +++ b/src/var/lib/tyto/program/show.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # Tyto - Littérateur # -# Copyright (C) 2023 Cyrille Louarn +# 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 @@ -34,35 +34,8 @@ #********************************************************************** -import os, sys, locale, importlib -import args, lang, logs, dom, db, form, tyto, check, stats - -# load locale translation -trans_dir = '/var/lib/tyto/translations' -sys.path.insert(0, trans_dir) - -# System language -try: lang_sys = locale.getdefaultlocale()[0].split('_')[0] -except: lang_sys = 'en' - -# Get default system language -# or set "en" (english) if no translation file -try: - lang_site = lang_sys - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) -except: - lang_site = 'en' - -# Set language site/form from configuration domain -# or set default english if not known -try: - dom.exists - lang_site = dom.lang_site - os.path.exists('%s/site_%s.py'%(trans_dir, lang_site)) - tr = importlib.import_module('site_%s'%lang_site, package=None) -except: - tr = importlib.import_module('site_%s'%lang_site, package=None) - +import os, sys, importlib +import args, logs, dom, db, form, tyto, check, stats, langs #========================# # Read lines from a file # @@ -94,10 +67,8 @@ def read_lines(f, alone): #======================# # From command line: # -# - 'showdb' / 'show' # -# - 'editdb' / 'edit' # -# Show or edit files # -# final html, db, load # +# Show or edit file # +# final html, db, src # #----------------------# def manage(target): if not dom.exists: logs.out("10", '', True) @@ -127,10 +98,6 @@ def manage(target): if args.action == "show-about": target = 'post' - # When edit article, get src hash - if args.action == "edit": - curr_hash = tyto.get_filesum(db.uri_file, True) - # Convert command action to do[] # as edit* &nd show* [action] have same target file @@ -153,71 +120,71 @@ def manage(target): # Set target file from "new" [action] do = \ { - 'src' : { - 'domain' : dom.config, - 'footer' : dom.footer_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_src - }, - 'db' : { - 'domain' : dom.config, - 'footer' : dom.footer_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_db - }, - 'about' : { - 'domain' : dom.config, - 'footer' : dom.footer_about_f, - 'metas' : dom.metas_f, - 'navbar' : dom.navbar_f, - 'sidebar' : dom.sidebar_f, - 'post' : post_db - }, - 'wip' : { - 'domain' : dom.config, - 'footer' : dom.wip_footer_f, - 'metas' : dom.wip_metas_f, - 'navbar' : dom.wip_navbar_f, - 'sidebar' : dom.wip_sidebar_f, - 'post' : post_wip - }, - 'www' : { - 'domain' : dom.config, - 'footer' : dom.www_footer_f, - 'metas' : dom.www_metas_f, - 'navbar' : dom.www_navbar_f, - 'sidebar' : dom.www_sidebar_f, - 'post' : post_www - }, + 'src' : { + 'domain' : dom.config, + 'footer' : dom.footer_f, + 'metas' : dom.metas_f, + 'navbar' : dom.navbar_f, + 'sidebar' : dom.sidebar_f, + 'post' : post_src + }, + 'db' : { + 'domain' : dom.config, + 'footer' : dom.footer_f, + 'metas' : dom.metas_f, + 'navbar' : dom.navbar_f, + 'sidebar' : dom.sidebar_f, + 'post' : post_db + }, + 'about' : { + 'domain' : dom.config, + 'footer' : dom.footer_about_f, + 'metas' : dom.metas_f, + 'navbar' : dom.navbar_f, + 'sidebar' : dom.sidebar_f, + 'post' : post_db + }, + 'wip' : { + 'domain' : dom.config, + 'footer' : dom.wip_footer_f, + 'metas' : dom.wip_metas_f, + 'navbar' : dom.wip_navbar_f, + 'sidebar' : dom.wip_sidebar_f, + 'post' : post_wip + }, + 'www' : { + 'domain' : dom.config, + 'footer' : dom.www_footer_f, + 'metas' : dom.www_metas_f, + 'navbar' : dom.www_navbar_f, + 'sidebar' : dom.www_sidebar_f, + 'post' : post_www + }, } # Read or edit file, according to legacy args.action try: file = do[action][target] + if args.action in actions_read: read_lines(file, True) + elif args.action in actions_edit: + curr_hash = tyto.get_filesum(file, True) tyto.edit_file(file) + except: logs.out("28", '%s + %s'%(action, target), True) # If edit article and hash changed, ask to check if args.action == "edit" and post_src: - new_hash = tyto.get_filesum(post_src, True) + new_hash = tyto.get_filesum(file, True) if curr_hash != new_hash: - ask = '' - try: ask = input(' ├ %s%s '%(tr.post_chg, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if not ask in form.answer_yes: - logs.out("255", '', True) + if file == post_src: + form.asking(' ├ %s%s '%( + langs.site.post_chg, langs.site.q + ), True) # Reload post DB (if edited article, and check it if ask "y") importlib.reload(db) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index c3b01f2..40fee31 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -516,7 +516,8 @@ def files_to_srv(server): d_in = uri.split("/")[-1] d_in = uri.rsplit(d_in)[0] - # Destination file to server + # Destination file and directories according to server + # (remove last / from domain directory value) f_src = '%s%s'%(dom.articles_d[:-1], uri) if server == 'wip': f_dst = '%s%s'%(dom.srv_wip[:-1], uri) @@ -525,19 +526,22 @@ def files_to_srv(server): f_dst = '%s%s'%(dom.srv_www[:-1], uri) d_dst = '%s%s'%(dom.srv_www[:-1], d_in) - # Create folder and subfolders + # Create sub-directories in server try: os.makedirs(d_dst, exist_ok=True) logs.out("33", d_dst, False) except: logs.out('4', d_dst, True) + # COpy files to server try: shutil.copy2(f_src, f_dst) logs.out("32", f_dst, False) except: logs.out('4', f_dst, True) + # Copy source post file in server + # if article_code is True in domain DB if dom.article_code: if server == "wip": base_srv = dom.srv_wip elif server == "www": base_srv = dom.srv_www diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 6d84b9a..1fa25b6 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 # Tyto - Littérateur # -# Copyright (C) 2023 Cyrille Louarn +# Copyright (C) 2023 Cyrille Louarn # Copyright (C) 2023 Adrien Bourmault # # 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. +# 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 @@ -39,7 +39,7 @@ import os, re, sys, locale, shutil, importlib, time from pathlib import Path -import args, logs, lang, dom, db, tyto, html, form, stats +import args, logs, dom, db, tyto, html, form, stats # load locale translation trans_dir = '/var/lib/tyto/translations' @@ -112,15 +112,7 @@ def manage_wip(target): # wip is up-to-date: ask to wip again else: logs.out("19", db.date_wip, False) - try: - res = input(' ├ [%s] %s%s '%(db.title, tr.wip_new, tr.q)) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if not res in form.answer_yes: - logs.out("255", '', True) - + form.asking(' ├ [%s] %s%s '%(db.title, tr.wip_new, tr.q), True) wip_article(db.uri_file) @@ -308,34 +300,55 @@ def wip_words_tags(): ) -#=======================# -# Convert links from DB # -# - link_%i # -# - file_%i # -#-----------------------# -def wip_links(): +#========================# +# Convert links set inDB # +# - file_%i # +# - link_%i # +# from marker to HTML # +#------------------------# +def wip_link_convert(marker, html): global post_bottom + post_bottom = post_bottom.replace(marker, html) - # Doing files, first, becase of similar marker - if db.uniq_files > 0: +def wip_links(): + if db.uniq_files == 0 and db.uniq_links == 0: return + + link_tb = 'target="_blank"' + link_ts = 'target="_self"' + link_html = '%s' + + # ! Doing link files, first, becase of similar marker + #---------------------------------------------------- + if db.uniq_files > 0: for i in range(1, db.uniq_files + 1): - file = 'db.file_%s'%i - post_bottom = post_bottom.replace(eval(file)[0]+'+', - eval(file)[1]%('_blank') - ) - post_bottom = post_bottom.replace(eval(file)[0], - eval(file)[1]%('_self') - ) + link = 'db.file_%s'%i + link_css = "link_file" + link_name = eval(link)[0][2:] + link_anc = eval(link)[1] + link_title = eval(link)[2] + link_set = link_html%( + link_css, link_anc, link_title, "%s", link_name + ) + + wip_link_convert(eval(link)[0]+'+', link_set%link_tb) + wip_link_convert(eval(link)[0], link_set%link_ts) + - if db.uniq_links > 0: + # Convert simple links + #--------------------- + if db.uniq_links > 0: for i in range(1, db.uniq_links + 1): - link = 'db.link_%s'%i - post_bottom = post_bottom.replace(eval(link)[0]+'+', - eval(link)[1]%('_blank') - ) - post_bottom = post_bottom.replace(eval(link)[0], - eval(link)[1]%('_self') - ) + link = 'db.link_%s'%i + link_css = "link" + link_name = eval(link)[0][1:] + link_anc = eval(link)[1] + link_title = eval(link)[2] + link_set = link_html%( + link_css, link_anc, link_title, "%s", link_name + ) + + wip_link_convert(eval(link)[0]+'+', link_set%link_tb) + wip_link_convert(eval(link)[0], link_set%link_ts) #===============# @@ -370,8 +383,8 @@ def wip_images(): if db.uniq_images == 0: return global post_bottom - image_link = '%s' - image_show = '%s' + image_link = '%s' + image_show = '%s' # Check each line for ln, line in enumerate(post_bottom.rsplit('\n')): @@ -419,13 +432,15 @@ def wip_images(): 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_css, image_target, + eval(image)[2], eval(image)[2], + style ) # Set link for image if target: image_tgt = image_link%( - set_css, image_target, eval(image)[2], '%s' + set_css, image_target, '%s' ) else: image_tgt = '%s' diff --git a/src/var/lib/tyto/translations/logs_en.py b/src/var/lib/tyto/translations/logs_en.py index baafdf8..7fad89a 100644 --- a/src/var/lib/tyto/translations/logs_en.py +++ b/src/var/lib/tyto/translations/logs_en.py @@ -11,6 +11,10 @@ #********************************************************************** # Generic +sidebar = 'Sidebar' +navbar = 'Navbar' +metas = 'Metas Tags' +footer = 'Footer' line = "Ligne" ntd = "Nothing to do" @@ -44,5 +48,9 @@ mark_np = "Not paired marks" symb_np = "Not paired symbols" snpic_d = "Using default snpic. Not found" anch_nu = "Anchor not uniq" +nyfile = "file not yet created" +nycheck = "Article not yet checked" +nywip = "Article not yet wip" +add = "Add:" laterout = "Maybe later..." diff --git a/src/var/lib/tyto/translations/logs_fr.py b/src/var/lib/tyto/translations/logs_fr.py index 3823509..899cb8a 100644 --- a/src/var/lib/tyto/translations/logs_fr.py +++ b/src/var/lib/tyto/translations/logs_fr.py @@ -11,7 +11,12 @@ #********************************************************************** # Generique -linecol = "Line" +sidebar = 'Barre Latérale' +navbar = 'Barre de navigation' +metas = 'Balises Metas' +footer = "Pied de Page" + +line = "Line" ntd = "Rien à faire" unused_r = "Ressource manquante" @@ -44,5 +49,10 @@ mark_np = "Marqueurs non jumelés" symb_np = "Symboles non jumelés" snpic_d = "snpic utilisé par défaut. Manquant" anch_nu = "Ancre non unique" +nyfile = "Fichier pas encore créé" +nycheck = "Article pas encore 'check'" +nywip = "Article pas encore 'wip'" +add = "Ajout:" + laterout = "Pour plus tard..." diff --git a/src/var/lib/tyto/translations/site_en.py b/src/var/lib/tyto/translations/site_en.py index 163bb06..8948ad4 100644 --- a/src/var/lib/tyto/translations/site_en.py +++ b/src/var/lib/tyto/translations/site_en.py @@ -23,7 +23,7 @@ This is a python file, so... DO NOT REMOVE: # Generic sidebar = 'Sidebar' navbar = 'Navbar' -metas = 'HTML Metas Tags' +metas = 'Metas Tags' footer = 'Footer' title = 'Title' File = 'File' @@ -178,7 +178,7 @@ sidebar_doc = \ '# Order in sidebar position\n' + \ '# Max articles = %d\n' + \ '# Option Tp set sidebar title:\n' + \ -' ": Sidebar Title"\n' + \ +'# ": Sidebar Title"\n' + \ '\n# %s\n'%(20 * "-") + \ '# Examples :\n' + \ '# : My new articles list' diff --git a/src/var/lib/tyto/translations/site_fr.py b/src/var/lib/tyto/translations/site_fr.py index 72051a6..449a9d6 100644 --- a/src/var/lib/tyto/translations/site_fr.py +++ b/src/var/lib/tyto/translations/site_fr.py @@ -23,7 +23,7 @@ Ceci est un fichier python, donc... NE PAS ENLEVER : # Generic sidebar = 'Barre Latérale' navbar = 'Barre de navigation' -metas = 'Balises Metas HTML' +metas = 'Balises Metas' footer = "Pied de Page" title = 'Titre' File = 'Fichier' @@ -179,7 +179,7 @@ sidebar_doc = \ '# L\'ordre définit la position\n' + \ '# Articles max = %d\n' + \ '# Option Pour définir un titre à la barre latérale:\n' + \ -' ": Titre de la sidebar"\n' + \ +'# ": Titre de la sidebar"\n' + \ '\n# %s\n'%(20 * "-") + \ '# Exemples :\n' + \ '# : Ma liste des nouveaux articles\n' + \