diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c500c3..117ad39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,16 @@ Tyto - Littérateur # CURRENTLY IN DEV ! +## [1.9.11] +- Preparing for multi-targets with "all" +- check if article is a .tyto format +- preparing values for articles + ## [1.9.10] - cleaner code - start/stop domain by user - User directories check/create when domain activated +- Check install configuration ## [1.9.9] - cleaner code with new check/update domain process diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index abf0518..099edab 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Version: 1.9.10 -# Updated: 2023-09-29 1695998917 +# Version: 1.9.11 +# Updated: 2023-09-29 1696004712 # Tyto - Littérateur # Copyright (C) 2023 Cyrille Louarn diff --git a/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc index 3515f88..17afd7e 100644 Binary files a/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc and b/src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc differ 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 fb38194..bc9ecf4 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__/domain.cpython-311.pyc b/src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc index 2598c44..6e05990 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 be29656..235c5b2 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 32be386..4807808 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/args.py b/src/var/lib/tyto/program/args.py index f6cc65c..39b9730 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -49,10 +49,13 @@ def get_action(): # Target arguments # #------------------# def get_target(): - global target + global target, multiple try: target = sys.argv[2] except: target = "" + multiple = False + if target == "all": multiple = True + #================================# # Searching options in arguments # diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index cac1d5f..6cbabc6 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -33,7 +33,19 @@ #-------------------------- import sys -import domain, langs, debug, post, tools +import args, domain, langs, debug, post, tools + + +#=====================================# +# Check domain # +# Load domain configuration file # +# Update it if needed, and set values # +# Load website lang # +# Domain must be activated # +#-------------------------------------# +def ready(): + domain.cf_update_values(False) + domain.ready() #===========================================# @@ -42,9 +54,42 @@ import domain, langs, debug, post, tools # Create user work domain directories # #-------------------------------------------# def manage(action, target): - # Load configuration and website lang - domain.cf_update_values(False) - domain.ready() - - target.endswith(".tyto") and post.is_article(target) + # target is "all" + if args.multiple: + multiple_targets + return + + # target is not "all" + ready() + if target.endswith(".tyto"): + is_article(target) + + +#================================# +# Check article(S) # +# Also used with multiple (loop) # +#--------------------------------# +def is_article(target): + if not post.is_article(target): + if args.multiple: + return # Let other articles pass + + sys.exit(post.error) + + header_contents() + + +#===========================================# +# # Create a loop to get all .tyto articles # +#-------------------------------------------# +def multiple_targets(): + ready() + +#=======================# +# 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) diff --git a/src/var/lib/tyto/program/post.py b/src/var/lib/tyto/program/post.py index 6bd45f8..0c809cf 100644 --- a/src/var/lib/tyto/program/post.py +++ b/src/var/lib/tyto/program/post.py @@ -36,6 +36,8 @@ import os, configparser import domain, debug, tools, tyto +error = 0 + #============================================# # Check if current directory is in articles/ # # Check if article from target exists # @@ -44,33 +46,85 @@ import domain, debug, tools, tyto #--------------------------------------------# def is_article(target): # User MUST be in articles/ - (os.getcwd() + "/").startswith(domain.wrk_articles) or \ - debug.out(2, "-> articles/", domain.cf_usr_articles, True, 2, True) + domain.user_dir.startswith(domain.wrk_articles) or \ + debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True) + + global error # Target URI most be from legacy directory or not begins with if target.startswith(tyto.notarget): - debug.out(20, "./, ../", target, True, 2, True) + debug.out(20, "./, ../", target, True, 2, False) + error = 20 + return False # Article exists global uri uri = os.path.join(domain.wrk_articles, target) - os.path.exists(uri) or debug.out(5, "False", uri, True, 2, True) + if not os.path.exists(uri): + debug.out(5, "False", uri, True, 2, False) + error = 5 + return False # Article is a Tyto format and not empty (exit on errors) - is_tyto_format() + if not is_tyto_format(): + return False - # - global uri_id, cf_uri - - # Set post ID from URI - uri_id = tools.get_filesum(uri, 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 db = cf_load() # True or False + return True + + +#=========================================# +# Article is in Tyto format and not empty # +# Return True or False # +#-----------------------------------------# +def is_tyto_format(): + global head_contents, text_contents, error + + 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) + + if not separator: + debug.out(21, tyto.post_sep, uri, True, 2, False) + error = 21 + return False + + if not head_contents: + debug.out(22, "?", uri, True, 2, False) + error = 22 + return False + + if not text_contents: + debug.out(23, "?", uri, True, 2, False) + error = 23 + return False + + return True #=======================================# @@ -78,10 +132,12 @@ def is_article(target): # return True, or False if unused (yet) # #---------------------------------------# def cf_load(): + global cf + cf = False + if not os.path.exists(cf_uri): return False - global cf cf = configparser.ConfigParser() cf.read(cf_uri) @@ -100,29 +156,3 @@ def cf_valid(): 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 1bcc1c0..d06818f 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -40,6 +40,7 @@ targets = ( "domain", "domains", "title", "date", "about", "mail", "tags", "lang", "server", + "all", ) force_options = ("--force", "-F")