Cleaner code, better update process for domain configuration file

This commit is contained in:
Cyrille L 2023-09-29 15:06:12 +02:00
parent 02cad1789e
commit 2bcda76cd0
9 changed files with 306 additions and 435 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.8 # Version: 1.9.9
# Updated: 2023-09-27 1695826135 # Updated: 2023-09-29 1695992721
# Tyto - Littérateur # Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org> # Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -67,10 +67,7 @@ def ult_cf_load():
ult_cf = False ult_cf = False
if not os.path.exists(ult_cf_uri): if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user) tools.create_file(ult_cf_uri, tyto.ini_domain_user)
if os.path.exists(cf_uri): cf_update_values()
else: debug.out(100, name, ult_cf_uri, True, 1, True)
ult_cf = configparser.ConfigParser() ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri) ult_cf.read(ult_cf_uri)
@ -83,10 +80,10 @@ def ult_dlf_load():
global ult_dlf global ult_dlf
# User Domains list file # User Domains list file
ult_dlf = False
if not os.path.exists(ult_dlf_uri): if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list) tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
ult_dlf = False
ult_dlf = configparser.ConfigParser() ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri) ult_dlf.read(ult_dlf_uri)
@ -113,20 +110,20 @@ def cf_exists():
#=========================================# #=========================================#
# Guess and return wip_url from name # # Guess and return www_url from name #
#-----------------------------------------# #-----------------------------------------#
def create_wip_url(): def create_www_url():
wip_url = "https://www-wip.%s/" www_url = "https://www-wip.%s/"
len_cn = name.count(".") len_cn = name.count(".")
# Domain name Format: a.b # Domain name Format: a.b
if len_cn == 1: if len_cn == 1:
return wip_url%name return www_url%name
# Domain name format: (at least) a.b.c # Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1 len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:] tld = name[len_cn:]
return wip_url%tld return www_url%tld
#==========================================# #==========================================#
@ -174,470 +171,330 @@ def cf_create():
cf_update_values(True) cf_update_values(True)
#===================================================#
# Generic set section and values for ini file #
# File must exists (checked before) #
# Create section, set key if not exists #
# Ask yser when default is a key form and not value #
#---------------------------------------------------#
def cf_set_value(section, key, default):
global new_val
try: new_val
except: new_val = False
try:
val = cf.get(section, key)
except:
try: cf.add_section(section) ; new_val = True
except: pass
val = ""
# Values has a form
if default in tyto.keys_4q:
if val: return val
else: default = tyto.keys_questions[default](False) ; new_val = True
# Optional key
elif not default:
if not val: return default
else: default = val
# Force set default value
if val != default:
new_val = True
cf.set(section, key, default)
debug.out(204, "[%s] %s"%(section, key), default, False, 0, False)
return default
#===========================================# #===========================================#
# Set or Update domain configuration values # # Set or Update domain configuration values #
# Ask for some values if empty # # Ask for some values if empty #
# Ensure to set correct values # # Ensure to set correct values #
#-------------------------------------------# #-------------------------------------------#
def cf_update_values(write): def cf_update_values(write):
# Load Domain Configuration file # Load Domain Configuration file
cf_load() cf_load()
if cf.get("DOMAIN", "name") != name:
cf.set("DOMAIN", "name", name)
debug.out(204, "[DOMAIN] name", name, False, 0, False)
write = True
# [SERVER]
global srv
srv = cf.get("SERVER", "root")
if not tools.dir_exists(srv, False):
srv = forms.ask_domain_server(False)
cf.set("SERVER", "root", srv)
debug.out(204, "[SERVER] root", srv, False, 0, False)
write = True
global srv_name
srv_name = os.path.join(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)
write = True
global srv_wip
srv_wip = os.path.join(srv_name, "wip/")
if cf.get("SERVER", "wip") != srv_wip:
cf.set("SERVER", "wip", srv_wip)
debug.out(204, "[SERVER] wip", srv_wip, False, 0, False)
write = True
global srv_wip_tpl
srv_wip_tpl = os.path.join(srv_wip, "template/")
if cf.get("WIP_DIRS", "template") != srv_wip_tpl:
cf.set("WIP_DIRS", "template", srv_wip_tpl)
debug.out(204, "[WIP_DIRS] template", srv_wip_tpl, False, 0, False)
write = True
global srv_wip_images
srv_wip_images = os.path.join(srv_wip, "images/")
if cf.get("WIP_DIRS", "images") != srv_wip_images:
cf.set("WIP_DIRS", "images", srv_wip_images)
debug.out(204, "[WIP_DIRS] images", srv_wip_images, False, 0, False)
write = True
global srv_wip_files
srv_wip_files = os.path.join(srv_wip, "files/")
if cf.get("WIP_DIRS", "files") != srv_wip_files:
cf.set("WIP_DIRS", "files", srv_wip_files)
debug.out(204, "[WIP_DIRS] files", srv_wip_files, False, 0, False)
write = True
global srv_www
srv_www = os.path.join(srv_name, "www/")
if cf.get("SERVER", "www") != srv_www:
cf.set("SERVER", "www", srv_www)
debug.out(204, "[SERVER] www", srv_www, False, 0, False)
write = True
global srv_www_tpl
srv_www_tpl = os.path.join(srv_www, "template/")
if cf.get("WWW_DIRS", "template") != srv_www_tpl:
cf.set("WWW_DIRS", "template", srv_www_tpl)
debug.out(204, "[WWW_DIRS] template", srv_www_tpl, False, 0, False)
write = True
global srv_www_images
srv_www_images = os.path.join(srv_www, "images/")
if cf.get("WWW_DIRS", "images") != srv_www_images:
cf.set("WWW_DIRS", "images", srv_www_images)
debug.out(204, "[WWW_DIRS] images", srv_www_images, False, 0, False)
write = True
global srv_www_files
srv_www_files = os.path.join(srv_www, "files/")
if cf.get("WWW_DIRS", "files") != srv_www_files:
cf.set("WWW_DIRS", "files", srv_www_files)
debug.out(204, "[WWW_DIRS] files", srv_www_files, False, 0, False)
write = True
# [DOMAIN] # [DOMAIN]
# ======== # ========
try: cf.getboolean("DOMAIN", "activated") global activated, title, date, about, mail, tags, license, license_url
except: try: activated = cf.getboolean("DOMAIN", "activated")
cf.set("DOMAIN", "activated", "no") except: activated = cf_set_value("DOMAIN", "activated", "no")
debug.out(204, "[DOMAIN] activated", "no", False, 0, False)
write = True
global title cf_set_value("DOMAIN", "name", name)
title = cf.get("DOMAIN", "title")
if not title:
cf.set("DOMAIN", "title", forms.ask_domain_title(False))
write = True
global date title = cf_set_value("DOMAIN", "title", "title")
date = cf.get("DOMAIN", "date") date = cf_set_value("DOMAIN", "date", "date")
if not date: about = cf_set_value("DOMAIN", "about", "about")
cf.set("DOMAIN", "date", forms.ask_domain_date(False)) mail = cf_set_value("DOMAIN", "mail", "mail")
write = True tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
global about
about = cf.get("DOMAIN", "about")
if not about:
cf.set("DOMAIN", "about", forms.ask_domain_about(False))
write = True
global mail
mail = cf.get("DOMAIN", "mail")
if not mail:
cf.set("DOMAIN", "mail", forms.ask_domain_mail(False))
write = True
global tags
tags = cf.get("DOMAIN", "tags")
if not tags:
cf.set("DOMAIN", "tags", forms.ask_domain_tags(False))
write = True
global license, license_url
license = cf.get("DOMAIN", "license")
if not license: if not license:
cf.set("DOMAIN", "license", "gfdl-1.3") license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
write = True license_url = cf_set_value("DOMAIN", "lincese_url",
license_url = cf.get("DOMAIN", "license_url") "https://www.gnu.org/licenses/fdl-1.3.txt")
if license == "gfdl-1.3" and \ elif not license == "gfdl-1.3":
not license_url == "https://www.gnu.org/licenses/fdl-1.3.txt": license_url = cf_set_value("DOMAIN", "lincese_url","")
cf.set("DOMAIN", "license_url", "https://www.gnu.org/licenses/fdl-1.3.txt")
write = True
# Optional # Optional
global legals_url, terms_url, statuses_url global legals_url, terms_url, statuses_url
legals_url = cf.get("DOMAIN", "legals_url") legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf.get("DOMAIN", "terms_url") terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf.get("DOMAIN", "statuses_url") statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# [SERVER]
# ========
global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server")
if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www)
# [WIP_DIRS]
# ==========
global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files)
# [WWW_DIRS]
# ==========
global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files)
# [WEBSITE] # [WEBSITE]
# ========= # =========
global www_url global www_url, www_url, lang, css, sep, article_code, static
www_url = cf.get("WEBSITE", "www_url") www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url: if not www_url:
www_url = "https://%s/"%name www_url = cf_set_value("WEBSITE", "www_url", create_www_url())
cf.set("WEBSITE", "www_url", www_url)
debug.out(204, "[WEBSITE] www_url", www_url, False, 0, False)
write = True
global wip_url www_url = cf_set_value("WEBSITE", "www_url", "")
wip_url = cf.get("WEBSITE", "wip_url") if not www_url:
if not wip_url: www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
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_set_value("WEBSITE", "lang", "")
lang = cf.get("WEBSITE", "lang")
if not lang: if not lang:
cf.set("WEBSITE", "lang", forms.ask_domain_lang(False)) lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
write = True
elif not langs.translation_exists("website", lang, False): elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang() lang = langs.get_sys_lang()
write = True
langs.load_website_lang() langs.load_website_lang()
global css css = cf_set_value("WEBSITE", "css", "")
css = cf.get("WEBSITE", "css")
if not css: if not css:
cf.set("WEBSITE", "css", "tyto") css = cf_set_value("WEBSITE", "css", "tyto")
write = True
sep = cf_set_value("WEBSITE", "separator", "")
global sep if not sep or len(sep) > 2:
sep = cf.get("WEBSITE", "separator") sep = cf_set_value("WEBSITE", "separator", "|")
if not sep or len(sep) > 2:
cf.set("WEBSITE", "separator", "|") try: article_code = cf.getboolean("WEBSITE", "article_code")
write = True except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
global article_code, static
try: cf.getboolean("WEBSITE", "article_code")
except: cf.set("WEBSITE", "article_code", "yes") ; write = True
try: cf.getboolean("WEBSITE", "static")
except: cf.set("WEBSITE", "static", "no") ; write = True
# [WEBSITE_MODULES] # [WEBSITE_MODULES]
# ================= # =================
global navbar global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: cf.getboolean("WEBSITE_MODULES", "navbar") try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: cf.set("WEBSITE_MODULES", "navbar", "yes") ; write = True except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
global sidebar_title sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
sidebar_title = cf.get("WEBSITE_MODULES", "sidebar_title")
if not sidebar_title: if not sidebar_title:
cf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title) sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
write = True langs.site.sidebar_title)
global sidebar_items sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
sidebar_items = cf.get("WEBSITE_MODULES", "sidebar_items") if not sidebar_items or not sidebar_items.isdigit():
if not sidebar_items.isdigit(): sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
cf.set("WEBSITE_MODULES", "sidebar_items", "0")
write = True
try: cf.getboolean("WEBSITE_MODULES", "sitemaps") rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
except: cf.set("WEBSITE_MODULES", "sitemaps", "yes") ; write = True if not rss_items or not rss_items.isdigit():
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
global rss_items
rss_items = cf.get("WEBSITE_MODULES", "rss_items")
if not rss_items.isdigit():
cf.set("WEBSITE_MODULES", "rss_items", "0")
write = True
# TEMPLATE_FILES # TEMPLATE_FILENAMES
# ============== # ==================
favicon = cf.get("TEMPLATE_FILENAMES", "favicon") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon: if not favicon:
favicon = "favicon.png" favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
cf.set("TEMPLATE_FILENAMES", "favicon", favicon)
write = True
usr_favicon = os.path.join(cf_usr_tpl, favicon)
if cf.get("USER_TEMPLATE_FILES", "favicon") != usr_favicon:
cf.set("USER_TEMPLATE_FILES", "favicon", usr_favicon)
write = True
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
logo = cf.get("TEMPLATE_FILENAMES", "logo")
if not logo: if not logo:
logo = "logo.png" logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
cf.set("TEMPLATE_FILENAMES", "logo", logo)
write = True
usr_logo = os.path.join(cf_usr_tpl, logo)
if cf.get("USER_TEMPLATE_FILES", "logo") != usr_logo:
cf.set("USER_TEMPLATE_FILES", "logo", usr_logo)
write = True
styles = cf.get("TEMPLATE_FILENAMES", "styles") styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles: if not styles:
styles = "styles.css" styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
cf.set("TEMPLATE_FILENAMES", "styles", styles)
write = True
usr_styles = os.path.join(cf_usr_tpl, styles)
if cf.get("USER_TEMPLATE_FILES", "styles") != usr_styles:
cf.set("USER_TEMPLATE_FILES", "styles", usr_styles)
write = True
rss = cf.get("TEMPLATE_FILENAMES", "rss") rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss: if not rss:
rss = "rss.xml" rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
cf.set("TEMPLATE_FILENAMES", "rss", rss)
write = True
stats = cf.get("TEMPLATE_FILENAMES", "stats") stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats: if not stats:
stats = "tyto_stats.ini" stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
cf.set("TEMPLATE_FILENAMES", "stats", stats)
write = True
# [USER_DIRS] # [USER_DIRS]
# =========== # ===========
if cf.get("USER_DIRS", "root") != cf_dir: cf_set_value("USER_DIRS", "root", wrk_dir)
cf.set("USER_DIRS", "root", cf_dir) cf_set_value("USER_DIRS", "articles", wrk_articles)
write = True cf_set_value("USER_DIRS", "images", wrk_images)
if cf.get("USER_DIRS", "articles") != cf_usr_articles: cf_set_value("USER_DIRS", "files", wrk_files)
cf.set("USER_DIRS", "articles", cf_usr_articles) cf_set_value("USER_DIRS", "template", wrk_tpl)
write = True cf_set_value("USER_DIRS", "modules", wrk_mods)
if cf.get("USER_DIRS", "images") != cf_usr_images: cf_set_value("USER_DIRS", "database", wrk_db)
cf.set("USER_DIRS", "images", cf_usr_images)
write = True
if cf.get("USER_DIRS", "files") != cf_usr_files:
cf.set("USER_DIRS", "files", cf_usr_files)
write = True
if cf.get("USER_DIRS", "template") != cf_usr_tpl:
cf.set("USER_DIRS", "template", cf_usr_tpl)
write = True
if cf.get("USER_DIRS", "modules") != cf_usr_mods:
cf.set("USER_DIRS", "modules", cf_usr_mods)
write = True
if cf.get("USER_DIRS", "database") != cf_usr_db:
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 # [USER_TEMPLATE_FILES]
usr_navbar = os.path.join(cf_usr_mods, "tyto_navbar.raw") # =====================
if cf.get("USER_MODULES_FILES", "navbar") != usr_navbar: global wrk_favicon, wrk_logo, wri_styles
cf.set("USER_MODULES_FILES", "navbar", usr_navbar) wrk_favicon = os.path.join(wrk_tpl, favicon)
debug.out(204, "[USER_MODULES_FILES] navbar", usr_navbar, False, 0, False) cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
write = True
global usr_sidebar wrk_logo = os.path.join(wrk_tpl, logo)
usr_sidebar = os.path.join(cf_usr_mods, "tyto_sidebar.raw") cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
if cf.get("USER_MODULES_FILES", "sidebar") != usr_sidebar:
cf.set("USER_MODULES_FILES", "sidebar", usr_sidebar) wrk_styles = os.path.join(wrk_tpl, styles)
debug.out(204, "[USER_MODULES_FILES] sidebar", usr_sidebar, False, 0, False) cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
write = True
# [USER_MODULES_FILES]
# ====================
global wri_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
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_FILES]
# =========== # ===========
wip_favicon = os.path.join(srv_wip_tpl, favicon) global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
if cf.get("WIP_FILES", "favicon") != wip_favicon: wip_favicon = os.path.join(wip_tpl, favicon)
cf.set("WIP_FILES", "favicon", wip_favicon) cf_set_value("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_logo = os.path.join(wip_tpl, logo)
wip_metas = os.path.join(srv_wip_tpl, "metas.html") cf_set_value("WIP_FILES", "logo", wip_logo)
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_styles = os.path.join(wip_tpl, styles)
wip_navbar = os.path.join(srv_wip_tpl, "navbar.html") cf_set_value("WIP_FILES", "styles", wip_styles)
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_rss = os.path.join(wip_tpl, rss)
wip_sidebar = os.path.join(srv_wip_tpl, "sidebar.html") cf_set_value("WIP_FILES", "rss", wip_rss)
if cf.get("WIP_FILES", "sidebar") != wip_sidebar:
cf.set("WIP_FILES", "sidebar", wip_sidebar) wip_stats = os.path.join(wip_tpl, stats)
debug.out(204, "[WIP_FILES] sidebar", wip_sidebar, False, 0, False) cf_set_value("WIP_FILES", "stats", wip_stats)
write = True
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer)
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_FILES]
# =========== # ===========
www_favicon = os.path.join(srv_www_tpl, favicon) global www_favicon, www_logo, www_styles, www_rss, www_stats
if cf.get("WWW_FILES", "favicon") != www_favicon: www_favicon = os.path.join(www_tpl, favicon)
cf.set("WWW_FILES", "favicon", www_favicon) cf_set_value("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_logo = os.path.join(www_tpl, logo)
www_header = os.path.join(srv_www_tpl, "header.html") cf_set_value("WWW_FILES", "logo", www_logo)
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_styles = os.path.join(www_tpl, styles)
www_navbar = os.path.join(srv_www_tpl, "navbar.html") cf_set_value("WWW_FILES", "styles", www_styles)
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_rss = os.path.join(www_tpl, rss)
www_sidebar = os.path.join(srv_www_tpl, "sidebar.html") cf_set_value("WWW_FILES", "rss", www_rss)
if cf.get("WWW_FILES", "sidebar") != www_sidebar:
cf.set("WWW_FILES", "sidebar", www_sidebar) www_stats = os.path.join(www_tpl, stats)
debug.out(204, "[WWW_FILES] sidebar", www_sidebar, False, 0, False) cf_set_value("WWW_FILES", "stats", www_stats)
write = True
global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer)
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] # [TYTO]
# ====== # ======
if cf.get("TYTO", "domain_hash") != cf_id: cf_set_value("TYTO", "domain_hash", cf_id)
cf.set("TYTO", "domain_hash", cf_id) cf_set_value("TYTO", "domain_conf", cf_uri)
write = True cf_set_value("TYTO", "domain_user", ult_cf_uri)
if cf.get("TYTO", "domain_conf") != cf_uri:
cf.set("TYTO", "domain_conf", cf_uri)
write = True # ================================= #
if cf.get("TYTO", "domain_user") != ult_cf_uri: # Write Configuration file #
cf.set("TYTO", "domain_user", ult_cf_uri) # Only if needed or when new domain #
write = True # --------------------------------- #
if new_val or write:
# Write Configuration file
# Only if needed or when new domain
if write:
with open(cf_uri, "w") as f: with open(cf_uri, "w") as f:
cf.write(f) cf.write(f)
debug.out(204, "True", cf_uri, True, 0, False)
#=============================================# #=============================================#
@ -654,8 +511,8 @@ def cf_update_values(write):
ult_cf.set("DOMAIN", "hash", cf_hash_c) ult_cf.set("DOMAIN", "hash", cf_hash_c)
ult_write = True ult_write = True
if ult_cf.get("DOMAIN", "root") != cf_dir: if ult_cf.get("DOMAIN", "root") != wrk_dir:
ult_cf.set("DOMAIN", "root", cf_dir) ult_cf.set("DOMAIN", "root", wrk_dir)
ult_write = True ult_write = True
if ult_cf.get("DOMAIN", "conf") != cf_uri: if ult_cf.get("DOMAIN", "conf") != cf_uri:
@ -670,19 +527,20 @@ def cf_update_values(write):
with open(ult_cf_uri, "w") as f: with open(ult_cf_uri, "w") as f:
ult_cf.write(f) ult_cf.write(f)
# Update User local Domains List File # Update User local Domains List File
#------------------------------------ #------------------------------------
ult_dlf_load() ult_dlf_load()
dlf_write = False dlf_write = False
try: try:
dlf_line = ult_dlf.get("DOMAINS", name) dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != cf_dir: if dlf_line != wrk_dir:
dlf_write = True dlf_write = True
except: except:
dlf_write = True dlf_write = True
if dlf_write: if dlf_write:
ult_dlf.set("DOMAINS", name, cf_dir) ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f: with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f) ult_dlf.write(f)
@ -705,7 +563,7 @@ def cf_valid():
cf_update_values(False) cf_update_values(False)
active = is_active() active = is_active()
active and create_work_dirs() active and create_wrk_dirs()
return active return active
@ -736,7 +594,7 @@ def is_active():
#===================================# #===================================#
# Create user domain work directory # # Create user domain work directory #
#-----------------------------------# #-----------------------------------#
def create_work_dirs(): def create_wrk_dirs():
cf_load() cf_load()
for key, directory in cf.items("USER_DIRS"): for key, directory in cf.items("USER_DIRS"):
@ -762,20 +620,20 @@ except:
# cf: Domain Configuration File # # cf: Domain Configuration File #
#------------------------------------------# #------------------------------------------#
# Domain Configuration directory # Domain Configuration directory
cf_dir = user_dir.rsplit("articles/")[0] wrk_dir = user_dir.rsplit("articles/")[0]
cf_usr_articles = os.path.join(cf_dir, "articles/") wrk_articles = os.path.join(wrk_dir, "articles/")
cf_usr_tpl = os.path.join(cf_dir, "template/") wrk_tpl = os.path.join(wrk_dir, "template/")
cf_usr_images = os.path.join(cf_dir, "images/") wrk_images = os.path.join(wrk_dir, "images/")
cf_usr_files = os.path.join(cf_dir, "files/") wrk_files = os.path.join(wrk_dir, "files/")
cf_usr_mods = os.path.join(cf_dir, "modules/") wrk_mods = os.path.join(wrk_dir, "modules/")
cf_usr_db = os.path.join(cf_dir, ".db/") wrk_db = os.path.join(wrk_dir, ".db/")
# Domain name from current basename directory # Domain name from current basename directory
# Exit if not format at least "abc.tld" # Exit if not format at least "abc.tld"
name = os.path.basename(os.path.dirname(cf_dir)) name = os.path.basename(os.path.dirname(wrk_dir))
cf_name = "tyto_domain.ini" cf_name = "tyto_domain.ini"
cf_uri = os.path.join(cf_dir, cf_name) cf_uri = os.path.join(wrk_dir, cf_name)
cf_id = tools.get_filesum(cf_uri, False) # ID from URI cf_id = tools.get_filesum(cf_uri, False) # ID from URI
# Tyto directory in home local user files # Tyto directory in home local user files

