[1.9.21] - 3 lines tags supported, cleaner code, see changelog

This commit is contained in:
Cyrille L 2023-10-08 11:28:16 +02:00
parent afa2546abb
commit ff4ecf7d6f
29 changed files with 1502 additions and 1386 deletions

View File

@ -9,6 +9,16 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.21]
- new indentation (3 spaces)
- added 'raw:' marker
- (for wip process):
- - added html titles to post database
- - added html comments to post database (default: ';; a comment')
- - added val3 tag as html comment to content, and convert content to base64
- - - added values to post database
- cleaner code
## [1.9.20]
- working on 'check' process
- - updated 'logo:' process

View File

@ -9,6 +9,11 @@ tyto
## ToDo next (working on)
- 'check' action processes
- create template post database
- - support for words tags (bolds...)
- - support lists, anchors
- - thinking about creating an auto top article menu from titles
- - stats for article words
- manage template post database
- - check valid database
- Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Version: 1.9.20
# Updated: 2023-10-06 1696580458
# Version: 1.9.21
# Updated: 2023-10-08 1696756865
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
@ -48,27 +48,27 @@ import os
# Error message #
#---------------#
def error_message(path):
print("! Installation error, unused:", path)
sys.exit(1)
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)
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)
@ -77,8 +77,8 @@ def check_install():
#======#
import sys
if not __name__ == "__main__":
print("! Error: '%s' not '%s'"%(__name__, "__main__"))
sys.exit(1)
print("! Error: '%s' not '%s'"%(__name__, "__main__"))
sys.exit(1)
# files list in /program/
prog_files = {

View File

@ -40,59 +40,59 @@ import langs, tyto, debug, help, new, check, userset, show
# Action Arguments #
#------------------#
def get_action():
global action
try: action = sys.argv[1]
except: action = ""
global action
try: action = sys.argv[1]
except: action = ""
#==================#
# Target arguments #
#------------------#
def get_target():
global target, targets
try: target = sys.argv[2]
except: target = ""
targets = False
if target == "all": targets = True
global target, targets
try: target = sys.argv[2]
except: target = ""
targets = False
if target == "all": targets = True
#================================#
# Searching options in arguments #
#--------------------------------#
def get_options():
global dlogs, force, erron
dlogs = force = erron = False
for arg in range(1, len(sys.argv)):
dlogs = sys.argv[arg] in tyto.debug_options
force = sys.argv[arg] in tyto.force_options
erron = sys.argv[arg] in tyto.debug_errors
global dlogs, force, erron
dlogs = force = erron = False
for arg in range(1, len(sys.argv)):
dlogs = sys.argv[arg] in tyto.debug_options
force = sys.argv[arg] in tyto.force_options
erron = sys.argv[arg] in tyto.debug_errors
#===========#
# Show logs #
#-----------#
def valid_action():
global action
if not action in tyto.actions:
debug.out(1, "[action]", action, False, 2, False)
action = "help"
global action
if not action in tyto.actions:
debug.out(1, "[action]", action, False, 2, False)
action = "help"
#==============#
# Start action #
#--------------#
def start_process():
# Set Lang logs
langs.load_logs_lang()
get_options()
get_action()
get_target()
valid_action()
do = {
# Set Lang logs
langs.load_logs_lang()
get_options()
get_action()
get_target()
valid_action()
do = {
"help" : help.show,
"check" : check.manage,
"new" : new.manage,
@ -101,6 +101,6 @@ def start_process():
"stop" : userset.manage,
"show" : show.manage,
}
do[action](action, target)
do[action](action, target)

File diff suppressed because it is too large Load Diff

View File

@ -47,32 +47,32 @@ import langs, args
# stop to sys exit with nbr if True #
#-----------------------------------#
def out(nbr, var, val, show, color, stop):
args.get_options()
if not show:
# Show only warn and error logs
show = args.dlogs or args.erron and color > 0
if not show:
return nbr
# COlors
CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink
# Color of "*"
SC = CL # Default gray
if color == 0: SC = CG
elif color == 1: SC = CY
elif color == 2: SC = CR
# Messages for logs
messages = \
args.get_options()
if not show:
# Show only warn and error logs
show = args.dlogs or args.erron and color > 0
if not show:
return nbr
# COlors
CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink
# Color of "*"
SC = CL # Default gray
if color == 0: SC = CG
elif color == 1: SC = CY
elif color == 2: SC = CR
# Messages for logs
messages = \
{
# ERRORS (1-100)
1 : langs.logs.err_arg,
@ -115,23 +115,22 @@ def out(nbr, var, val, show, color, stop):
209 : langs.logs.domain_on,
255 : langs.logs.later,
}
# Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
# Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
SC, CS,
CL, messages[nbr], CS,
CB, var, CS,
CC, val, CS
)
)
# Exit if stop = True
if stop:
if nbr >= 200:
nbr = 0
sys.exit(nbr)
return nbr
)
# Exit if stop = True
if stop:
if nbr >= 200: nbr = 0
sys.exit(nbr)
return nbr

