diff --git a/CHANGELOG.md b/CHANGELOG.md index 117ad39..3c4ba38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Tyto - Littérateur # CURRENTLY IN DEV ! +## [1.9.12] +- preparing check process : head tags in article + ## [1.9.11] - Preparing for multi-targets with "all" - check if article is a .tyto format diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 099edab..0888f9a 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.11 -# Updated: 2023-09-29 1696004712 +# Version: 1.9.12 +# Updated: 2023-09-30 1696082419 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc index bc9ecf4..512ec39 100644 Binary files a/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc index d42cd39..d9f7488 100644 Binary files a/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc index 6e05990..b378b80 100644 Binary files a/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc index 235c5b2..9dedeaa 100644 Binary files a/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/post.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc index 4807808..752c9d8 100644 Binary files a/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc differ diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 6cbabc6..37e91ec 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -76,8 +76,14 @@ def is_article(target): sys.exit(post.error) - header_contents() + head_contents() + if post.error != 0: + if args.multiple: + return # Let other articles pass + + sys.exit(post.error) + print("pass", post.error, args.multiple) #===========================================# # # Create a loop to get all .tyto articles # @@ -89,7 +95,65 @@ def multiple_targets(): #=======================# # check header contents # #-----------------------# -def header_contents(): - print("check: uri_db =", post.cf_uri, post.wrk_id) - print("wrk_target", post.wrk_target) - print(post.head_contents, post.text_contents) +def head_contents(): + for ln, line in enumerate(post.head_contents.rsplit("\n"), 1): + if not line or line.isspace() or line.startswith("#"): continue + + # One Line tags (Must be set) + # =========================== + if not post.title[1] and line.startswith(post.title[0]): + post.title = (post.title[0], ol_tag_value(line, False)) + + elif not post.about[1] and line.startswith(post.about[0]): + post.about = (post.about[0], ol_tag_value(line, False)) + + elif not post.date[1] and line.startswith(post.date[0]): + post.date = (post.date[0], ol_tag_value(line, False)) + + elif not post.author[1] and line.startswith(post.author[0]): + post.author = (post.author[0], ol_tag_value(line, True)) + + elif not post.tags[1] and line.startswith(post.tags[0]): + post.tags = (post.tags[0], ol_tag_value(line, True)) + + # Sets are done from loop + # Check if tag value exists + # ========================= + if not is_ol_tag(post.title[0], post.title[1]): return + if not is_ol_tag(post.about[0], post.about[1]): return + if not is_ol_tag(post.date[0], post.date[1]): return + if not is_ol_tag(post.author[0], post.author[1]): return + if not is_ol_tag(post.tags[0], post.tags[1]): return + + +#===========================================# +# Return value from one line after "[tag]:" # +# tags, author are comma separated # +# set new value, removing spaces (strip) # +#-------------------------------------------# +def ol_tag_value(line, commas): + value = line.rsplit(":")[1].lstrip() + + # reformat comma separated items, removing first space + if commas: + tuple_values = value.rsplit(",") + value = "" + for i, item in enumerate(tuple_values): + value = value + item.strip() + if i != len(tuple_values) - 1: + value = value + "," + + return value + + +#===========================# +# Check if tag value is set # +# return True/False # +#---------------------------# +def is_ol_tag(tag, value): + if not value: + post.error = 51 + debug.out(51, "%s ?"%tag, post.uri, True, 2, False) + return False + + return True diff --git a/src/var/lib/tyto/program/debug.py b/src/var/lib/tyto/program/debug.py index 1f321b0..dc2f8d1 100644 --- a/src/var/lib/tyto/program/debug.py +++ b/src/var/lib/tyto/program/debug.py @@ -88,6 +88,7 @@ def out(nbr, var, val, show, color, stop): 22 : langs.logs.err_post_head, 23 : langs.logs.err_post_empty, 50 : langs.logs.err_date, + 51 : langs.logs.err_post_data, # WARNINGS (100-200) 100 : langs.logs.warn_no_dom, 101 : langs.logs.domain_created, diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index f69b0a8..effe725 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -145,7 +145,7 @@ def cf_create(): forms.ask_domain_shortname(name) # Create default files - tools.create_file(cf_uri, tyto.ini_domain%name) + tools.create_file(cf_uri, ini_template%name) tools.create_dirs(ult_dir) tools.create_file(ult_cf_uri, tyto.ini_domain_user) @@ -595,6 +595,9 @@ except: debug.out(2, "PWD", "?", True, 2, True) +#======# +# main # +#======# #==========================================# # utl: $USER/.local/Tyto # # cf: Domain Configuration File # @@ -620,3 +623,115 @@ cf_id = tools.get_filesum(cf_uri, False) # ID from URI ult_dir = os.path.join(home_dir, ".local/Tyto/") ult_dlf_uri = os.path.join(ult_dir, "domains.ini") # Domains list file ult_cf_uri = os.path.join(ult_dir, cf_id + ".ini") + + +#===========================# +# Templates #================================================== +#===========================# +#=============================# +# Domain configuration file # +# Create file with new domain # +#-----------------------------# +ini_template = """[DOMAIN] +activated = no +name = %s +title = +date = +about = +tags = +mail = +license = gfdl-1.3 +license_url = https://www.gnu.org/licenses/fdl-1.3.txt +legals_url = +terms_url = +statuses_url = + +[WEBSITE] +www_url = +wip_url = +lang = +css = tyto +separator = | +article_code = yes +static = no + +[WEBSITE_MODULES] +navbar = yes +sidebar_title = +sidebar_items = 6 +rss_items = 100 +sitemaps = yes + +[TEMPLATE_FILENAMES] +favicon = favicon.png +logo = logo.png +styles = styles.css +rss = rss.xml +stats = tyto_stats.ini + +[USER_DIRS] +root = +articles = +images = +files = +modules = +database = +template = + +[USER_TEMPLATE_FILES] +logo = +favicon = +styles = + +[USER_MODULES_FILES] +metas = +header = +navbar = +sidebar = +footer = + +[SERVER] +root = /var/www/ +domain = +wip = +www = + +[WIP_DIRS] +images = +files = +template = + +[WIP_FILES] +favicon = +logo = +styles = +rss = +stats = +metas = +header = +navbar = +sidebar = +footer = + +[WWW_DIRS] +images = +files = +template = + +[WWW_FILES] +favicon = +logo = +styles = +rss = +stats = +metas = +header = +navbar = +sidebar = +footer = + +[TYTO] +domain_hash = +domain_conf = +domain_user = +""" diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py index 0c809cf..50199c7 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -36,8 +36,6 @@ import os, configparser import domain, debug, tools, tyto -error = 0 - #============================================# # Check if current directory is in articles/ # # Check if article from target exists # @@ -102,7 +100,7 @@ def is_tyto_format(): if not line: continue - if line.startswith(tyto.post_sep): + if line.startswith(post_sep): separator = True continue @@ -110,7 +108,7 @@ def is_tyto_format(): else: head_contents = "%s%s\n"%(head_contents, line) if not separator: - debug.out(21, tyto.post_sep, uri, True, 2, False) + debug.out(21, post_sep, uri, True, 2, False) error = 21 return False @@ -156,3 +154,18 @@ def cf_valid(): print("post: chk_hash", chk_hash) + +#======# +# MAIN # +#======# +error = 0 + +# Tag separator to split head and text article +post_sep = "-----" + +# One Line Tags in head article +title = ("title:", False) +about = ("about:", False) +date = ("date:", False) +tags = ("tags:", False) +author = ("author:", False) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index d06818f..36227a3 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -72,116 +72,7 @@ keys_questions = { "tags" : forms.ask_domain_tags } -#===========================# -# Templates #================================================== -#===========================# -#=============================# -# Domain configuration file # -# Create file with new domain # -#-----------------------------# -ini_domain = """[DOMAIN] -activated = no -name = %s -title = -date = -about = -tags = -mail = -license = gfdl-1.3 -license_url = https://www.gnu.org/licenses/fdl-1.3.txt -legals_url = -terms_url = -statuses_url = -[WEBSITE] -www_url = -wip_url = -lang = -css = tyto -separator = | -article_code = yes -static = no - -[WEBSITE_MODULES] -navbar = yes -sidebar_title = -sidebar_items = 6 -rss_items = 100 -sitemaps = yes - -[TEMPLATE_FILENAMES] -favicon = favicon.png -logo = logo.png -styles = styles.css -rss = rss.xml -stats = tyto_stats.ini - -[USER_DIRS] -root = -articles = -images = -files = -modules = -database = -template = - -[USER_TEMPLATE_FILES] -logo = -favicon = -styles = - -[USER_MODULES_FILES] -metas = -header = -navbar = -sidebar = -footer = - -[SERVER] -root = /var/www/ -domain = -wip = -www = - -[WIP_DIRS] -images = -files = -template = - -[WIP_FILES] -favicon = -logo = -styles = -rss = -stats = -metas = -header = -navbar = -sidebar = -footer = - -[WWW_DIRS] -images = -files = -template = - -[WWW_FILES] -favicon = -logo = -styles = -rss = -stats = -metas = -header = -navbar = -sidebar = -footer = - -[TYTO] -domain_hash = -domain_conf = -domain_user = -""" # Template file configuration for each a created domain # @@ -199,9 +90,6 @@ root = ini_domains_list = """[DOMAINS] """ -# Domain keys that can be empty -opt_domain_keys = ("legals_url", "terms_url", "statuses_url") - #=============================# # articles configuration file # #-----------------------------# @@ -253,8 +141,3 @@ lines = # Put here values where posts target cannot begin with notarget = ("./", "../") - -#===================# -# Artcicle contents #========================================================== -#===================# -post_sep = "-----" diff --git a/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc b/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc index e724e2e..535c427 100644 Binary files a/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc and b/src/var/lib/tyto/translations/__pycache__/logs_fr.cpython-311.pyc differ diff --git a/src/var/lib/tyto/translations/logs_fr.py b/src/var/lib/tyto/translations/logs_fr.py index f698d82..76078fe 100644 --- a/src/var/lib/tyto/translations/logs_fr.py +++ b/src/var/lib/tyto/translations/logs_fr.py @@ -61,6 +61,7 @@ err_post_sep = "Séparateur manquant" err_post_head = "Erreur dans l'Entête" err_post_empty = "Article vide" err_ini_file = "Configuration invalide" +err_post_data = "Article: donnée manquante" # Warnings warn_no_dom = "Domaine non configuré"