View File

@ -262,5 +262,5 @@ def ask_domain_server(update):
return return
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer) if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return srv else: return answer

View File

@ -44,8 +44,7 @@ import domain, debug, tools, tyto
#--------------------------------------------# #--------------------------------------------#
def is_article(target): def is_article(target):
# User MUST be in articles/ # User MUST be in articles/
domain.cf_load() (os.getcwd() + "/").startswith(domain.wrk_articles) or \
(os.getcwd() + "/").startswith(domain.cf_usr_articles) or \
debug.out(2, "-> articles/", domain.cf_usr_articles, True, 2, True) debug.out(2, "-> articles/", domain.cf_usr_articles, True, 2, True)
# Target URI most be from legacy directory or not begins with # Target URI most be from legacy directory or not begins with
@ -54,8 +53,7 @@ def is_article(target):
# Article exists # Article exists
global uri global uri
uri = os.path.join(domain.wrk_articles, target)
uri = os.path.join(domain.cf_usr_articles, target)
os.path.exists(uri) or debug.out(5, "False", uri, True, 2, True) os.path.exists(uri) or debug.out(5, "False", uri, True, 2, True)
# Article is a Tyto format and not empty (exit on errors) # Article is a Tyto format and not empty (exit on errors)
@ -68,13 +66,10 @@ def is_article(target):
uri_id = tools.get_filesum(uri, False) uri_id = tools.get_filesum(uri, False)
# Set post configuration file database # Set post configuration file database
cf_uri = os.path.join(domain.cf_usr_db, uri_id + ".ini") cf_uri = os.path.join(domain.wrk_db, uri_id + ".ini")
# Load Database # Load Database
db = cf_load() # True or False db = cf_load() # True or False
if db: cf_valid()
else: tools.create_file(cf_uri, tyto.ini_article)
@ -87,7 +82,6 @@ def cf_load():
return False return False
global cf global cf
cf = configparser.ConfigParser() cf = configparser.ConfigParser()
cf.read(cf_uri) cf.read(cf_uri)

