Preparing articles values, multiple targets with 'all'

This commit is contained in:
Cyrille L 2023-09-29 18:26:12 +02:00
parent 26d18ac4b8
commit 5b4356d229
11 changed files with 131 additions and 46 deletions

View File

@ -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

View File

@ -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 <echolib+tyto@a-lec.org>

View File

@ -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 #

View File

@ -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 is "all"
if args.multiple:
multiple_targets
return
target.endswith(".tyto") and post.is_article(target)
# 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)

View File

@ -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)

View File

@ -40,6 +40,7 @@ targets = (
"domain",
"domains",
"title", "date", "about", "mail", "tags", "lang", "server",
"all",
)
force_options = ("--force", "-F")