diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be154d..66e73bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,14 @@ Tyto - Littérateur - Changelog: - License: - Documentation: - -## [1.9.1] -- Auto update configuration domain -- Better managing configuration domain values -- Better checking if valid domain + +## [1.9.5] +- Preparing post database + +## [1.9.4] +- Added start/strop action to activate (or deactivate) domain +- Directories creation for user working domain +- better log management for user diff --git a/README.md b/README.md index 3350f57..ac7fcac 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,9 @@ This program can ve tested but not at all usable. Lots of work to do... tyto ``` -# Working on -- Managing domain(s) -- - needs more checks to be validated -- english logs translation file (French only, for now) +## ToDo next (working on) +- check action +- user is in articles/ directory +- target post exists and compatible +- create template post database -# Next -- Create all directories for valid domain diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 46ed4a8..c1cb731 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.4 -# Updated: 2023-09-25 1695630197 +# Version: 1.9.5 +# Updated: 2023-09-25 1695637945 # 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 159ce74..5bb30de 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 26bdfea..b9fb11d 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 438da5e..8215033 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 new file mode 100644 index 0000000..6b49658 Binary files /dev/null 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 ae86333..d3a454d 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 56045bf..c4a2e13 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -33,7 +33,7 @@ #-------------------------- import sys -import domain, langs, debug +import domain, langs, debug, post #===========================================# @@ -42,9 +42,8 @@ import domain, langs, debug # Create user work domain directories # #-------------------------------------------# def manage(action, target): - # Load domain configuration, update if needed, check if valid - if not domain.cf_valid(): - debug.out(105, domain.name, domain.cf_uri, True, 1, True) + # Load domain configuration (update it if needed), check if valid + domain.cf_valid() or debug.out(105, domain.name, domain.cf_uri, True, 1, True) + target.endswith(".tyto") and post.is_article(target) langs.load_website_lang() - print("check:", action, target) diff --git a/src/var/lib/tyto/program/debug.py b/src/var/lib/tyto/program/debug.py index b2f86f8..31ae03f 100644 --- a/src/var/lib/tyto/program/debug.py +++ b/src/var/lib/tyto/program/debug.py @@ -82,6 +82,10 @@ def out(nbr, var, val, show, color, stop): 6 : langs.logs.err_no_dir, 7 : langs.logs.err_cr_file, 8 : langs.logs.err_lang, + 20 : langs.logs.err_bad_uri, + 21 : langs.logs.err_post_sep, + 22 : langs.logs.err_post_head, + 23 : langs.logs.err_post_empty, 50 : langs.logs.err_date, # WARNINGS (100-200) 100 : langs.logs.warn_no_dom, diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index a48a7a6..2209ef5 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -57,6 +57,12 @@ def cf_load(): cf = configparser.ConfigParser() cf.read(cf_uri) + # Set some needed global values + global articles_dir, db_dir + + articles_dir = cf.get("USER_DIRS", "articles") + db_dir = cf.get("USER_DIRS", "database") + #=====================================# # Load User Domain Configuration file # diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py index f5c7407..4ee9948 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -31,3 +31,104 @@ # file functions: # file program : #-------------------------- + +import os, configparser +import domain, debug, tools, tyto + + +#============================================# +# Check if current directory is in articles/ # +# Check if article from target exists # +# Set post configuration file database # +# load database # +#--------------------------------------------# +def is_article(target): + # User MUST be in articles/ + domain.cf_load() + (os.getcwd() + "/").startswith(domain.articles_dir) or \ + debug.out(2, "-> articles/", domain.articles_dir, True, 2, True) + + # Target URI is from legacy directory + if target.startswith("./") or target.startswith("../"): + debug.out(20, "./, ../", target, True, 2, True) + + # Article exists + global uri + + uri = os.path.join(domain.articles_dir, target) + os.path.exists(uri) or debug.out(5, "False", uri, True, 2, True) + + # Article is a Tyto format and not empty (exit on errors) + is_tyto_format() + + # + global uri_id, cf_uri + + # Set post ID from URI + uri_id = tools.get_filesum(uri, False) + + # Set post configuration file database + cf_uri = os.path.join(domain.db_dir, uri_id + ".ini") + + # Load Database + db = cf_load() # True or False + if db: cf_valid() + else: tools.create_file(cf_uri, tyto.ini_article) + + + + +#=======================================# +# Load post database # +# return True, or False if unused (yet) # +#---------------------------------------# +def cf_load(): + if not os.path.exists(cf_uri): + return False + + global cf + + 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") + + print("post: chk_hash", chk_hash) + + +#=========================================# +# Article is in Tyto format and not empty # +#-----------------------------------------# +def is_tyto_format(): + global uri, header_contents, writer_contents + + separator = False + head_contents = text_contents = "" + + with open(uri, "r") as contents: + contents = contents.read() + for line in contents.rsplit("\n"): + if not line: + continue + + if line.startswith(tyto.post_sep): + separator = True + continue + + if separator: text_contents = "%s%s\n"%(text_contents, line) + else: head_contents = "%s%s\n"%(head_contents, line) + + separator or debug.out(21, tyto.post_sep, uri, True, 2, True) + head_contents or debug.out(22, "?", uri, True, 2, True) + text_contents or debug.out(23, "?", uri, True, 2, True) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index a767c37..b62a86b 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -55,6 +55,8 @@ git_url = "https://git.a-lec.org/echolib/tyto-litterateur" #===========================# # Templates #================================================== +#===========================# +#===========================# # Domain configuration file # #---------------------------# ini_domain = """[DOMAIN] @@ -173,8 +175,63 @@ conf = root = """ +# Domains list ini file ini_domains_list = """[DOMAINS] """ # Domain keys that can be empty opt_domain_keys = ("legals_url", "terms_url", "statuses_url") + +#=============================# +# articles configuration file # +#-----------------------------# +ini_article = """[DOMAIN] +name = + +[FILE] +id = +uri = +db = +target = +src_link = + + +[CONTENTS] +title = +about = +date = +local_date = +tags = +authors = +snpic = +sitemap = + +[CHECK] +hash = +date = +epoch = + +[WIP] +hash = +date = +epoch = +static = +uri = +web = + +[WWW] +hash = +date = +epoch = +static = +uri = +web = + +[STATS] +lines = +""" + +#===================# +# 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 02ca1b0..2332974 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 f5d50b3..2af3159 100644 --- a/src/var/lib/tyto/translations/logs_fr.py +++ b/src/var/lib/tyto/translations/logs_fr.py @@ -47,15 +47,19 @@ domain_srv = "URI du serveur" # logs for debug #--------------- # Errors -err_arg = "Argument invalide" -err_hole = "Dossier courant invalide" -err_date = "Format de date invalide" -err_lang = "Format de langue invalide" -err_dir = "Dossier non compatible" -err_no_dir = "Dossier inexistant" -err_cd = "Dossier non créé" -err_no_file = "Fichier manquant" -err_cr_file = "Fichier non créé" +err_arg = "Argument invalide" +err_hole = "Dossier courant invalide" +err_date = "Format de date invalide" +err_lang = "Format de langue invalide" +err_dir = "Dossier non compatible" +err_no_dir = "Dossier inexistant" +err_cd = "Dossier non créé" +err_no_file = "Fichier manquant" +err_cr_file = "Fichier non créé" +err_bad_uri = "URI non compatible" +err_post_sep = "Séparateur manquant" +err_post_head = "Erreur dans l'Entête" +err_post_empty = "Article vide" # Warnings warn_no_dom = "Domaine non configuré"