View File

@ -23,6 +23,8 @@
# File: /var/lib/tyto/program/tyto.py # File: /var/lib/tyto/program/tyto.py
#---------------------------------------------------------------------- #----------------------------------------------------------------------
import forms
# #
# Arguments in command line # # Arguments in command line #
# #
@ -53,12 +55,29 @@ web_url = "https://tyto.echolib.re"
git_url = "https://git.a-lec.org/echolib/tyto-litterateur" git_url = "https://git.a-lec.org/echolib/tyto-litterateur"
#=============================================================#
# Domain questions #
# Used by domain.cf_set_value() #
# to check for configuration domain in [SECTION]: key = value #
# Ask user if no value and update configuration file #
#-------------------------------------------------------------#
keys_4q = ("server", "title", "date", "about", "mail", "tags")
keys_questions = {
"server" : forms.ask_domain_server,
"title" : forms.ask_domain_title,
"date" : forms.ask_domain_date,
"about" : forms.ask_domain_about,
"mail" : forms.ask_domain_mail,
"tags" : forms.ask_domain_tags
}
#===========================# #===========================#
# Templates #================================================== # Templates #==================================================
#===========================# #===========================#
#===========================# #=============================#
# Domain configuration file # # Domain configuration file #
#---------------------------# # Create file with new domain #
#-----------------------------#
ini_domain = """[DOMAIN] ini_domain = """[DOMAIN]
activated = no activated = no
name = %s name = %s
@ -86,8 +105,8 @@ static = no
navbar = yes navbar = yes
sidebar_title = sidebar_title =
sidebar_items = 6 sidebar_items = 6
sitemaps = yes
rss_items = 100 rss_items = 100
sitemaps = yes
[TEMPLATE_FILENAMES] [TEMPLATE_FILENAMES]
favicon = favicon.png favicon = favicon.png