View File

@ -40,8 +40,8 @@ import debug, tyto, tools, forms, langs
# Exit if directory name is compatible with a domain name #
#---------------------------------------------------------#
def compatible_name():
if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True)
if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True)
#================================#
@ -49,13 +49,13 @@ def compatible_name():
# As needed, exit if not exists #
#--------------------------------#
def cf_load():
global cf
cf_exists() or sys.exit(100)
cf = False
cf = configparser.ConfigParser()
cf.read(cf_uri)
global cf
cf_exists() or sys.exit(100)
cf = False
cf = configparser.ConfigParser()
cf.read(cf_uri)
#=====================================#
@ -63,29 +63,29 @@ def cf_load():
# As needed, exit if not exists #
#-------------------------------------#
def ult_cf_load():
global ult_cf
ult_cf = False
if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri)
global ult_cf
ult_cf = False
if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri)
#===================================#
# Load User local Domains List File #
#-----------------------------------#
def ult_dlf_load():
global ult_dlf
# User Domains list file
ult_dlf = False
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri)
global ult_dlf
# User Domains list file
ult_dlf = False
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri)
#===========================================#
@ -94,36 +94,36 @@ def ult_dlf_load():
# return True or False
#-------------------------------------------#
def cf_exists():
global shown_ok, shown_no
if os.path.exists(cf_uri):
try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True
return True
else:
try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True
compatible_name()
return False
global shown_ok, shown_no
if os.path.exists(cf_uri):
try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True
return True
else:
try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True
compatible_name()
return False
#=========================================#
# Guess and return wip_url from name #
#-----------------------------------------#
def create_wip_url():
www_url = "https://www-wip.%s/"
len_cn = name.count(".")
# Domain name Format: a.b
if len_cn == 1:
return www_url%name
# Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:]
return www_url%tld
www_url = "https://www-wip.%s/"
len_cn = name.count(".")
# Domain name Format: a.b
if len_cn == 1:
return www_url%name
# Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:]
return www_url%tld
#==========================================#
@ -134,41 +134,41 @@ def create_wip_url():
# If not User domains list file, create it #
#------------------------------------------#
def cf_create():
compatible_name()
# This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log
if cf_exists():
debug.out(102, "!?", cf_uri, True, 1, False)
compatible_name()
# This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log
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(name)
# Create default files
tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# User Domains list file
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# Ask user for domain settings
cf_load()
forms.ask_domain_title(True)
forms.ask_domain_date(True)
forms.ask_domain_about(True)
forms.ask_domain_mail(True)
forms.ask_domain_tags(True)
# Set default lang, from config file or system lang
forms.ask_domain_lang(True)
# Set server directory
forms.ask_domain_server(True)
# Update Domain Configuration file
cf_update_values(True)
# Ask User to create new domain. Will exit if not ok.
forms.ask_domain_shortname(name)
# Create default files
tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# User Domains list file
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# Ask user for domain settings
cf_load()
forms.ask_domain_title(True)
forms.ask_domain_date(True)
forms.ask_domain_about(True)
forms.ask_domain_mail(True)
forms.ask_domain_tags(True)
# Set default lang, from config file or system lang
forms.ask_domain_lang(True)
# Set server directory
forms.ask_domain_server(True)
# Update Domain Configuration file
cf_update_values(True)
@ -179,35 +179,35 @@ def cf_create():
# 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
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
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
cf.set(section, key, default)
debug.out(204, "[%s] %s"%(section, key), default, False, 0, False)
return default
#===========================================#
@ -216,334 +216,334 @@ def cf_set_value(section, key, default):
# Ensure to set correct values #
#-------------------------------------------#
def cf_update_values(write):
# Load Domain Configuration file
cf_load()
# [DOMAIN]
# ========
global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no")
cf_set_value("DOMAIN", "name", name)
title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","")
# Optional
global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# Load Domain Configuration file
cf_load()
# [DOMAIN]
# ========
global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no")
cf_set_value("DOMAIN", "name", name)
title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","")
# Optional
global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_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]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "")
if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang()
langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "")
if not css:
css = cf_set_value("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
# [WEBSITE_MODULES]
# =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
# [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]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "")
if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang()
langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "")
if not css:
css = cf_set_value("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
# [WEBSITE_MODULES]
# =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
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")
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS]
# ===========
cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES]
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES]
# ====================
global wrk_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)
# [WIP_FILES]
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats)
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)
# [WWW_FILES]
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats)
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)
# [TYTO]
# ======
cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri)
# ================================= #
# Write Configuration file #
# Only if needed or when new domain #
# --------------------------------- #
if new_val or write:
with open(cf_uri, "w") as f:
cf.write(f)
#=============================================#
# Update User local domain configuration file #
#---------------------------------------------#
ult_write = False
ult_cf_load()
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") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_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
if ult_write:
with open(ult_cf_uri, "w") as f:
ult_cf.write(f)
# Update User local Domains List File
#------------------------------------
ult_dlf_load()
dlf_write = False
try:
dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != wrk_dir:
dlf_write = True
except:
dlf_write = True
if dlf_write:
ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
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")
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS]
# ===========
cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES]
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES]
# ====================
global wrk_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)
# [WIP_FILES]
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats)
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)
# [WWW_FILES]
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats)
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)
# [TYTO]
# ======
cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri)
# ================================= #
# Write Configuration file #
# Only if needed or when new domain #
# --------------------------------- #
if new_val or write:
with open(cf_uri, "w") as f:
cf.write(f)
#=============================================#
# Update User local domain configuration file #
#---------------------------------------------#
ult_write = False
ult_cf_load()
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") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_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
if ult_write:
with open(ult_cf_uri, "w") as f:
ult_cf.write(f)
# Update User local Domains List File
#------------------------------------
ult_dlf_load()
dlf_write = False
try:
dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != wrk_dir:
dlf_write = True
except:
dlf_write = True
if dlf_write:
ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f)
#========================================#
@ -552,19 +552,18 @@ def cf_update_values(write):
# if activated, check/create wrk dirs #
#----------------------------------------#
def userset_status(action):
do = {
do = {
"start" : "yes",
"stop" : "no"
}
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False)
ready()
if action == "start":
status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False)
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False)
ready()
if action == "start":
status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False)
#========================================#
@ -574,12 +573,12 @@ def userset_status(action):
# 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)
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)
#======#=======================================================================
@ -590,10 +589,10 @@ def ready():
# Exit Tyto if in black hole... #
#-----------------------------------#
try:
user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~')
user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~')
except:
debug.out(2, "PWD", "?", True, 2, True)
debug.out(2, "PWD", "?", True, 2, True)
#======#

