[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 ! # 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] ## [1.9.20]
- working on 'check' process - working on 'check' process
- - updated 'logo:' process - - updated 'logo:' process

View File

@ -9,6 +9,11 @@ tyto
## ToDo next (working on) ## ToDo next (working on)
- 'check' action processes - '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 ! - Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.20 # Version: 1.9.21
# Updated: 2023-10-06 1696580458 # Updated: 2023-10-08 1696756865
# 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>
@ -48,27 +48,27 @@ import os
# Error message # # Error message #
#---------------# #---------------#
def error_message(path): def error_message(path):
print("! Installation error, unused:", path) print("! Installation error, unused:", path)
sys.exit(1) sys.exit(1)
#======================================================# #======================================================#
# A little checker to be sure, all files are installed # # A little checker to be sure, all files are installed #
#------------------------------------------------------# #------------------------------------------------------#
def check_install(): def check_install():
if not os.path.exists(libs): error_message(libs) if not os.path.exists(libs): error_message(libs)
if not os.path.exists(trfs): error_message(trfs) if not os.path.exists(trfs): error_message(trfs)
for f in prog_files: for f in prog_files:
f = os.path.join(libs, f + ".py") f = os.path.join(libs, f + ".py")
if not os.path.exists(f): if not os.path.exists(f):
error_message(f) error_message(f)
# Only default lang files # Only default lang files
for f in lang_files: for f in lang_files:
f = os.path.join(trfs, f + ".py") f = os.path.join(trfs, f + ".py")
if not os.path.exists(f): if not os.path.exists(f):
error_message(f) error_message(f)
@ -77,8 +77,8 @@ def check_install():
#======# #======#
import sys import sys
if not __name__ == "__main__": if not __name__ == "__main__":
print("! Error: '%s' not '%s'"%(__name__, "__main__")) print("! Error: '%s' not '%s'"%(__name__, "__main__"))
sys.exit(1) sys.exit(1)
# files list in /program/ # files list in /program/
prog_files = { prog_files = {

View File

@ -40,59 +40,59 @@ import langs, tyto, debug, help, new, check, userset, show
# Action Arguments # # Action Arguments #
#------------------# #------------------#
def get_action(): def get_action():
global action global action
try: action = sys.argv[1] try: action = sys.argv[1]
except: action = "" except: action = ""
#==================# #==================#
# Target arguments # # Target arguments #
#------------------# #------------------#
def get_target(): def get_target():
global target, targets global target, targets
try: target = sys.argv[2] try: target = sys.argv[2]
except: target = "" except: target = ""
targets = False targets = False
if target == "all": targets = True if target == "all": targets = True
#================================# #================================#
# Searching options in arguments # # Searching options in arguments #
#--------------------------------# #--------------------------------#
def get_options(): def get_options():
global dlogs, force, erron global dlogs, force, erron
dlogs = force = erron = False dlogs = force = erron = False
for arg in range(1, len(sys.argv)): for arg in range(1, len(sys.argv)):
dlogs = sys.argv[arg] in tyto.debug_options dlogs = sys.argv[arg] in tyto.debug_options
force = sys.argv[arg] in tyto.force_options force = sys.argv[arg] in tyto.force_options
erron = sys.argv[arg] in tyto.debug_errors erron = sys.argv[arg] in tyto.debug_errors
#===========# #===========#
# Show logs # # Show logs #
#-----------# #-----------#
def valid_action(): def valid_action():
global action global action
if not action in tyto.actions: if not action in tyto.actions:
debug.out(1, "[action]", action, False, 2, False) debug.out(1, "[action]", action, False, 2, False)
action = "help" action = "help"
#==============# #==============#
# Start action # # Start action #
#--------------# #--------------#
def start_process(): def start_process():
# Set Lang logs # Set Lang logs
langs.load_logs_lang() langs.load_logs_lang()
get_options() get_options()
get_action() get_action()
get_target() get_target()
valid_action() valid_action()
do = { do = {
"help" : help.show, "help" : help.show,
"check" : check.manage, "check" : check.manage,
"new" : new.manage, "new" : new.manage,
@ -101,6 +101,6 @@ def start_process():
"stop" : userset.manage, "stop" : userset.manage,
"show" : show.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 # # stop to sys exit with nbr if True #
#-----------------------------------# #-----------------------------------#
def out(nbr, var, val, show, color, stop): def out(nbr, var, val, show, color, stop):
args.get_options() args.get_options()
if not show: if not show:
# Show only warn and error logs # Show only warn and error logs
show = args.dlogs or args.erron and color > 0 show = args.dlogs or args.erron and color > 0
if not show: if not show:
return nbr return nbr
# COlors # COlors
CS = '\033[0;0m' # Unset CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink CP = '\033[1;35m' # Pink
# Color of "*" # Color of "*"
SC = CL # Default gray SC = CL # Default gray
if color == 0: SC = CG if color == 0: SC = CG
elif color == 1: SC = CY elif color == 1: SC = CY
elif color == 2: SC = CR elif color == 2: SC = CR
# Messages for logs # Messages for logs
messages = \ messages = \
{ {
# ERRORS (1-100) # ERRORS (1-100)
1 : langs.logs.err_arg, 1 : langs.logs.err_arg,
@ -115,23 +115,22 @@ def out(nbr, var, val, show, color, stop):
209 : langs.logs.domain_on, 209 : langs.logs.domain_on,
255 : langs.logs.later, 255 : langs.logs.later,
} }
# Print, acoording to parameters # Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%( print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
SC, CS, SC, CS,
CL, messages[nbr], CS, CL, messages[nbr], CS,
CB, var, CS, CB, var, CS,
CC, val, CS CC, val, CS
) )
) )
# Exit if stop = True # Exit if stop = True
if stop: if stop:
if nbr >= 200: if nbr >= 200: nbr = 0
nbr = 0 sys.exit(nbr)
sys.exit(nbr)
return 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 # # Exit if directory name is compatible with a domain name #
#---------------------------------------------------------# #---------------------------------------------------------#
def compatible_name(): def compatible_name():
if len(name.rsplit(".")) <= 1: if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True) debug.out(3, "abc.tld", name, True, 2, True)
#================================# #================================#
@ -49,13 +49,13 @@ def compatible_name():
# As needed, exit if not exists # # As needed, exit if not exists #
#--------------------------------# #--------------------------------#
def cf_load(): def cf_load():
global cf global cf
cf_exists() or sys.exit(100) cf_exists() or sys.exit(100)
cf = False cf = False
cf = configparser.ConfigParser() cf = configparser.ConfigParser()
cf.read(cf_uri) cf.read(cf_uri)
#=====================================# #=====================================#
@ -63,29 +63,29 @@ def cf_load():
# As needed, exit if not exists # # As needed, exit if not exists #
#-------------------------------------# #-------------------------------------#
def ult_cf_load(): def ult_cf_load():
global ult_cf global ult_cf
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)
ult_cf = configparser.ConfigParser() ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri) ult_cf.read(ult_cf_uri)
#===================================# #===================================#
# Load User local Domains List File # # Load User local Domains List File #
#-----------------------------------# #-----------------------------------#
def ult_dlf_load(): def ult_dlf_load():
global ult_dlf global ult_dlf
# User Domains list file # User Domains list file
ult_dlf = False 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 = configparser.ConfigParser() ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri) ult_dlf.read(ult_dlf_uri)
#===========================================# #===========================================#
@ -94,36 +94,36 @@ def ult_dlf_load():
# return True or False # return True or False
#-------------------------------------------# #-------------------------------------------#
def cf_exists(): def cf_exists():
global shown_ok, shown_no global shown_ok, shown_no
if os.path.exists(cf_uri): if os.path.exists(cf_uri):
try: shown_ok try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False) except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True shown_ok = True
return True return True
else: else:
try: shown_no try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False) except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True shown_no = True
compatible_name() compatible_name()
return False return False
#=========================================# #=========================================#
# Guess and return wip_url from name # # Guess and return wip_url from name #
#-----------------------------------------# #-----------------------------------------#
def create_wip_url(): def create_wip_url():
www_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 www_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 www_url%tld return www_url%tld
#==========================================# #==========================================#
@ -134,41 +134,41 @@ def create_wip_url():
# If not User domains list file, create it # # If not User domains list file, create it #
#------------------------------------------# #------------------------------------------#
def cf_create(): def cf_create():
compatible_name() compatible_name()
# This fonction is only called with "new domain" argument # This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log # If a conf already exists, show important RESET log
if cf_exists(): if cf_exists():
debug.out(102, "!?", cf_uri, True, 1, False) debug.out(102, "!?", cf_uri, True, 1, False)
# Ask User to create new domain. Will exit if not ok. # Ask User to create new domain. Will exit if not ok.
forms.ask_domain_shortname(name) forms.ask_domain_shortname(name)
# Create default files # Create default files
tools.create_file(cf_uri, ini_template%name) tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir) tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user) tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# User Domains list file # User Domains list file
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)
# Ask user for domain settings # Ask user for domain settings
cf_load() cf_load()
forms.ask_domain_title(True) forms.ask_domain_title(True)
forms.ask_domain_date(True) forms.ask_domain_date(True)
forms.ask_domain_about(True) forms.ask_domain_about(True)
forms.ask_domain_mail(True) forms.ask_domain_mail(True)
forms.ask_domain_tags(True) forms.ask_domain_tags(True)
# Set default lang, from config file or system lang # Set default lang, from config file or system lang
forms.ask_domain_lang(True) forms.ask_domain_lang(True)
# Set server directory # Set server directory
forms.ask_domain_server(True) forms.ask_domain_server(True)
# Update Domain Configuration file # Update Domain Configuration file
cf_update_values(True) cf_update_values(True)
@ -179,35 +179,35 @@ def cf_create():
# Ask yser when default is a key form and not value # # Ask yser when default is a key form and not value #
#---------------------------------------------------# #---------------------------------------------------#
def cf_set_value(section, key, default): def cf_set_value(section, key, default):
global new_val global new_val
try: new_val try: new_val
except: new_val = False 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: cf.set(section, key, default)
val = cf.get(section, key) debug.out(204, "[%s] %s"%(section, key), default, False, 0, False)
except:
try: cf.add_section(section) ; new_val = True return default
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
#===========================================# #===========================================#
@ -216,334 +216,334 @@ def cf_set_value(section, key, default):
# 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()
# [DOMAIN] # [DOMAIN]
# ======== # ========
global activated, title, date, about, mail, tags, license, license_url global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated") try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no") except: activated = cf_set_value("DOMAIN", "activated", "no")
cf_set_value("DOMAIN", "name", name) cf_set_value("DOMAIN", "name", name)
title = cf_set_value("DOMAIN", "title", "title") title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date") date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about") about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail") mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags") tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "") license = cf_set_value("DOMAIN", "lincese", "")
if not license: if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3") license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url", license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt") "https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3": elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","") license_url = cf_set_value("DOMAIN", "lincese_url","")
# Optional # Optional
global legals_url, terms_url, statuses_url global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "") legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "") terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "") statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# [SERVER] # [SERVER]
# ======== # ========
global srv, srv_name, wip, www global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server") srv = cf_set_value("SERVER", "root", "server")
if not tools.dir_exists(srv, False): if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server") srv = cf_set_value("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/") srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name) cf_set_value("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/") wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip) cf_set_value("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/") www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www) cf_set_value("SERVER", "www", www)
# [WIP_DIRS] # [WIP_DIRS]
# ========== # ==========
global wip_tpl, wip_images, wip_files global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/") wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl) cf_set_value("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/") wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images) cf_set_value("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/") wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files) cf_set_value("WIP_DIRS", "files", wip_files)
# [WWW_DIRS] # [WWW_DIRS]
# ========== # ==========
global www_tpl, www_images, www_files global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/") www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl) cf_set_value("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/") www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images) cf_set_value("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/") www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files) cf_set_value("WWW_DIRS", "files", www_files)
# [WEBSITE] # [WEBSITE]
# ========= # =========
global wip_url, www_url, lang, css, sep, article_code, static global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "") wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url: if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url()) wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "") www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url: if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name) www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "") lang = cf_set_value("WEBSITE", "lang", "")
if not lang: if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang()) lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
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()
langs.load_website_lang() langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "") css = cf_set_value("WEBSITE", "css", "")
if not css: if not css:
css = cf_set_value("WEBSITE", "css", "tyto") css = cf_set_value("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "") sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2: if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|") sep = cf_set_value("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code") try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes") except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static") try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no") except: static = cf_set_value("WEBSITE", "static", "no")
# [WEBSITE_MODULES] # [WEBSITE_MODULES]
# ================= # =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar") try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes") except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "") sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title: if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title) langs.site.sidebar_title)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "") sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit(): if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0") sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "") rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
if not rss_items or not rss_items.isdigit(): if not rss_items or not rss_items.isdigit():
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0") rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps") try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes") except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
# TEMPLATE_FILENAMES # TEMPLATE_FILENAMES
# ================== # ==================
global favicon, logo, styles, rss, stats global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon: if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "") logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo: if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png") logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "") styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles: if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css") styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "") rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss: if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml") rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "") stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats: if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini") stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS] # [USER_DIRS]
# =========== # ===========
cf_set_value("USER_DIRS", "root", wrk_dir) cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles) cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images) cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files) cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl) cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods) cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db) cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES] # [USER_TEMPLATE_FILES]
# ===================== # =====================
global wrk_favicon, wrk_logo, wri_styles global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon) wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon) cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo) wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo) cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles) wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles) cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES] # [USER_MODULES_FILES]
# ==================== # ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw") wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas) cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw") wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header) cf_set_value("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw") wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar) cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw") wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar) cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw") wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer) cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
# [WIP_FILES] # [WIP_FILES]
# =========== # ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon) wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon) cf_set_value("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo) wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo) cf_set_value("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles) wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles) cf_set_value("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss) wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss) cf_set_value("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats) wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats) cf_set_value("WIP_FILES", "stats", wip_stats)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html") wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas) cf_set_value("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html") wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header) cf_set_value("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html") wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar) cf_set_value("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html") wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar) cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html") wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer) cf_set_value("WIP_FILES", "footer", wip_footer)
# [WWW_FILES] # [WWW_FILES]
# =========== # ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon) www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon) cf_set_value("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo) www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo) cf_set_value("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles) www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles) cf_set_value("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss) www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss) cf_set_value("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats) www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats) cf_set_value("WWW_FILES", "stats", www_stats)
global www_metas, www_header, www_navbar, www_sidebar, www_footer global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html") www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas) cf_set_value("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html") www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header) cf_set_value("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html") www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar) cf_set_value("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html") www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar) cf_set_value("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html") www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer) cf_set_value("WWW_FILES", "footer", www_footer)
# [TYTO] # [TYTO]
# ====== # ======
cf_set_value("TYTO", "domain_hash", cf_id) cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri) cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri) cf_set_value("TYTO", "domain_user", ult_cf_uri)
# ================================= # # ================================= #
# Write Configuration file # # Write Configuration file #
# Only if needed or when new domain # # Only if needed or when new domain #
# --------------------------------- # # --------------------------------- #
if new_val or write: if new_val or write:
with open(cf_uri, "w") as f: with open(cf_uri, "w") as f:
cf.write(f) cf.write(f)
#=============================================# #=============================================#
# Update User local domain configuration file # # Update User local domain configuration file #
#---------------------------------------------# #---------------------------------------------#
ult_write = False ult_write = False
ult_cf_load() ult_cf_load()
if ult_cf.get("DOMAIN", "name") != name: if ult_cf.get("DOMAIN", "name") != name:
ult_cf.set("DOMAIN", "name", name) ult_cf.set("DOMAIN", "name", name)
ult_write = True ult_write = True
cf_hash_c = tools.get_filesum(cf_uri, True) cf_hash_c = tools.get_filesum(cf_uri, True)
if ult_cf.get("DOMAIN", "hash") != cf_hash_c: if ult_cf.get("DOMAIN", "hash") != cf_hash_c:
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") != wrk_dir: if ult_cf.get("DOMAIN", "root") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_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:
ult_cf.set("DOMAIN", "conf", cf_uri) ult_cf.set("DOMAIN", "conf", cf_uri)
ult_write = True ult_write = True
if ult_cf.get("SERVER", "root") != srv: if ult_cf.get("SERVER", "root") != srv:
ult_cf.set("SERVER", "root", srv) ult_cf.set("SERVER", "root", srv)
ult_write = True ult_write = True
if ult_write: if ult_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 != wrk_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, wrk_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)
#========================================# #========================================#
@ -552,19 +552,18 @@ def cf_update_values(write):
# if activated, check/create wrk dirs # # if activated, check/create wrk dirs #
#----------------------------------------# #----------------------------------------#
def userset_status(action): def userset_status(action):
do = {
do = {
"start" : "yes", "start" : "yes",
"stop" : "no" "stop" : "no"
} }
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action]) tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False) cf_update_values(False)
ready() ready()
if action == "start": if action == "start":
status = cf.get("DOMAIN", "activated") status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False) 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 # # or check/create wrk directories #
#----------------------------------------# #----------------------------------------#
def ready(): def ready():
if not activated: if not activated:
status = cf.get("DOMAIN", "activated") status = cf.get("DOMAIN", "activated")
debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True) debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True)
for key, directory in cf.items("USER_DIRS"): for key, directory in cf.items("USER_DIRS"):
tools.create_dirs(directory) tools.create_dirs(directory)
#======#======================================================================= #======#=======================================================================
@ -590,10 +589,10 @@ def ready():
# Exit Tyto if in black hole... # # Exit Tyto if in black hole... #
#-----------------------------------# #-----------------------------------#
try: try:
user_dir = os.getcwd() + "/" user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
except: 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... # # user interrupts... #
#--------------------# #--------------------#
def maybe_later(expected, answer): 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 # # yes_only : True / False #
#-------------------------# #-------------------------#
def ask(q, yes_only, default): def ask(q, yes_only, default):
expected = "" expected = ""
if yes_only: if yes_only:
expected = langs.logs.ok expected = langs.logs.ok
try: answer = input(q) try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?") except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
# return default answer if exists # return default answer if exists
if not answer: if not answer:
if default: if default:
return default return default
maybe_later(expected, "?") maybe_later(expected, "?")
# Answer is a Y/N process # Answer is a Y/N process
if yes_only: if yes_only:
for ok in langs.logs.ok: for ok in langs.logs.ok:
if answer.lower() == ok.lower(): if answer.lower() == ok.lower():
return True return True
maybe_later(expected, answer) maybe_later(expected, answer)
return answer return answer
#====================================# #====================================#
@ -81,11 +81,11 @@ def ask(q, yes_only, default):
# return value[0:12] # # return value[0:12] #
#------------------------------------# #------------------------------------#
def shorter(value): def shorter(value):
if len(value) > 12: if len(value) > 12:
return '%s...'%(value[0:12]) return '%s...'%(value[0:12])
# Or legacy # Or legacy
return value return value
#=========================# #=========================#
@ -93,8 +93,8 @@ def shorter(value):
# from directory basename # # from directory basename #
# ------------------------# # ------------------------#
def ask_domain_shortname(config_name): def ask_domain_shortname(config_name):
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False) ask(q, True, False)
#=======================# #=======================#
@ -104,14 +104,14 @@ def ask_domain_shortname(config_name):
# - False: return value # # - False: return value #
#-----------------------# #-----------------------#
def ask_domain_title(update): def ask_domain_title(update):
try: title = domain.cf.get("DOMAIN", "title") try: title = domain.cf.get("DOMAIN", "title")
except: title = "" except: title = ""
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title) answer = ask(q, False, title)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer else: return answer
#===========================# #===========================#
@ -122,24 +122,24 @@ def ask_domain_title(update):
# - False: return value # # - False: return value #
#---------------------------# #---------------------------#
def ask_domain_date(update): def ask_domain_date(update):
try: date = domain.cf.get("DOMAIN", "date") try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]" except: date = "YYYY[-MM][-DD]"
example = date example = date
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date) answer = ask(q, False, date)
# Check date format (not valid date) # Check date format (not valid date)
try: try:
parse(answer) parse(answer)
except: except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False) debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update) ask_domain_date(update)
return return
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer else: return answer
#========================# #========================#
@ -149,14 +149,14 @@ def ask_domain_date(update):
# - False: return value # # - False: return value #
#------------------------# #------------------------#
def ask_domain_about(update): def ask_domain_about(update):
try: about = domain.cf.get("DOMAIN", "about") try: about = domain.cf.get("DOMAIN", "about")
except: about = "" except: about = ""
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about) answer = ask(q, False, about)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer else: return answer
#=======================# #=======================#
@ -166,14 +166,14 @@ def ask_domain_about(update):
# - False: return value # # - False: return value #
#-----------------------# #-----------------------#
def ask_domain_mail(update): def ask_domain_mail(update):
try: mail = domain.cf.get("DOMAIN", "mail") try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = "" except: mail = ""
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail) answer = ask(q, False, mail)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer else: return answer
#===============================================# #===============================================#
@ -183,22 +183,22 @@ def ask_domain_mail(update):
# - False: return value # # - False: return value #
#-----------------------------------------------# #-----------------------------------------------#
def ask_domain_tags(update): def ask_domain_tags(update):
try: tags = domain.cf.get("DOMAIN", "tags") try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = "" except: tags = ""
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags) answer = ask(q, False, tags)
# Remove useless spaces for HTML meta # Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",") tuple_tags = answer.rsplit(",")
answer = "" answer = ""
for i, tag in enumerate(tuple_tags): for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip() answer = answer + tag.strip()
if i != len(tuple_tags) - 1: if i != len(tuple_tags) - 1:
answer = answer + "," answer = answer + ","
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer else: return answer
#===================================# #===================================#
@ -206,52 +206,52 @@ def ask_domain_tags(update):
# default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO # default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO
#-----------------------------------# #-----------------------------------#
def ask_domain_lang(update): def ask_domain_lang(update):
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang() try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = "" except: lang = ""
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower() answer = ask(q, False, lang).lower()
# Lang Format is 2 character # Lang Format is 2 character
if len(answer) != 2: if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False) debug.out("8", "xx", answer, True, 2, False)
debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False) debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False)
answer = lang answer = lang
# Check if translation file exists # Check if translation file exists
if not langs.translation_exists("website", answer, False): if not langs.translation_exists("website", answer, False):
lang = lang.get_sys_lang() lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False) debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang answer = lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer) if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang else: return lang
#===================================# #===================================#
# Get domain server root # # Get domain server root #
#-----------------------------------# #-----------------------------------#
def ask_domain_server(update): def ask_domain_server(update):
try: try:
srv = domain.cf.get("SERVER", "root") srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False): if not tools.dir_exists(srv, False):
srv = ""
except:
srv = "" srv = ""
except:
srv = "" if srv and not tools.dir_exists(srv, False):
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)
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):
# Check if directory exists answer = ""
if not tools.dir_exists(answer, False): ask_domain_server(update)
answer = "" return
ask_domain_server(update)
return if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer
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 # # Help Contents is in translations/logs_XX #
#------------------------------------------# #------------------------------------------#
def show(action, target): 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 # # return True or False #
#----------------------------------# #----------------------------------#
def translation_exists(module, lang, out): def translation_exists(module, lang, out):
global tr_file global tr_file
modules = ("logs", "website") modules = ("logs", "website")
if not module in modules: return # in case of internal typo error # in case of internal typo error
if not module in modules:
tr_file = "%s%s_%s.py"%(trfs, module, lang) print("! langs: internal error: 'logs', 'website'")
if not os.path.exists(tr_file): sys.exit(254)
debug.out(5, lang, tr_file, True, 2, False)
return False tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file):
return True 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 # # Get system Lang to set logs #
#-----------------------------# #-----------------------------#
def get_sys_lang(): def get_sys_lang():
global lang, tr_logs_uri global lang, tr_logs_uri
tr_logs_uri = "%slogs_%s.py" tr_logs_uri = "%slogs_%s.py"
try: lang = locale.getdefaultlocale()[0].rsplit("_")[0] try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en" except: lang = "en"
if not translation_exists("logs", lang, False): if not translation_exists("logs", lang, False):
lang = "en" lang = "en"
tr_logs_uri = tr_logs_uri%(trfs, lang) tr_logs_uri = tr_logs_uri%(trfs, lang)
return lang return lang
#===============================# #===============================#
# Import logs lang file in logs # # Import logs lang file in logs #
#-------------------------------# #-------------------------------#
def load_logs_lang(): def load_logs_lang():
global logs, lang, set_logs global logs, lang, set_logs
try: try:
set_logs set_logs
except: except:
logs = __import__("logs_%s"%get_sys_lang()) logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False) debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True set_logs = True
#=============================================================================# #=============================================================================#
@ -107,30 +110,31 @@ def load_logs_lang():
# Get website lang from cf to set site # # Get website lang from cf to set site #
#---------------------------------------# #---------------------------------------#
def get_website_lang(): def get_website_lang():
global site_lang, tr_website_uri global site_lang, tr_website_uri
tr_website_uri = "%swebsite_%s.py" tr_website_uri = "%swebsite_%s.py"
try: site_lang = domain.cf.get("WEBSITE", "lang") try: site_lang = domain.cf.get("WEBSITE", "lang")
except: site_lang = get_sys_lang() except: site_lang = get_sys_lang()
if not translation_exists("website", site_lang, False): if not translation_exists("website", site_lang, False):
site_lang = get_sys_lang() # or default "en" site_lang = get_sys_lang() # or default "en"
tr_website_uri = tr_website_uri%(trfs, site_lang) tr_website_uri = tr_website_uri%(trfs, site_lang)
return site_lang return site_lang
#==================================# #==================================#
# Import website lang file in site # # Import website lang file in site #
#----------------------------------# #----------------------------------#
def load_website_lang(): def load_website_lang():
global site, site_lang, set_site global site, site_lang, set_site
site = __import__("website_%s"%get_website_lang()) site = __import__("website_%s"%get_website_lang())
try: try:
set_site set_site
except: except:
debug.out(208, site_lang, tr_website_uri, False, 0, False) debug.out(208, site_lang, tr_website_uri, False, 0, False)
set_site = True set_site = True

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@
#-------------------------- #--------------------------
from hashlib import blake2b from hashlib import blake2b
import sys, os, configparser, datetime, time import sys, os, configparser, datetime, time, base64
import debug, domain import debug, domain
@ -41,17 +41,17 @@ import debug, domain
# #
# #
def exit(targets, error): def exit(targets, error):
if targets: return if targets: return
sys.exit(error) sys.exit(error)
#==============================# #==============================#
# Set and return date and time # # Set and return date and time #
#------------------------------# #------------------------------#
def nowdate(): def nowdate():
now = datetime.datetime.now() now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S')) return(now.strftime('%Y-%m-%d %H:%M:%S'))
# #
@ -59,18 +59,18 @@ def nowdate():
# Return date (only year) for post database # Return date (only year) for post database
# #
def local_date(date): def local_date(date):
date = date.rsplit(" ")[0] # if nowdate() date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0] year = date.rsplit("-")[0]
month = date.rsplit("-")[1] month = date.rsplit("-")[1]
day = date.rsplit("-")[2] day = date.rsplit("-")[2]
dates = { dates = {
"fr" : "%s/%s/%s"%(day, month, year), "fr" : "%s/%s/%s"%(day, month, year),
"en" : date, "en" : date,
} }
return dates[domain.lang] return dates[domain.lang]
#========================# #========================#
@ -79,12 +79,12 @@ def local_date(date):
# False = URI # # False = URI #
#------------------------# #------------------------#
def get_filesum(path, src): def get_filesum(path, src):
file_sum = blake2b(digest_size=4) file_sum = blake2b(digest_size=4)
if src: file_sum.update(open(path, 'rb').read()) if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode()) else: file_sum.update(path.encode())
return file_sum.hexdigest() return file_sum.hexdigest()
#========================================# #========================================#
@ -92,66 +92,102 @@ def get_filesum(path, src):
# Mainly used to check domain server dir # # Mainly used to check domain server dir #
#----------------------------------------# #----------------------------------------#
def dir_exists(dir_path, out): def dir_exists(dir_path, out):
if not bool(os.path.exists(dir_path)): if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out) debug.out(6, "False", dir_path, out, 2, out)
return False return False
return True return True
#====================# #====================#
# Create directories # # Create directories #
#--------------------# #--------------------#
def create_dirs(path): def create_dirs(path):
try: try:
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path, exist_ok=True) os.makedirs(path, exist_ok=True)
debug.out(203, "True", path, False, 0, False) debug.out(203, "True", path, False, 0, False)
except: except:
# Exit if not created # Exit if not created
debug.out(5, "False", path, True, 2, True) debug.out(5, "False", path, True, 2, True)
#============================# #============================#
# Create a new file and logs # # Create a new file and logs #
#----------------------------# #----------------------------#
def create_file(file_path, contents): def create_file(file_path, contents):
up = bool(os.path.exists(file_path)) up = bool(os.path.exists(file_path))
try: try:
with open(file_path, "w") as f: with open(file_path, "w") as f:
f.write(contents) f.write(contents)
except: except:
# Exit at error # Exit at error
debug.out(7, "False", file_path, True, 2, True) debug.out(7, "False", file_path, True, 2, True)
# log "update" or "new" # log "update" or "new"
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
if up: debug.out(207, file_name, file_path, False, 0, False) if up: debug.out(207, file_name, file_path, False, 0, False)
else: debug.out(206, file_name, file_path, False, 0, False) else: debug.out(206, file_name, file_path, False, 0, False)
#===========================================# #===========================================#
# Update ini file, replacing existing value # # Update ini file, replacing existing value #
#-------------------------------------------# #-------------------------------------------#
def update_ini_file(file_path, section, key, val): def update_ini_file(file_path, section, key, val):
# Exit if no file # Exit if no file
if not os.path.exists(file_path): if not os.path.exists(file_path):
debug.out(5, "False", file_path, True, 2, True) 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 # Put here values where posts target cannot begin with
notarget = ("./", "../") 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 # # Specific to action "set #
#------------------------------------# #------------------------------------#
def manage(action, target): def manage(action, target):
# Load or Exit if no configuration # Load or Exit if no configuration
domain.cf_load() domain.cf_load()
if action == "set": if action == "set":
do = { do = {
"title" : forms.ask_domain_title, "title" : forms.ask_domain_title,
"date" : forms.ask_domain_date, "date" : forms.ask_domain_date,
"about" : forms.ask_domain_about, "about" : forms.ask_domain_about,
"mail" : forms.ask_domain_mail, "mail" : forms.ask_domain_mail,
"lang" : forms.ask_domain_lang, "lang" : forms.ask_domain_lang,
"server" : forms.ask_domain_server, "server" : forms.ask_domain_server,
} }
do[target](True) do[target](True)
elif action in ("start", "stop") and target == "domain": elif action in ("start", "stop") and target == "domain":
domain.userset_status(action) domain.userset_status(action)