diff --git a/CHANGELOG.md b/CHANGELOG.md index c618bdf..a51a171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ Tyto - Littérateur - License: - Documentation: +# CURRENTLY IN DEV ! + +## [1.9.8] +- Check/create/update a domain is ready + ## [1.9.7] - new process to check and update configuration file (bug at write some values) diff --git a/README.md b/README.md index 0a56932..3ce4399 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ tyto ``` ## ToDo next (working on) -- Manage domain configuration file values - check action - create template post database diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 4a53280..2b0113c 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.7 -# Updated: 2023-09-27 1695799605 +# Version: 1.9.8 +# Updated: 2023-09-27 1695826135 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn 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 5c8f9bd..cf79271 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__/langs.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc index fa48364..cb08c4b 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/domain.py b/src/var/lib/tyto/program/domain.py index 033d44e..847f099 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -180,9 +180,7 @@ def cf_create(): # Ensure to set correct values # #-------------------------------------------# def cf_update_values(write): - global cf # Load Domain Configuration file - cf = "" cf_load() if cf.get("DOMAIN", "name") != name: @@ -201,7 +199,6 @@ def cf_update_values(write): global srv_name srv_name = os.path.join(srv, name + "/") - print("domain: srv_name", srv_name) if cf.get("SERVER", "domain") != srv_name: cf.set("SERVER", "domain", srv_name) debug.out(204, "[SERVER] domain", srv_name, False, 0, False) @@ -313,19 +310,30 @@ def cf_update_values(write): cf.set("DOMAIN", "license_url", "https://www.gnu.org/licenses/fdl-1.3.txt") write = True + # Optional + global legals_url, terms_url, statuses_url + legals_url = cf.get("DOMAIN", "legals_url") + terms_url = cf.get("DOMAIN", "terms_url") + statuses_url = cf.get("DOMAIN", "statuses_url") + # [WEBSITE] # ========= - global www_url, wip_url + global www_url www_url = cf.get("WEBSITE", "www_url") if not www_url: - cf.set("WEBSITE", "www_url", "https://%s/"%name) + www_url = "https://%s/"%name + cf.set("WEBSITE", "www_url", www_url) + debug.out(204, "[WEBSITE] www_url", www_url, False, 0, False) write = True + global wip_url wip_url = cf.get("WEBSITE", "wip_url") if not wip_url: - cf.set("WEBSITE", "wip_url", create_wip_url()) + wip_url = create_wip_url() + cf.set("WEBSITE", "wip_url", wip_url) + debug.out(204, "[WEBSITE] wip_url", wip_url, False, 0, False) write = True - + global lang lang = cf.get("WEBSITE", "lang") if not lang: @@ -336,11 +344,12 @@ def cf_update_values(write): write = True langs.load_website_lang() - + global css css = cf.get("WEBSITE", "css") if not css: - cf.set("WEBSITE", "css", "tyto") + cf.set("WEBSITE", "css", "tyto") + write = True global sep sep = cf.get("WEBSITE", "separator") @@ -355,6 +364,7 @@ def cf_update_values(write): except: cf.set("WEBSITE", "static", "no") ; write = True # [WEBSITE_MODULES] + # ================= global navbar try: cf.getboolean("WEBSITE_MODULES", "navbar") except: cf.set("WEBSITE_MODULES", "navbar", "yes") ; write = True @@ -391,14 +401,7 @@ def cf_update_values(write): if cf.get("USER_TEMPLATE_FILES", "favicon") != usr_favicon: cf.set("USER_TEMPLATE_FILES", "favicon", usr_favicon) write = True - wip_favicon = os.path.join(srv_wip_tpl, favicon) - if cf.get("WIP_FILES", "favicon") != wip_favicon: - cf.set("WIP_FILES", "favicon", wip_favicon) - write = True - www_favicon = os.path.join(srv_www_tpl, favicon) - if cf.get("WWW_FILES", "favicon") != www_favicon: - cf.set("WWW_FILES", "favicon", www_favicon) - write = True + logo = cf.get("TEMPLATE_FILENAMES", "logo") if not logo: @@ -409,14 +412,6 @@ def cf_update_values(write): if cf.get("USER_TEMPLATE_FILES", "logo") != usr_logo: cf.set("USER_TEMPLATE_FILES", "logo", usr_logo) write = True - wip_logo = os.path.join(srv_wip_tpl, logo) - if cf.get("WIP_FILES", "logo") != wip_logo: - cf.set("WIP_FILES", "logo", wip_logo) - write = True - www_logo = os.path.join(srv_www_tpl, logo) - if cf.get("WWW_FILES", "logo") != www_logo: - cf.set("WWW_FILES", "logo", www_logo) - write = True styles = cf.get("TEMPLATE_FILENAMES", "styles") if not styles: @@ -427,42 +422,18 @@ def cf_update_values(write): if cf.get("USER_TEMPLATE_FILES", "styles") != usr_styles: cf.set("USER_TEMPLATE_FILES", "styles", usr_styles) write = True - wip_styles = os.path.join(srv_wip_tpl, styles) - if cf.get("WIP_FILES", "styles") != wip_styles: - cf.set("WIP_FILES", "styles", wip_styles) - write = True - www_styles = os.path.join(srv_www_tpl, styles) - if cf.get("WWW_FILES", "styles") != www_styles: - cf.set("WWW_FILES", "styles", www_styles) - write = True rss = cf.get("TEMPLATE_FILENAMES", "rss") if not rss: rss = "rss.xml" cf.set("TEMPLATE_FILENAMES", "rss", rss) write = True - wip_rss = os.path.join(srv_wip_tpl, rss) - if cf.get("WIP_FILES", "rss") != wip_rss: - cf.set("WIP_FILES", "rss", wip_rss) - write = True - www_rss = os.path.join(srv_www_tpl, rss) - if cf.get("WWW_FILES", "rss") != www_rss: - cf.set("WWW_FILES", "rss", www_rss) - write = True stats = cf.get("TEMPLATE_FILENAMES", "stats") if not stats: stats = "tyto_stats.ini" cf.set("TEMPLATE_FILENAMES", "stats", stats) write = True - wip_stats = os.path.join(srv_wip_tpl, stats) - if cf.get("WIP_FILES", "stats") != wip_stats: - cf.set("WIP_FILES", "stats", wip_stats) - write = True - www_stats = os.path.join(srv_www_tpl, stats) - if cf.get("WWW_FILES", "stats") != www_stats: - cf.set("WWW_FILES", "stats", www_stats) - write = True # [USER_DIRS] # =========== @@ -488,6 +459,167 @@ def cf_update_values(write): cf.set("USER_DIRS", "database", cf_usr_db) write = True + # USER_MODULES_FILES + # ================== + global usr_metas + usr_metas = os.path.join(cf_usr_mods, "tyto_metas.raw") + if cf.get("USER_MODULES_FILES", "metas") != usr_metas: + cf.set("USER_MODULES_FILES", "metas", usr_metas) + debug.out(204, "[USER_MODULES_FILES] metas", usr_metas, False, 0, False) + write = True + + global usr_header + usr_header = os.path.join(cf_usr_mods, "tyto_header.raw") + if cf.get("USER_MODULES_FILES", "header") != usr_header: + cf.set("USER_MODULES_FILES", "header", usr_header) + debug.out(204, "[USER_MODULES_FILES] header", usr_header, False, 0, False) + write = True + + global usr_navbar + usr_navbar = os.path.join(cf_usr_mods, "tyto_navbar.raw") + if cf.get("USER_MODULES_FILES", "navbar") != usr_navbar: + cf.set("USER_MODULES_FILES", "navbar", usr_navbar) + debug.out(204, "[USER_MODULES_FILES] navbar", usr_navbar, False, 0, False) + write = True + + global usr_sidebar + usr_sidebar = os.path.join(cf_usr_mods, "tyto_sidebar.raw") + if cf.get("USER_MODULES_FILES", "sidebar") != usr_sidebar: + cf.set("USER_MODULES_FILES", "sidebar", usr_sidebar) + debug.out(204, "[USER_MODULES_FILES] sidebar", usr_sidebar, False, 0, False) + write = True + + global usr_footer + usr_footer = os.path.join(cf_usr_mods, "tyto_footer.raw") + if cf.get("USER_MODULES_FILES", "footer") != usr_footer: + cf.set("USER_MODULES_FILES", "footer", usr_footer) + debug.out(204, "[USER_MODULES_FILES] footer", usr_footer, False, 0, False) + write = True + + # [WIP_FILES] + # =========== + wip_favicon = os.path.join(srv_wip_tpl, favicon) + if cf.get("WIP_FILES", "favicon") != wip_favicon: + cf.set("WIP_FILES", "favicon", wip_favicon) + write = True + + wip_logo = os.path.join(srv_wip_tpl, logo) + if cf.get("WIP_FILES", "logo") != wip_logo: + cf.set("WIP_FILES", "logo", wip_logo) + write = True + + wip_styles = os.path.join(srv_wip_tpl, styles) + if cf.get("WIP_FILES", "styles") != wip_styles: + cf.set("WIP_FILES", "styles", wip_styles) + write = True + + wip_rss = os.path.join(srv_wip_tpl, rss) + if cf.get("WIP_FILES", "rss") != wip_rss: + cf.set("WIP_FILES", "rss", wip_rss) + write = True + + wip_stats = os.path.join(srv_wip_tpl, stats) + if cf.get("WIP_FILES", "stats") != wip_stats: + cf.set("WIP_FILES", "stats", wip_stats) + write = True + + global wip_metas + wip_metas = os.path.join(srv_wip_tpl, "metas.html") + if cf.get("WIP_FILES", "metas") != wip_metas: + cf.set("WIP_FILES", "metas", wip_metas) + debug.out(204, "[WIP_FILES] metas", wip_metas, False, 0, False) + write = True + + global wip_header + wip_header = os.path.join(srv_wip_tpl, "header.html") + if cf.get("WIP_FILES", "header") != wip_header: + cf.set("WIP_FILES", "header", wip_header) + debug.out(204, "[WIP_FILES] header", wip_header, False, 0, False) + write = True + + global wip_navbar + wip_navbar = os.path.join(srv_wip_tpl, "navbar.html") + if cf.get("WIP_FILES", "navbar") != wip_navbar: + cf.set("WIP_FILES", "navbar", wip_navbar) + debug.out(204, "[WIP_FILES] navbar", wip_navbar, False, 0, False) + write = True + + global wip_sidebar + wip_sidebar = os.path.join(srv_wip_tpl, "sidebar.html") + if cf.get("WIP_FILES", "sidebar") != wip_sidebar: + cf.set("WIP_FILES", "sidebar", wip_sidebar) + debug.out(204, "[WIP_FILES] sidebar", wip_sidebar, False, 0, False) + write = True + + global wip_footer + wip_footer = os.path.join(srv_wip_tpl, "footer.html") + if cf.get("WIP_FILES", "footer") != wip_footer: + cf.set("WIP_FILES", "footer", wip_footer) + debug.out(204, "[WIP_FILES] footer", wip_footer, False, 0, False) + write = True + + # [WWW_FILES] + # =========== + www_favicon = os.path.join(srv_www_tpl, favicon) + if cf.get("WWW_FILES", "favicon") != www_favicon: + cf.set("WWW_FILES", "favicon", www_favicon) + write = True + + www_logo = os.path.join(srv_www_tpl, logo) + if cf.get("WWW_FILES", "logo") != www_logo: + cf.set("WWW_FILES", "logo", www_logo) + write = True + + www_styles = os.path.join(srv_www_tpl, styles) + if cf.get("WWW_FILES", "styles") != www_styles: + cf.set("WWW_FILES", "styles", www_styles) + write = True + + www_rss = os.path.join(srv_www_tpl, rss) + if cf.get("WWW_FILES", "rss") != www_rss: + cf.set("WWW_FILES", "rss", www_rss) + write = True + + www_stats = os.path.join(srv_www_tpl, stats) + if cf.get("WWW_FILES", "stats") != www_stats: + cf.set("WWW_FILES", "stats", www_stats) + write = True + + global www_metas + www_metas = os.path.join(srv_www_tpl, "metas.html") + if cf.get("WWW_FILES", "metas") != www_metas: + cf.set("WWW_FILES", "metas", www_metas) + debug.out(204, "[WWW_FILES] metas", www_metas, False, 0, False) + write = True + + global www_header + www_header = os.path.join(srv_www_tpl, "header.html") + if cf.get("WWW_FILES", "header") != www_header: + cf.set("WWW_FILES", "header", www_header) + debug.out(204, "[WWW_FILES] header", www_header, False, 0, False) + write = True + + global www_navbar + www_navbar = os.path.join(srv_www_tpl, "navbar.html") + if cf.get("WWW_FILES", "navbar") != www_navbar: + cf.set("WWW_FILES", "navbar", www_navbar) + debug.out(204, "[WWW_FILES] navbar", www_navbar, False, 0, False) + write = True + + global www_sidebar + www_sidebar = os.path.join(srv_www_tpl, "sidebar.html") + if cf.get("WWW_FILES", "sidebar") != www_sidebar: + cf.set("WWW_FILES", "sidebar", www_sidebar) + debug.out(204, "[WWW_FILES] sidebar", www_sidebar, False, 0, False) + write = True + + global www_footer + www_footer = os.path.join(srv_www_tpl, "footer.html") + if cf.get("WWW_FILES", "footer") != www_footer: + cf.set("WWW_FILES", "footer", www_footer) + debug.out(204, "[WWW_FILES] footer", www_footer, False, 0, False) + write = True + # [TYTO] # ====== if cf.get("TYTO", "domain_hash") != cf_id: @@ -500,35 +632,60 @@ def cf_update_values(write): cf.set("TYTO", "domain_user", ult_cf_uri) write = True - # Write Configuration file # Only if needed or when new domain - print("domain: write", write) if write: with open(cf_uri, "w") as f: cf.write(f) + debug.out(204, "True", cf_uri, True, 0, False) - # Update User local domain configuration file - #-------------------------------------------- + + #=============================================# + # Update User local domain configuration file # + #---------------------------------------------# + ult_write = False 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) + if ult_cf.get("DOMAIN", "name") != name: + ult_cf.set("DOMAIN", "name", name) + ult_write = True + + cf_hash_c = tools.get_filesum(cf_uri, True) + if ult_cf.get("DOMAIN", "hash") != cf_hash_c: + ult_cf.set("DOMAIN", "hash", cf_hash_c) + ult_write = True + + if ult_cf.get("DOMAIN", "root") != cf_dir: + ult_cf.set("DOMAIN", "root", cf_dir) + ult_write = True + + if ult_cf.get("DOMAIN", "conf") != cf_uri: + ult_cf.set("DOMAIN", "conf", cf_uri) + ult_write = True + + if ult_cf.get("SERVER", "root") != srv: + ult_cf.set("SERVER", "root", srv) + ult_write = True - with open(ult_cf_uri, "w") as f: - ult_cf.write(f) + if ult_write: + 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", name, cf_dir) + dlf_write = False + try: + dlf_line = ult_dlf.get("DOMAINS", name) + if dlf_line != cf_dir: + dlf_write = True + except: + dlf_write = True - with open(ult_dlf_uri, "w") as f: - ult_dlf.write(f) - - debug.out(204, "True", cf_uri, True, 0, False) + if dlf_write: + ult_dlf.set("DOMAINS", name, cf_dir) + with open(ult_dlf_uri, "w") as f: + ult_dlf.write(f) + #=============================================# diff --git a/src/var/lib/tyto/program/langs.py b/src/var/lib/tyto/program/langs.py index 77054bc..0dc4aba 100644 --- a/src/var/lib/tyto/program/langs.py +++ b/src/var/lib/tyto/program/langs.py @@ -110,8 +110,8 @@ def get_website_lang(): global site_lang, tr_website_uri tr_website_uri = "%swebsite_%s.py" - domain.cf_load() - site_lang = domain.cf.get("WEBSITE", "lang") or get_sys_lang() + try: site_lang = domain.cf.get("WEBSITE", "lang") + except: site_lang = get_sys_lang() if not translation_exists("website", site_lang, False): site_lang = get_sys_lang() # or default "en"