View File

@ -43,7 +43,7 @@ import debug, domain, langs, tools
# user interrupts... #
#--------------------#
def maybe_later(expected, answer):
debug.out(255, expected, answer, True, 0, True)
debug.out(255, expected, answer, True, 0, True)
#=========================#
@ -51,29 +51,29 @@ def maybe_later(expected, answer):
# yes_only : True / False #
#-------------------------#
def ask(q, yes_only, default):
expected = ""
if yes_only:
expected = langs.logs.ok
try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
# return default answer if exists
if not answer:
if default:
return default
expected = ""
if yes_only:
expected = langs.logs.ok
try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
# return default answer if exists
if not answer:
if default:
return default
maybe_later(expected, "?")
# Answer is a Y/N process
if yes_only:
for ok in langs.logs.ok:
if answer.lower() == ok.lower():
return True
maybe_later(expected, "?")
# Answer is a Y/N process
if yes_only:
for ok in langs.logs.ok:
if answer.lower() == ok.lower():
return True
maybe_later(expected, answer)
return answer
maybe_later(expected, answer)
return answer
#====================================#
@ -81,11 +81,11 @@ def ask(q, yes_only, default):
# return value[0:12] #
#------------------------------------#
def shorter(value):
if len(value) > 12:
return '%s...'%(value[0:12])
# Or legacy
return value
if len(value) > 12:
return '%s...'%(value[0:12])
# Or legacy
return value
#=========================#
@ -93,8 +93,8 @@ def shorter(value):
# from directory basename #
# ------------------------#
def ask_domain_shortname(config_name):
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False)
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False)
#=======================#
@ -104,14 +104,14 @@ def ask_domain_shortname(config_name):
# - False: return value #
#-----------------------#
def ask_domain_title(update):
try: title = domain.cf.get("DOMAIN", "title")
except: title = ""
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer
try: title = domain.cf.get("DOMAIN", "title")
except: title = ""
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer
#===========================#
@ -122,24 +122,24 @@ def ask_domain_title(update):
# - False: return value #
#---------------------------#
def ask_domain_date(update):
try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]"
example = date
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date)
# Check date format (not valid date)
try:
parse(answer)
except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update)
return
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer
try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]"
example = date
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date)
# Check date format (not valid date)
try:
parse(answer)
except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update)
return
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer
#========================#
@ -149,14 +149,14 @@ def ask_domain_date(update):
# - False: return value #
#------------------------#
def ask_domain_about(update):
try: about = domain.cf.get("DOMAIN", "about")
except: about = ""
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer
try: about = domain.cf.get("DOMAIN", "about")
except: about = ""
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer
#=======================#
@ -166,14 +166,14 @@ def ask_domain_about(update):
# - False: return value #
#-----------------------#
def ask_domain_mail(update):
try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = ""
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer
try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = ""
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer
#===============================================#
@ -183,22 +183,22 @@ def ask_domain_mail(update):
# - False: return value #
#-----------------------------------------------#
def ask_domain_tags(update):
try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = ""
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags)
# Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",")
answer = ""
for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip()
if i != len(tuple_tags) - 1:
answer = answer + ","
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer
try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = ""
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags)
# Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",")
answer = ""
for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip()
if i != len(tuple_tags) - 1:
answer = answer + ","
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer
#===================================#
@ -206,52 +206,52 @@ def ask_domain_tags(update):
# default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO
#-----------------------------------#
def ask_domain_lang(update):
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = ""
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower()
# Lang Format is 2 character
if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False)
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):
lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = ""
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower()
# Lang Format is 2 character
if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False)
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):
lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang
#===================================#
# Get domain server root #
#-----------------------------------#
def ask_domain_server(update):
try:
srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False):
try:
srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False):
srv = ""
except:
srv = ""
except:
srv = ""
if srv and not tools.dir_exists(srv, False):
srv = ""
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
answer = ask(q, False, srv)
# Check if directory exists
if not tools.dir_exists(answer, False):
answer = ""
ask_domain_server(update)
return
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer
if srv and not tools.dir_exists(srv, False):
srv = ""
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
answer = ask(q, False, srv)
# Check if directory exists
if not tools.dir_exists(answer, False):
answer = ""
ask_domain_server(update)
return
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer

