diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index ce6e6e5..46ed4a8 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.2 -# Updated: 2023-09-23 1695486804 +# Version: 1.9.4 +# Updated: 2023-09-25 1695630197 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc index d3e4f59..3515f88 100644 Binary files a/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc index 561c139..159ce74 100644 Binary files a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc index c5c7a11..438da5e 100644 Binary files a/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc index 5192df5..d8bafe2 100644 Binary files a/src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc index d838498..00b7f8a 100644 Binary files a/src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc index 5f5fcc3..6edf5f4 100644 Binary files a/src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc index 54ddb3e..853beec 100644 Binary files a/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc index a72c071..ae86333 100644 Binary files a/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc index 61482d9..c09b1ea 100644 Binary files a/src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py index 35801aa..f6cc65c 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -94,6 +94,8 @@ def start_process(): "check" : check.manage, "new" : new.manage, "set" : userset.manage, + "start" : userset.manage, + "stop" : userset.manage, "show" : show.manage, } diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index f0ab8dc..56045bf 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -36,10 +36,15 @@ import sys import domain, langs, debug +#===========================================# +# Manage argument from command line "check" # +# Domain must be valid to proceed # +# Create user work domain directories # +#-------------------------------------------# def manage(action, target): # Load domain configuration, update if needed, check if valid - if not domain.valid_conf(): - debug.out(105, domain.conf_name, domain.dcf_uri, True, 1, True) - + if not domain.cf_valid(): + debug.out(105, domain.name, domain.cf_uri, True, 1, True) + langs.load_website_lang() print("check:", action, target) diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 4b44b64..a48a7a6 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -40,38 +40,37 @@ import debug, tyto, tools, forms, langs # Exit if directory name is compatible with a domain name # #---------------------------------------------------------# def compatible_name(): - if len(conf_name.rsplit(".")) <= 1: - debug.out(3, "abc.tld", conf_name, True, 2, True) + if len(name.rsplit(".")) <= 1: + debug.out(3, "abc.tld", name, True, 2, True) #================================# # Load Domain Configuration file # # As needed, exit if not exists # #--------------------------------# -def dcf_load(): - global dcf +def cf_load(): + global cf - dcf = False - if not dcf_exists(): - debug.out(100, conf_name, dcf_uri, True, 1, True) - - dcf = configparser.ConfigParser() - dcf.read(dcf_uri) + cf_exists() or sys.exit(100) + + cf = False + cf = configparser.ConfigParser() + cf.read(cf_uri) #=====================================# # Load User Domain Configuration file # # As needed, exit if not exists # #-------------------------------------# -def ult_dcf_load(): - global ult_dcf +def ult_cf_load(): + global ult_cf - ult_dcf = False - if not os.path.exists(ult_dcf_uri): - debug.out(100, conf_name, ult_dcf_uri, True, 1, True) + ult_cf = False + if not os.path.exists(ult_cf_uri): + debug.out(100, name, ult_cf_uri, True, 1, True) - ult_dcf = configparser.ConfigParser() - ult_dcf.read(ult_dcf_uri) + ult_cf = configparser.ConfigParser() + ult_cf.read(ult_cf_uri) #===================================# @@ -90,36 +89,36 @@ def ult_dlf_load(): # Show status message only once # # return True or False #-------------------------------------------# -def dcf_exists(): +def cf_exists(): global shown_ok, shown_no - if os.path.exists(dcf_uri): + if os.path.exists(cf_uri): try: shown_ok - except: debug.out(202, conf_name, dcf_uri, True, 0, False) + except: debug.out(202, name, cf_uri, False, 0, False) shown_ok = True return True else: try: shown_no - except: debug.out(104, "False", dcf_uri, True, 1, False) + except: debug.out(104, "False", cf_uri, True, 1, False) shown_no = True compatible_name() return False #=========================================# -# Guess and return wip_url from conf_name # +# Guess and return wip_url from name # #-----------------------------------------# def create_wip_url(): wip_url = "https://www-wip.%s/" - len_cn = conf_name.count(".") + len_cn = name.count(".") # Domain name Format: a.b if len_cn == 1: - return wip_url%conf_name + return wip_url%name # Domain name format: (at least) a.b.c - len_cn = len(conf_name.rsplit(".")[0]) + 1 - tld = conf_name[len_cn:] + len_cn = len(name.rsplit(".")[0]) + 1 + tld = name[len_cn:] return wip_url%tld @@ -130,21 +129,21 @@ def create_wip_url(): # - default User domain configuration file # # If not User domains list file, create it # #------------------------------------------# -def dcf_create(): +def cf_create(): compatible_name() # This fonction is only called with "new domain" argument # If a conf already exists, show important RESET log - if dcf_exists(): - debug.out(102, "!?", dcf_uri, True, 1, False) + if cf_exists(): + debug.out(102, "!?", cf_uri, True, 1, False) # Ask User to create new domain. Will exit if not ok. - forms.ask_domain_shortname(conf_name) + forms.ask_domain_shortname(name) # Create default files - tools.create_file(dcf_uri, tyto.ini_domain) + tools.create_file(cf_uri, tyto.ini_domain) tools.create_dirs(ult_dir) - tools.create_file(ult_dcf_uri, tyto.ini_domain_user) + tools.create_file(ult_cf_uri, tyto.ini_domain_user) # User Domains list file if not os.path.exists(ult_dlf_uri): @@ -167,47 +166,49 @@ def dcf_create(): #===========================================# # Set or Update domain configuration values # #-------------------------------------------# -def dcf_update_values(srv): +def cf_update_values(srv): # Prepare Domain Configuration File keys values #----------------------------------------------- - dcf_load() + cf_load() # Test server directory, and exit if not exists - srv = srv or dcf.get("SERVER", "root") # Set from db if unknown + srv = srv or cf.get("SERVER", "root") # Set from db if unknown # Test registred website lang # change to default lang sys, or "en" if no translation file # Load website lang file langs.load_website_lang() + cf.set("WEBSITE", "lang", langs.site_lang) - srv_dom = os.path.join(srv, conf_name + "/") + srv_dom = os.path.join(srv, name + "/") srv_wip = os.path.join(srv_dom, "wip/") srv_www = os.path.join(srv_dom, "www/") # Set booleans if invalid values - try: dcf.getboolean("DOMAIN", "activated") - except: dcf.set("DOMAIN", "activated", "no") - try: dcf.getboolean("WEBSITE", "article_code") - except: dcf.set("WEBSITE", "article_code", "yes") - try: dcf.getboolean("WEBSITE", "static") - except: dcf.set("WEBSITE", "static", "no") - try: dcf.getboolean("WEBSITE_MODULES", "sitemaps") - except: dcf.set("WEBSITE_MODULES", "sitemaps", "yes") + try: cf.getboolean("DOMAIN", "activated") + except: cf.set("DOMAIN", "activated", "no") + try: cf.getboolean("WEBSITE", "article_code") + except: cf.set("WEBSITE", "article_code", "yes") + try: cf.getboolean("WEBSITE", "static") + except: cf.set("WEBSITE", "static", "no") + try: cf.getboolean("WEBSITE_MODULES", "sitemaps") + except: cf.set("WEBSITE_MODULES", "sitemaps", "yes") # Set template filenames to default if none - favicon = dcf.get("TEMPLATE_FILENAMES", "favicon") or "favicon.png" - logo = dcf.get("TEMPLATE_FILENAMES", "logo") or "logo.png" - styles = dcf.get("TEMPLATE_FILENAMES", "styles") or "styles.css" - rss = dcf.get("TEMPLATE_FILENAMES", "rss") or "rss.xml" - stats = dcf.get("TEMPLATE_FILENAMES", "stats") or "stats.ini" + favicon = cf.get("TEMPLATE_FILENAMES", "favicon") or "favicon.png" + logo = cf.get("TEMPLATE_FILENAMES", "logo") or "logo.png" + styles = cf.get("TEMPLATE_FILENAMES", "styles") or "styles.css" + rss = cf.get("TEMPLATE_FILENAMES", "rss") or "rss.xml" + stats = cf.get("TEMPLATE_FILENAMES", "stats") or "stats.ini" - dcf.get("WEBSITE", "www_url") or \ - dcf.set("WEBSITE", "www_url", "https://%s/"%conf_name) - dcf.get("WEBSITE", "wip_url") or \ - dcf.set("WEBSITE", "wip_url", create_wip_url()) + # https URLs (www + wip) + cf.get("WEBSITE", "www_url") or \ + cf.set("WEBSITE", "www_url", "https://%s/"%name) + cf.get("WEBSITE", "wip_url") or \ + cf.set("WEBSITE", "wip_url", create_wip_url()) - usr_mods = os.path.join(dcf_dir + "modules/") - usr_tpl = os.path.join(dcf_dir, "template/") + usr_mods = os.path.join(cf_dir, "modules/") + usr_tpl = os.path.join(cf_dir, "template/") usr_favicon = os.path.join(usr_tpl, favicon) usr_logo = os.path.join(usr_tpl, logo) usr_styles = os.path.join(usr_tpl, styles) @@ -229,162 +230,187 @@ def dcf_update_values(srv): # Update Domain Configuration File #--------------------------------- - dcf.set("DOMAIN", "name", conf_name) - dcf.set("TYTO", "domain_hash", tools.get_filesum(dcf_uri, False)) - dcf.set("TYTO", "domain_conf", dcf_uri) - dcf.set("TYTO", "domain_user", ult_dcf_uri) + cf.set("DOMAIN", "name", name) + cf.set("TYTO", "domain_hash", tools.get_filesum(cf_uri, False)) + cf.set("TYTO", "domain_conf", cf_uri) + cf.set("TYTO", "domain_user", ult_cf_uri) # USER - dcf.set("USER_DIRS", "root", dcf_dir) - dcf.set("USER_DIRS", "articles", dcf_dir + "articles/") - dcf.set("USER_DIRS", "images", dcf_dir + "images/") - dcf.set("USER_DIRS", "files", dcf_dir + "files/") - dcf.set("USER_DIRS", "modules", usr_mods) - dcf.set("USER_DIRS", "database", dcf_dir + ".db/") - dcf.set("USER_DIRS", "template", usr_tpl) + cf.set("USER_DIRS", "root", cf_dir) + cf.set("USER_DIRS", "articles", cf_dir + "articles/") + cf.set("USER_DIRS", "images", cf_dir + "images/") + cf.set("USER_DIRS", "files", cf_dir + "files/") + cf.set("USER_DIRS", "modules", usr_mods) + cf.set("USER_DIRS", "database", cf_dir + ".db/") + cf.set("USER_DIRS", "template", usr_tpl) - dcf.set("USER_MODULES_FILES", "metas", usr_mods + "tyto_metas.raw") - dcf.set("USER_MODULES_FILES", "header", usr_mods + "tyto_header.raw") - dcf.set("USER_MODULES_FILES", "navbar", usr_mods + "tyto_navbar.raw") - dcf.set("USER_MODULES_FILES", "sidebar", usr_mods + "tyto_sidebar.raw") - dcf.set("USER_MODULES_FILES", "footer", usr_mods + "tyto_footer.raw") + cf.set("USER_MODULES_FILES", "metas", usr_mods + "tyto_metas.raw") + cf.set("USER_MODULES_FILES", "header", usr_mods + "tyto_header.raw") + cf.set("USER_MODULES_FILES", "navbar", usr_mods + "tyto_navbar.raw") + cf.set("USER_MODULES_FILES", "sidebar", usr_mods + "tyto_sidebar.raw") + cf.set("USER_MODULES_FILES", "footer", usr_mods + "tyto_footer.raw") - dcf.set("USER_TEMPLATE_FILES", "favicon", usr_favicon) - dcf.set("USER_TEMPLATE_FILES", "logo", usr_logo) - dcf.set("USER_TEMPLATE_FILES", "styles", usr_styles) + cf.set("USER_TEMPLATE_FILES", "favicon", usr_favicon) + cf.set("USER_TEMPLATE_FILES", "logo", usr_logo) + cf.set("USER_TEMPLATE_FILES", "styles", usr_styles) # WEBSITE - dcf.set("WEBSITE", "lang", langs.site_lang) - dcf.get("WEBSITE_MODULES", "sidebar_title") or \ - dcf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title) - dcf.get("WEBSITE_MODULES", "sidebar_items").isdigit() or \ - dcf.set("WEBSITE_MODULES", "sidebar_items", "0") - dcf.get("WEBSITE_MODULES", "rss_items").isdigit() or \ - dcf.set("WEBSITE_MODULES", "rss_items", "0") + cf.get("WEBSITE_MODULES", "sidebar_title") or \ + cf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title) + cf.get("WEBSITE_MODULES", "sidebar_items").isdigit() or \ + cf.set("WEBSITE_MODULES", "sidebar_items", "0") + cf.get("WEBSITE_MODULES", "rss_items").isdigit() or \ + cf.set("WEBSITE_MODULES", "rss_items", "0") - dcf.set("TEMPLATE_FILENAMES", "favicon", favicon) - dcf.set("TEMPLATE_FILENAMES", "logo", logo) - dcf.set("TEMPLATE_FILENAMES", "styles", styles) - dcf.set("TEMPLATE_FILENAMES", "rss", rss) - dcf.set("TEMPLATE_FILENAMES", "stats", stats) + cf.set("TEMPLATE_FILENAMES", "favicon", favicon) + cf.set("TEMPLATE_FILENAMES", "logo", logo) + cf.set("TEMPLATE_FILENAMES", "styles", styles) + cf.set("TEMPLATE_FILENAMES", "rss", rss) + cf.set("TEMPLATE_FILENAMES", "stats", stats) # SERVER - dcf.set("SERVER", "root", srv) - dcf.set("SERVER", "domain", srv_dom) + cf.set("SERVER", "root", srv) + cf.set("SERVER", "domain", srv_dom) # WIP - dcf.set("WIP_DIRS", "root", srv_wip) - dcf.set("WIP_DIRS", "images", srv_wip + "images/") - dcf.set("WIP_DIRS", "files", srv_wip + "files/") - dcf.set("WIP_DIRS", "template", wip_tpl) - dcf.set("WIP_FILES", "favicon", wip_favicon) - dcf.set("WIP_FILES", "logo", wip_logo) - dcf.set("WIP_FILES", "styles", wip_styles) - dcf.set("WIP_FILES", "rss", wip_rss) - dcf.set("WIP_FILES", "stats", wip_stats) - dcf.set("WIP_FILES", "metas", wip_tpl + "metas.html") - dcf.set("WIP_FILES", "header", wip_tpl + "header.html") - dcf.set("WIP_FILES", "navbar", wip_tpl + "navbar.html") - dcf.set("WIP_FILES", "sidebar", wip_tpl + "sidebar.html") - dcf.set("WIP_FILES", "footer", wip_tpl + "footer.html") + cf.set("WIP_DIRS", "root", srv_wip) + cf.set("WIP_DIRS", "images", srv_wip + "images/") + cf.set("WIP_DIRS", "files", srv_wip + "files/") + cf.set("WIP_DIRS", "template", wip_tpl) + cf.set("WIP_FILES", "favicon", wip_favicon) + cf.set("WIP_FILES", "logo", wip_logo) + cf.set("WIP_FILES", "styles", wip_styles) + cf.set("WIP_FILES", "rss", wip_rss) + cf.set("WIP_FILES", "stats", wip_stats) + cf.set("WIP_FILES", "metas", wip_tpl + "metas.html") + cf.set("WIP_FILES", "header", wip_tpl + "header.html") + cf.set("WIP_FILES", "navbar", wip_tpl + "navbar.html") + cf.set("WIP_FILES", "sidebar", wip_tpl + "sidebar.html") + cf.set("WIP_FILES", "footer", wip_tpl + "footer.html") # WWW - dcf.set("WWW_DIRS", "root", srv_www) - dcf.set("WWW_DIRS", "images", srv_www + "images/") - dcf.set("WWW_DIRS", "files", srv_www + "files/") - dcf.set("WWW_DIRS", "template", www_tpl) - dcf.set("WWW_FILES", "favicon", www_favicon) - dcf.set("WWW_FILES", "logo", www_logo) - dcf.set("WWW_FILES", "styles", www_styles) - dcf.set("WWW_FILES", "rss", www_rss) - dcf.set("WWW_FILES", "stats", www_stats) - dcf.set("WWW_FILES", "metas", www_tpl + "metas.html") - dcf.set("WWW_FILES", "header", www_tpl + "header.html") - dcf.set("WWW_FILES", "navbar", www_tpl + "navbar.html") - dcf.set("WWW_FILES", "sidebar", www_tpl + "sidebar.html") - dcf.set("WWW_FILES", "footer", www_tpl + "footer.html") + cf.set("WWW_DIRS", "root", srv_www) + cf.set("WWW_DIRS", "images", srv_www + "images/") + cf.set("WWW_DIRS", "files", srv_www + "files/") + cf.set("WWW_DIRS", "template", www_tpl) + cf.set("WWW_FILES", "favicon", www_favicon) + cf.set("WWW_FILES", "logo", www_logo) + cf.set("WWW_FILES", "styles", www_styles) + cf.set("WWW_FILES", "rss", www_rss) + cf.set("WWW_FILES", "stats", www_stats) + cf.set("WWW_FILES", "metas", www_tpl + "metas.html") + cf.set("WWW_FILES", "header", www_tpl + "header.html") + cf.set("WWW_FILES", "navbar", www_tpl + "navbar.html") + cf.set("WWW_FILES", "sidebar", www_tpl + "sidebar.html") + cf.set("WWW_FILES", "footer", www_tpl + "footer.html") - with open(dcf_uri, "w") as f: - dcf.write(f) + with open(cf_uri, "w") as f: + cf.write(f) # Update User local domain configuration file #-------------------------------------------- - ult_dcf_load() - ult_dcf.set("DOMAIN", "name", conf_name) - ult_dcf.set("DOMAIN", "hash", tools.get_filesum(dcf_uri, True)) - ult_dcf.set("DOMAIN", "root", dcf_dir) - ult_dcf.set("DOMAIN", "conf", dcf_uri) - ult_dcf.set("SERVER", "root", srv) + ult_cf_load() + ult_cf.set("DOMAIN", "name", name) + ult_cf.set("DOMAIN", "hash", tools.get_filesum(cf_uri, True)) + ult_cf.set("DOMAIN", "root", cf_dir) + ult_cf.set("DOMAIN", "conf", cf_uri) + ult_cf.set("SERVER", "root", srv) - with open(ult_dcf_uri, "w") as f: - ult_dcf.write(f) + with open(ult_cf_uri, "w") as f: + ult_cf.write(f) # Update User local Domains List File #------------------------------------ ult_dlf_load() - ult_dlf.set("DOMAINS", conf_name, dcf_dir) + ult_dlf.set("DOMAINS", name, cf_dir) with open(ult_dlf_uri, "w") as f: ult_dlf.write(f) - debug.out(204, "True", dcf_uri, True, 0, False) + debug.out(204, "True", cf_uri, True, 0, False) #=============================================# # Ensure domain is valid and ready to be used # #---------------------------------------------# -def valid_conf(): +def cf_valid(): global active - dcf_load() - # - dcf name must be config_name - try: dcf_name = dcf.get("DOMAIN", "name") - except: debug.out(100, conf_name, dcf_uri, True, 2, True) - if dcf_name != conf_name: - debug.out(100, conf_name, dcf_uri, True, 2, True) + cf_load() + # - cf name must be config_name + try: cf_name = cf.get("DOMAIN", "name") + except: debug.out(100, name, cf_uri, True, 2, True) + + if cf_name != name: + debug.out(100, name, cf_uri, True, 2, True) # - root server must exists - try: dcf_srv = dcf.get("SERVER", "root") + try: cf_srv = cf.get("SERVER", "root") except: debug.out(100, "SERVER root", "?", True, 2, True) - if not dcf_srv or not tools.dir_exists(dcf_srv, True): - debug.out(100, "SERVER root", "? %s"%dcf_srv, True, 2, True) + if not cf_srv or not tools.dir_exists(cf_srv, True): + debug.out(100, "SERVER root", "? %s"%cf_srv, True, 2, True) - # Check some values in ult_dcf - ult_dcf_load() + # Check some values in ult_cf + ult_cf_load() try: - ult_dcf_name = ult_dcf.get("DOMAIN", "name") - ult_dcf_hash = ult_dcf.get("DOMAIN", "hash") - ult_dcf_conf = ult_dcf.get("DOMAIN", "conf") - ult_dcf_root = ult_dcf.get("DOMAIN", "root") + ult_cf_name = ult_cf.get("DOMAIN", "name") + ult_cf_hash = ult_cf.get("DOMAIN", "hash") + ult_cf_conf = ult_cf.get("DOMAIN", "conf") + ult_cf_root = ult_cf.get("DOMAIN", "root") except: - debug.out(100, conf_name, ult_dcf_uri, True, 1, True) + debug.out(100, name, ult_cf_uri, True, 1, True) # Compare values (exit if mismatch) - if ult_dcf_name != conf_name or \ - ult_dcf_conf != dcf_uri or \ - dcf_name != ult_dcf_name: - debug.out(100, conf_name, "?", True, 1, True) + if ult_cf_name != name or \ + ult_cf_conf != cf_uri or \ + cf_name != ult_cf_name: + debug.out(100, name, "?", True, 1, True) - # Check if dcf need to be updated - now_dcf_hash = tools.get_filesum(dcf_uri, True) - if now_dcf_hash != ult_dcf_hash: - dcf_update_values("") + # Check if cf need to be updated + now_cf_hash = tools.get_filesum(cf_uri, True) + if now_cf_hash != ult_cf_hash: + cf_update_values("") - return is_active() + active = is_active() + active and create_work_dirs() + return active +#========================================# +# When user wants to (de)activate domain # +#----------------------------------------# +def userset_status(action): + do = { + "start" : "yes", + "stop" : "no" + } + + tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action]) + cf_valid() + + #==============================# # Check if domain is activated # # Return True or False #------------------------------# def is_active(): - dcf_load() + cf_load() # Domain activated ? - try: return dcf.getboolean("DOMAIN", "activated") + try: return cf.getboolean("DOMAIN", "activated") except: return False +#===================================# +# Create user domain work directory # +#-----------------------------------# +def create_work_dirs(): + cf_load() + + for key, directory in cf.items("USER_DIRS"): + tools.create_dirs(directory) + + #======#======================================================================= # MAIN # #------# @@ -401,20 +427,20 @@ except: #==========================================# # utl: $USER/.local/Tyto # -# dcf: Domain Configuration File # +# cf: Domain Configuration File # #------------------------------------------# # Domain Configuration directory -dcf_dir = user_dir.rsplit("articles/")[0] +cf_dir = user_dir.rsplit("articles/")[0] # Domain name from current basename directory # Exit if not format at least "abc.tld" -conf_name = os.path.basename(os.path.dirname(dcf_dir)) +name = os.path.basename(os.path.dirname(cf_dir)) -dcf_name = "tyto_domain.ini" -dcf_uri = os.path.join(dcf_dir, dcf_name) -dcf_id = tools.get_filesum(dcf_uri, False) # ID from URI +cf_name = "tyto_domain.ini" +cf_uri = os.path.join(cf_dir, cf_name) +cf_id = tools.get_filesum(cf_uri, False) # ID from URI # Tyto directory in home local user files ult_dir = os.path.join(home_dir, ".local/Tyto/") ult_dlf_uri = os.path.join(ult_dir, "domains.ini") # Domains list file -ult_dcf_uri = os.path.join(ult_dir, dcf_id + ".ini") +ult_cf_uri = os.path.join(ult_dir, cf_id + ".ini") diff --git a/src/var/lib/tyto/program/forms.py b/src/var/lib/tyto/program/forms.py index bd9ebc8..7a3e641 100644 --- a/src/var/lib/tyto/program/forms.py +++ b/src/var/lib/tyto/program/forms.py @@ -102,13 +102,13 @@ def ask_domain_shortname(config_name): # Getting domain Title # #----------------------# def ask_domain_title(): - domain.dcf_load() - title = domain.dcf.get("DOMAIN", "title") + domain.cf_load() + title = domain.cf.get("DOMAIN", "title") q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q) answer = ask(q, False, title) if answer != title: - tools.update_ini_file(domain.dcf_uri, "DOMAIN", "title", answer) + tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer) #===========================# @@ -116,8 +116,8 @@ def ask_domain_title(): # Check if date match regex # #---------------------------# def ask_domain_date(): - domain.dcf_load() - date = domain.dcf.get("DOMAIN", "date") + domain.cf_load() + date = domain.cf.get("DOMAIN", "date") example = date or "YYYY[-MM-DD]" q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q) @@ -141,41 +141,41 @@ def ask_domain_date(): debug.out(50, "YYYY[-MM-DD]", answer, True, 2, True) if answer != date: - tools.update_ini_file(domain.dcf_uri, "DOMAIN", "date", answer) + tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer) #========================# # Get domain description # #------------------------# def ask_domain_about(): - domain.dcf_load() - about = domain.dcf.get("DOMAIN", "about") + domain.cf_load() + about = domain.cf.get("DOMAIN", "about") q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q) answer = ask(q, False, about) if answer != about: - tools.update_ini_file(domain.dcf_uri, "DOMAIN", "about", answer) + tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer) #=======================# # Get domain admin mail # #-----------------------# def ask_domain_mail(): - domain.dcf_load() - mail = domain.dcf.get("DOMAIN", "mail") + domain.cf_load() + mail = domain.cf.get("DOMAIN", "mail") q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q) answer = ask(q, False, mail) if answer != mail: - tools.update_ini_file(domain.dcf_uri, "DOMAIN", "mail", answer) + tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer) #===============================================# # Get domain tags (wil be used in all articles) # #-----------------------------------------------# def ask_domain_tags(): - domain.dcf_load() - tags = domain.dcf.get("DOMAIN", "tags") + domain.cf_load() + tags = domain.cf.get("DOMAIN", "tags") q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q) answer = ask(q, False, tags) @@ -189,7 +189,7 @@ def ask_domain_tags(): if i != len(tuple_tags) - 1: answer = answer + "," - tools.update_ini_file(domain.dcf_uri, "DOMAIN", "tags", answer) + tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer) #===================================# @@ -197,8 +197,8 @@ def ask_domain_tags(): # default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO #-----------------------------------# def ask_domain_lang(): - domain.dcf_load() - lang = domain.dcf.get("WEBSITE", "lang") or langs.get_sys_lang() + langs.get_website_lang() + lang = langs.site_lang q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q) answer = ask(q, False, lang).lower() @@ -206,26 +206,26 @@ def ask_domain_lang(): # Lang Format is 2 character if len(answer) != 2: debug.out("8", "xx", answer, True, 2, False) - ask_domain_lang() - return + debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False) + answer = lang # Check if translation file exists if not langs.translation_exists("website", answer, False): debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False) - answer = "en" + answer = lang if answer != lang: - tools.update_ini_file(domain.dcf_uri, "WEBSITE", "lang", answer) + tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer) #===================================# # Get domain server root # #-----------------------------------# def ask_domain_server(): - domain.dcf_load() - srv = domain.dcf.get("SERVER", "root") + domain.cf_load() + srv = domain.cf.get("SERVER", "root") - if srv and not not tools.dir_exists(srv, False): + if srv and not tools.dir_exists(srv, False): srv = "" q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q) @@ -237,5 +237,5 @@ def ask_domain_server(): ask_domain_server() return - domain.dcf_update_values(answer) + domain.cf_update_values(answer) diff --git a/src/var/lib/tyto/program/langs.py b/src/var/lib/tyto/program/langs.py index 03465c4..a336f1a 100644 --- a/src/var/lib/tyto/program/langs.py +++ b/src/var/lib/tyto/program/langs.py @@ -104,14 +104,14 @@ def load_logs_lang(): # Get/Set and import file | # #=============================================================================# #=======================================# -# Get website lang from dcf to set site # +# Get website lang from cf to set site # #---------------------------------------# def get_website_lang(): global site_lang, tr_website_uri tr_website_uri = "%swebsite_%s.py" - domain.dcf_load() - site_lang = domain.dcf.get("WEBSITE", "lang") + domain.cf_load() + site_lang = domain.cf.get("WEBSITE", "lang") or get_sys_lang() if not translation_exists("website", site_lang, False): site_lang = get_sys_lang() # or default "en" diff --git a/src/var/lib/tyto/program/new.py b/src/var/lib/tyto/program/new.py index 1310e79..58d141c 100644 --- a/src/var/lib/tyto/program/new.py +++ b/src/var/lib/tyto/program/new.py @@ -54,8 +54,8 @@ def manage(action, target): # or if user "force" option #-----------------------------------# def create_domain(): - if not domain.dcf_exists() or args.force: - domain.dcf_create() + if not domain.cf_exists() or args.force: + domain.cf_create() return diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py new file mode 100644 index 0000000..f5c7407 --- /dev/null +++ b/src/var/lib/tyto/program/post.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# 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 General Public License as published by +# the Free Software Foundation, either version 3 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#---------------------------------------------------------------------- +# XMPP: echolib (im@echolib.re) +# +# Description: About post (from target) database, uri... +# File: /var/lib/tyto/program/new.py +#---------------------------------------------------------------------- + +#------------------------- +# Funny Stats Project +#------------------------- +# file lines : +# file comments : +# file functions: +# file program : +#-------------------------- diff --git a/src/var/lib/tyto/program/tools.py b/src/var/lib/tyto/program/tools.py index 6e8e8a6..429cf5d 100644 --- a/src/var/lib/tyto/program/tools.py +++ b/src/var/lib/tyto/program/tools.py @@ -63,6 +63,19 @@ def dir_exists(dir_path, out): return True +#====================# +# Create directories # +#--------------------# +def create_dirs(path): + try: + if not os.path.exists(path): + os.makedirs(path, exist_ok=True) + debug.out(203, "True", path, False, 0, False) + except: + # Exit if not created + debug.out(5, "False", path, True, 2, True) + + #============================# # Create a new file and logs # #----------------------------# @@ -76,8 +89,10 @@ def create_file(file_path, contents): # Exit at error debug.out(7, "False", file_path, True, 2, True) - if up: debug.out(207, file_path, False, 0, False) - else: debug.out(206, file_path, False, 0, False) + # log "update" or "new" + file_name = os.path.basename(file_path) + if up: debug.out(207, file_name, file_path, False, 0, False) + else: debug.out(206, file_name, file_path, False, 0, False) #===========================================# @@ -88,23 +103,15 @@ def update_ini_file(file_path, section, key, val): if not os.path.exists(file_path): debug.out(5, "False", file_path, True, 2, True) + # Load ini file config = configparser.ConfigParser() config.read(file_path) - config.set(section, key, val) + # New value is same as registred + if config.get(section, key) == val: + return + + # Update file with new value + config.set(section, key, val) with open(file_path, "w") as f: config.write(f) - - -#====================# -# Create directories # -#--------------------# -def create_dirs(path): - try: - if not os.path.exists(path): - os.makedirs(path, exist_ok=True) - debug.out(203, "True", path, False, 0, False) - except: - # Exit if not created - debug.out(5, "False", path, True, 2, True) - diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 0054efa..a767c37 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -28,6 +28,7 @@ # actions = ( "check", "wip", "publish", + "start", "stop", "new", "set", "show", diff --git a/src/var/lib/tyto/program/userset.py b/src/var/lib/tyto/program/userset.py index 29b688b..09eee8c 100644 --- a/src/var/lib/tyto/program/userset.py +++ b/src/var/lib/tyto/program/userset.py @@ -32,7 +32,7 @@ # file program : #-------------------------- -import langs, forms +import langs, forms, domain #====================================# @@ -40,14 +40,19 @@ import langs, forms # Specific to action "set # #------------------------------------# def manage(action, target): - do = { - "title" : forms.ask_domain_title, - "date" : forms.ask_domain_date, - "about" : forms.ask_domain_about, - "mail" : forms.ask_domain_mail, - "lang" : forms.ask_domain_lang, - "server" : forms.ask_domain_server, - } + if action == "set": + do = { + "title" : forms.ask_domain_title, + "date" : forms.ask_domain_date, + "about" : forms.ask_domain_about, + "mail" : forms.ask_domain_mail, + "lang" : forms.ask_domain_lang, + "server" : forms.ask_domain_server, + } + + do[target]() + elif action in ("start", "stop") \ + and target == "domain": + domain.userset_status(action) + - do[target]() - diff --git a/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc b/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc index 18871d6..02ca1b0 100644 Binary files a/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc and b/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc differ diff --git a/src/var/lib/tyto/translations/logs_en.py b/src/var/lib/tyto/translations/logs_en.py index c8a0cdb..e8ccef8 100644 --- a/src/var/lib/tyto/translations/logs_en.py +++ b/src/var/lib/tyto/translations/logs_en.py @@ -42,6 +42,8 @@ tyto [action] [target] [options] [action] new : create new domain (reset with -F) set : set website lang, domain values (title, server...) + start : activate domain (default "no" when created) + stop : deactivate domain check : wip : publish : diff --git a/src/var/lib/tyto/translations/logs_fr.py b/src/var/lib/tyto/translations/logs_fr.py index f854c3e..f5d50b3 100644 --- a/src/var/lib/tyto/translations/logs_fr.py +++ b/src/var/lib/tyto/translations/logs_fr.py @@ -86,6 +86,8 @@ tyto [action] [target] [options] [action] new : créer un nouveau domaine (réinitialisé avec -F) set : définir la langue du site web, du domaine (titre, serveur...) + start : activer le domaine (défaut "no" à la création) + stop : désactiver le domaine show : [domains] check : wip :