diff --git a/CHANGELOG.md b/CHANGELOG.md index a51a171..0c500c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ Tyto - Littérateur # CURRENTLY IN DEV ! +## [1.9.10] +- cleaner code +- start/stop domain by user +- User directories check/create when domain activated + +## [1.9.9] +- cleaner code with new check/update domain process + ## [1.9.8] - Check/create/update a domain is ready diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index b8255aa..abf0518 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.9 -# Updated: 2023-09-29 1695992721 +# Version: 1.9.10 +# Updated: 2023-09-29 1695998917 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn @@ -41,6 +41,37 @@ # file program : #-------------------------- +import os + + +#===============# +# Error message # +#---------------# +def error_message(path): + print("! Installation error, unused:", path) + sys.exit(1) + + +#======================================================# +# A little checker to be sure, all files are installed # +#------------------------------------------------------# +def check_install(): + if not os.path.exists(libs): error_message(libs) + if not os.path.exists(trfs): error_message(trfs) + + for f in prog_files: + f = os.path.join(libs, f + ".py") + if not os.path.exists(f): + error_message(f) + + # Only default lang files + for f in lang_files: + f = os.path.join(trfs, f + ".py") + if not os.path.exists(f): + error_message(f) + + + #======#======================================================================= # MAIN # #======# @@ -49,9 +80,35 @@ if not __name__ == "__main__": print("! Error: '%s' not '%s'"%(__name__, "__main__")) sys.exit(1) +# files list in /program/ +prog_files = { + "args", + "check", + "debug", + "domain", + "forms", + "help", + "langs", + "new", + "post", + "show", + "tools", + "tyto", + "userset" + } +lang_files = { + "logs_en", + "logs_fr", + "website_en", + "website_fr" + } + # Set librairies to import app files libs = "/var/lib/tyto/program" trfs = "/var/lib/tyto/translations" + +check_install() + sys.path.insert(0, libs) sys.path.insert(0, trfs) 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 ef739a7..fb38194 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__/debug.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc index 28e7f8b..d42cd39 100644 Binary files a/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/debug.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 c5f7f01..2598c44 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__/tools.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc index 3129a0b..df7a87c 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__/userset.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc index f0eeefd..beda49e 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/check.py b/src/var/lib/tyto/program/check.py index 5ba563d..cac1d5f 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -42,10 +42,9 @@ import domain, langs, debug, post, tools # Create user work domain directories # #-------------------------------------------# def manage(action, target): - # Load domain configuration (update it if needed), check if valid - #domain.cf_valid() or debug.out(105, domain.name, domain.cf_uri, True, 1, True) + # Load configuration and website lang domain.cf_update_values(False) + domain.ready() + target.endswith(".tyto") and post.is_article(target) - langs.load_website_lang() - diff --git a/src/var/lib/tyto/program/debug.py b/src/var/lib/tyto/program/debug.py index 85c9e44..1f321b0 100644 --- a/src/var/lib/tyto/program/debug.py +++ b/src/var/lib/tyto/program/debug.py @@ -105,6 +105,7 @@ def out(nbr, var, val, show, color, stop): 206 : langs.logs.created_file, 207 : langs.logs.updated_file, 208 : langs.logs.website_lang, + 209 : langs.logs.domain_on, 255 : langs.logs.later, } diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 3d33654..f69b0a8 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -545,61 +545,41 @@ def cf_update_values(write): ult_dlf.write(f) - -#=============================================# -# Ensure domain is valid and ready to be used # -#---------------------------------------------# -def cf_valid(): - global active - - if not tools.compare_ini_ft(cf_uri, tyto.ini_domain): - cf_update_values(False) - - # Check if cf need to be updated - ult_cf_load() - ult_cf_hash = ult_cf.get("DOMAIN", "hash") - now_cf_hash = tools.get_filesum(cf_uri, True) - if now_cf_hash != ult_cf_hash: - cf_update_values(False) - - active = is_active() - active and create_wrk_dirs() - return active - - #========================================# # When user wants to (de)activate domain # +# Update key value and ensure conf is ok # # +# if activated, check/create wrk dirs # #----------------------------------------# def userset_status(action): + do = { "start" : "yes", "stop" : "no" } tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action]) - cf_valid() + cf_update_values(False) + ready() - -#==============================# -# Check if domain is activated # -# Return True or False -#------------------------------# -def is_active(): - cf_load() - # Domain activated ? - try: return cf.getboolean("DOMAIN", "activated") - except: return False + if action == "start": + status = cf.get("DOMAIN", "activated") + debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False) -#===================================# -# Create user domain work directory # -#-----------------------------------# -def create_wrk_dirs(): - cf_load() +#========================================# +# (After configuration file was checked) # +# Exit if domain not activated # +# # +# or check/create wrk directories # +#----------------------------------------# +def ready(): + if not activated: + status = cf.get("DOMAIN", "activated") + debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True) for key, directory in cf.items("USER_DIRS"): tools.create_dirs(directory) - + #======#======================================================================= # MAIN # diff --git a/src/var/lib/tyto/program/tools.py b/src/var/lib/tyto/program/tools.py index b3ac765..4d78b39 100644 --- a/src/var/lib/tyto/program/tools.py +++ b/src/var/lib/tyto/program/tools.py @@ -141,33 +141,14 @@ def update_ini_file(file_path, section, key, val): config.read(file_path) # New value is same as registred - if config.get(section, key) == val: - return + try: + if config.get(section, key) == val: + return + except: + config.add_section(section) # Update file with new value config.set(section, key, val) with open(file_path, "w") as f: config.write(f) - -#==================================================# -# Compare database file with origin file template # -# Used for domain and article configuration file # -# Return True, if ini keys are same # -#--------------------------------------------------# -def compare_ini_ft(cf_uri, template): - with open(cf_uri, "r") as f: - ln = 0 - lines = f.read() - lines = lines.rsplit("\n") - - for key_t in template.rsplit("\n"): - ln += 1 - key_t = key_t.rsplit("=")[0] - key_f = lines[ln -1].rsplit("=")[0] - - if not key_t == key_f: - debug.out(9, "l=%s: %s != %s"%(ln, key_f, key_t), cf_uri, False, 2, False) - return False - - return True diff --git a/src/var/lib/tyto/program/userset.py b/src/var/lib/tyto/program/userset.py index d752dd7..bd23470 100644 --- a/src/var/lib/tyto/program/userset.py +++ b/src/var/lib/tyto/program/userset.py @@ -40,8 +40,10 @@ import langs, forms, domain # Specific to action "set # #------------------------------------# def manage(action, target): + # Load or Exit if no configuration + domain.cf_load() + if action == "set": - domain.cf_load() do = { "title" : forms.ask_domain_title, "date" : forms.ask_domain_date, @@ -52,6 +54,7 @@ def manage(action, target): } do[target](True) + elif action in ("start", "stop") and target == "domain": domain.userset_status(action) 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 1ba5efa..e724e2e 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_fr.py b/src/var/lib/tyto/translations/logs_fr.py index a75af9e..f698d82 100644 --- a/src/var/lib/tyto/translations/logs_fr.py +++ b/src/var/lib/tyto/translations/logs_fr.py @@ -73,6 +73,7 @@ lang_logs_sys = "Langue des logs" website_lang = "Langue du site web" domains_no = "Aucun domaine trouvé" domain_found = "Domaine présent" +domain_on = "Domaine activé" domain_created = "Domaine déjà créé" domain_updated = "Domaine mis à jour" domain_new = "Domaine créé"