View File

@ -40,4 +40,4 @@ import langs, debug
# Help Contents is in translations/logs_XX #
#------------------------------------------#
def show(action, target):
print(langs.logs.help_contents)
print(langs.logs.help_contents)

View File

@ -49,17 +49,20 @@ trfs = "/var/lib/tyto/translations/"
# return True or False #
#----------------------------------#
def translation_exists(module, lang, out):
global tr_file
modules = ("logs", "website")
if not module in modules: return # in case of internal typo error
tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file):
debug.out(5, lang, tr_file, True, 2, False)
return False
return True
global tr_file
modules = ("logs", "website")
# in case of internal typo error
if not module in modules:
print("! langs: internal error: 'logs', 'website'")
sys.exit(254)
tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file):
debug.out(5, lang, tr_file, True, 2, False)
return False
return True
#=============================================================================#
@ -70,33 +73,33 @@ def translation_exists(module, lang, out):
# Get system Lang to set logs #
#-----------------------------#
def get_sys_lang():
global lang, tr_logs_uri
tr_logs_uri = "%slogs_%s.py"
try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en"
if not translation_exists("logs", lang, False):
lang = "en"
tr_logs_uri = tr_logs_uri%(trfs, lang)
return lang
global lang, tr_logs_uri
tr_logs_uri = "%slogs_%s.py"
try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en"
if not translation_exists("logs", lang, False):
lang = "en"
tr_logs_uri = tr_logs_uri%(trfs, lang)
return lang
#===============================#
# Import logs lang file in logs #
#-------------------------------#
def load_logs_lang():
global logs, lang, set_logs
try:
set_logs
except:
logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True
global logs, lang, set_logs
try:
set_logs
except:
logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True
#=============================================================================#
@ -107,30 +110,31 @@ def load_logs_lang():
# Get website lang from cf to set site #
#---------------------------------------#
def get_website_lang():
global site_lang, tr_website_uri
tr_website_uri = "%swebsite_%s.py"
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"
tr_website_uri = tr_website_uri%(trfs, site_lang)
return site_lang
global site_lang, tr_website_uri
tr_website_uri = "%swebsite_%s.py"
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"
tr_website_uri = tr_website_uri%(trfs, site_lang)
return site_lang
#==================================#
# Import website lang file in site #
#----------------------------------#
def load_website_lang():
global site, site_lang, set_site
site = __import__("website_%s"%get_website_lang())
try:
set_site
except:
debug.out(208, site_lang, tr_website_uri, False, 0, False)
set_site = True
global site, site_lang, set_site
site = __import__("website_%s"%get_website_lang())
try:
set_site
except:
debug.out(208, site_lang, tr_website_uri, False, 0, False)
set_site = True

View File

@ -40,11 +40,11 @@ import args, domain
# Specific to action "new" #
#------------------------------------#
def manage(action, target):
do = {
"domain" : create_domain,
}
do[target]()
do = {
"domain" : create_domain,
}
do[target]()
@ -54,8 +54,8 @@ def manage(action, target):
# or if user "force" option
#-----------------------------------#
def create_domain():
if not domain.cf_exists() or args.force:
domain.cf_create()
return
if not domain.cf_exists() or args.force:
domain.cf_create()
return

View File

@ -46,43 +46,43 @@ error = 0
# load database #
#--------------------------------------------#
def is_article(target):
# User MUST be in articles/
domain.user_dir.startswith(domain.wrk_articles) or \
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
# Target URI most be from legacy directory or not begins with
if target.startswith(tyto.notarget):
error = debug.out(20, "./, ../", target, True, 2, False)
return False
# Article exists
global uri
uri = os.path.join(domain.wrk_articles, target)
if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False)
return False
# Article is a Tyto format and not empty (exit on errors)
if not is_tyto_format():
return False
global uri_id, wrk_id, cf_uri, wrk_target
# Set post ID from...
uri_id = tools.get_filesum(uri, False) # ...URI
wrk_id = tools.get_filesum(uri, True) # ...CONTENTS
# Set post configuration file database
cf_uri = os.path.join(domain.wrk_db, uri_id + ".ini")
# Set target from articles/
wrk_target = uri.rsplit(domain.wrk_articles)[1]
# Load Database
global db
db = False
db = cf_load() # True or False
return True
# User MUST be in articles/
domain.user_dir.startswith(domain.wrk_articles) or \
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
# Target URI most be from legacy directory or not begins with
if target.startswith(tyto.notarget):
error = debug.out(20, "./, ../", target, True, 2, False)
return False
# Article exists
global uri
uri = os.path.join(domain.wrk_articles, target)
if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False)
return False
# Article is a Tyto format and not empty (exit on errors)
if not is_tyto_format():
return False
global uri_id, wrk_id, cf_uri, wrk_target
# Set post ID from...
uri_id = tools.get_filesum(uri, False) # ...URI
wrk_id = tools.get_filesum(uri, True) # ...CONTENTS
# Set post configuration file database
cf_uri = os.path.join(domain.wrk_db, uri_id + ".ini")
# Set target from articles/
wrk_target = uri.rsplit(domain.wrk_articles)[1]
# Load Database
global db
db = False
db = cf_load() # True or False
return True
#=========================================#
@ -90,33 +90,33 @@ def is_article(target):
# Return True or False #
#-----------------------------------------#
def is_tyto_format():
global head_contents, text_contents, contents
global head_lines, text_lines, lines
head_contents = text_contents = ""
with open(uri, "r") as contents:
contents = contents.read()
try:
head_contents = contents.rsplit(sep)[0]
text_contents = contents.rsplit(sep)[1]
except:
error = debug.out(21, sep, uri, True, 2, False)
global head_contents, text_contents, contents
global head_lines, text_lines, lines
head_contents = text_contents = ""
with open(uri, "r") as contents:
contents = contents.read()
try:
head_contents = contents.rsplit(sep)[0]
text_contents = contents.rsplit(sep)[1]
except:
error = debug.out(21, sep, uri, True, 2, False)
return False
if not head_contents:
error = debug.out(22, "?", uri, True, 2, False)
return False
if not head_contents:
error = debug.out(22, "?", uri, True, 2, False)
return False
if not text_contents:
error = debug.out(23, "?", uri, True, 2, False)
return False
lines = len(contents.splitlines())
head_lines = len(head_contents.splitlines())
text_lines = len(text_contents.splitlines())
return True
if not text_contents:
error = debug.out(23, "?", uri, True, 2, False)
return False
lines = len(contents.splitlines())
head_lines = len(head_contents.splitlines())
text_lines = len(text_contents.splitlines())
return True
#=======================================#
@ -124,32 +124,58 @@ def is_tyto_format():
# return True, or False if unused (yet) #
#---------------------------------------#
def cf_load():
global cf
cf = False
if not os.path.exists(cf_uri):
tools.create_file(cf_uri, ini_template)
cf = configparser.ConfigParser()
cf.read(cf_uri)
return True
global cf
cf = False
os.path.exists(cf_uri) or tools.create_file(cf_uri, ini_template)
cf = configparser.ConfigParser()
cf.read(cf_uri)
return True
#====================================================#
# Check if post database configuration file is valid #
#----------------------------------------------------#
def cf_valid():
global chk_hash, wip_hash, www_hash
chk_hash = cf.get("CHECK", "hash")
wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash")
global chk_hash, wip_hash, www_hash
chk_hash = cf.get("CHECK", "hash")
wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash")
#======#
# MAIN #=======================================================================
#======#
# Statistics
# ==========
stats_tyto_head_coms = 0
stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_quotes = 0
stats_parags = 0
stats_links = 0
stats_images = 0
stats_files = 0
stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_codes = 0
stats_raws = 0
stats_total_files = 0
stats_text_links = 0
stats_text_files = 0
stats_text_images = 0
stats_text_abbrs = 0
stats_text_codes = 0
stats_text_raws = 0
# head_contents
#==============
@ -170,16 +196,26 @@ author = ("author:", False)
logo = ("logo:", False)
# Multiple lines (3)
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_marks = {
"link:" : "__",
"file:" : "--",
"image:" : "_image:",
"abbr:" : "::"
}
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_tags_marks = {
"link:" : "__",
"file:" : "--",
"image:" : "_image:",
"abbr:" : "::",
"raw:" : "_raw:",
"code:" : "_code:"
}
ml_tags_stats = {
"link:" : stats_links,
"file:" : stats_files,
"image:" : stats_images,
"abbr:" : stats_abbrs,
"raw:" : stats_raws,
"code:" : stats_codes,
}
# Markers with uri in value2
value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3])
value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3], ml_tags[4])
value2s_ext_uris = ("http", "ftp")
# text_contents
@ -194,41 +230,17 @@ raw_contents = ("bcodes", "quotes")
# Comments
text_comments = (";;", "<!--")
html_comment = { text_comments[0] : "<!-- %s -->" }
# Tyto Titles #1 = <h2>
tyto_titles = ("#1", "#2", "#3", "#4", "#5")
html_titles = {
"#1" : '<h2 class="title_2">%s</h62>',
"#2" : '<h3 class="title_3">%s</h3>',
"#3" : '<h4 class="title_4">%s</h4>',
"#4" : '<h5 class="title_5">%s</h5>',
"#5" : '<h6 class="title_6">%s</h6>',
"#1" : '<h2 class="%s">%s</h2>',
"#2" : '<h3 class="%s">%s</h3>',
"#3" : '<h4 class="%s">%s</h4>',
"#4" : '<h5 class="%s">%s</h5>',
"#5" : '<h6 class="%s">%s</h6>',
}
# Statistics
# ==========
stats_tyto_head_coms = 0
stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_quotes = 0
stats_parags = 0
stats_links = 0
stats_images = 0
stats_files = 0
stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_total_files = 0
stats_text_links = 0
stats_text_files = 0
stats_text_images = 0
stats_text_abbrs = 0
#=============================#
# articles configuration file #
@ -245,6 +257,10 @@ ini_template = """[DOMAIN]
[WWW]
[COMMENTS]
[TITLES]
[LINKS]
[FILES]
@ -264,5 +280,4 @@ ini_template = """[DOMAIN]
[STATS_HEADERS]
[STATS_TEXTS]
"""

View File

@ -41,25 +41,25 @@ import domain, debug
# Specific to action "show" #
#------------------------------------#
def manage(action, target):
do = {
"domains": all_domains,
}
do[target]()
do = {
"domains": all_domains,
}
do[target]()
#============================#
# List all registred domains #
#----------------------------#
def all_domains():
domain.ult_dlf_load()
try:
c = 0
for key, value in domain.ult_dlf.items("DOMAINS"):
if key: c += 1
print(": %s > %s"%(key,value))
print("|\n; total =",c)
except:
debug.out(104, "False", domain.ult_dlf_uri, True, 1, False)
domain.ult_dlf_load()
try:
c = 0
for key, value in domain.ult_dlf.items("DOMAINS"):
if key: c += 1
print(": %s > %s"%(key,value))
print("|\n; total =",c)
except:
debug.out(104, "False", domain.ult_dlf_uri, True, 1, False)

View File

@ -33,7 +33,7 @@
#--------------------------
from hashlib import blake2b
import sys, os, configparser, datetime, time
import sys, os, configparser, datetime, time, base64
import debug, domain
@ -41,17 +41,17 @@ import debug, domain
#
#
def exit(targets, error):
if targets: return
sys.exit(error)
if targets: return
sys.exit(error)
#==============================#
# Set and return date and time #
#------------------------------#
def nowdate():
now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S'))
now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S'))
#
@ -59,18 +59,18 @@ def nowdate():
# Return date (only year) for post database
#
def local_date(date):
date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0]
month = date.rsplit("-")[1]
day = date.rsplit("-")[2]
dates = {
"fr" : "%s/%s/%s"%(day, month, year),
"en" : date,
}
return dates[domain.lang]
date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0]
month = date.rsplit("-")[1]
day = date.rsplit("-")[2]
dates = {
"fr" : "%s/%s/%s"%(day, month, year),
"en" : date,
}
return dates[domain.lang]
#========================#
@ -79,12 +79,12 @@ def local_date(date):
# False = URI #
#------------------------#
def get_filesum(path, src):
file_sum = blake2b(digest_size=4)
if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode())
return file_sum.hexdigest()
file_sum = blake2b(digest_size=4)
if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode())
return file_sum.hexdigest()
#========================================#
@ -92,66 +92,102 @@ def get_filesum(path, src):
# Mainly used to check domain server dir #
#----------------------------------------#
def dir_exists(dir_path, out):
if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out)
return False
return True
if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out)
return False
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)
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 #
#----------------------------#
def create_file(file_path, contents):
up = bool(os.path.exists(file_path))
try:
with open(file_path, "w") as f:
f.write(contents)
except:
# Exit at error
debug.out(7, "False", file_path, True, 2, True)
# 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)
up = bool(os.path.exists(file_path))
try:
with open(file_path, "w") as f:
f.write(contents)
except:
# Exit at error
debug.out(7, "False", file_path, True, 2, True)
# 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)
#===========================================#
# Update ini file, replacing existing value #
#-------------------------------------------#
def update_ini_file(file_path, section, key, val):
# Exit if no file
if not os.path.exists(file_path):
debug.out(5, "False", file_path, True, 2, True)
# Exit if no file
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)
# New value is same as registred
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)
# Load ini file
config = configparser.ConfigParser()
config.read(file_path)
# New value is same as registred
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)
#====================#
# Base64 Convertions #
#--------------------#
def b64_convert(action, content):
if action == 'encode':
global b64_content
b64_base64 = ''
content_bytes = content.encode("utf8")
base64_bytes = base64.b64encode(content_bytes)
b64_content = base64_bytes.decode("utf8")
return b64_content
elif action == 'decode':
global src_content
src_content = ''
content_bytes = content.encode("utf8")
base64_bytes = base64.b64decode(content_bytes)
src_content = base64_bytes.decode("utf8")
return src_content
#================================#
# Convert html sign in string #
# used to deactivate HTML markup #
# Return new string #
#--------------------------------#
def convert_html_signs(string):
string = string.replace('<', '&lt;')
string = string.replace('>', '&gt;')
astring = string.replace('"', '&quot;')
string = string.replace("'", '&apos;')
return string

View File

@ -93,3 +93,14 @@ ini_domains_list = """[DOMAINS]
# Put here values where posts target cannot begin with
notarget = ("./", "../")
#======#
# HTML #=======================================================================
#======#
pre_bcode = """<pre class="%s_blockcode">
<code class="%s_blockcode">
<ol class="%s_blockcode">
%s
</ol>
</code>
</pre>"""

View File

@ -40,22 +40,21 @@ import langs, forms, domain
# Specific to action "set #
#------------------------------------#
def manage(action, target):
# Load or Exit if no configuration
domain.cf_load()
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,
}
# Load or Exit if no configuration
domain.cf_load()
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](True)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)
do[target](True)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)