Preparing articles values, multiple targets with 'all'
This commit is contained in:
parent
26d18ac4b8
commit
5b4356d229
|
@ -9,10 +9,16 @@ Tyto - Littérateur
|
||||||
|
|
||||||
# CURRENTLY IN DEV !
|
# 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]
|
## [1.9.10]
|
||||||
- cleaner code
|
- cleaner code
|
||||||
- start/stop domain by user
|
- start/stop domain by user
|
||||||
- User directories check/create when domain activated
|
- User directories check/create when domain activated
|
||||||
|
- Check install configuration
|
||||||
|
|
||||||
## [1.9.9]
|
## [1.9.9]
|
||||||
- cleaner code with new check/update domain process
|
- cleaner code with new check/update domain process
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Version: 1.9.10
|
# Version: 1.9.11
|
||||||
# Updated: 2023-09-29 1695998917
|
# Updated: 2023-09-29 1696004712
|
||||||
# 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>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -49,10 +49,13 @@ def get_action():
|
||||||
# Target arguments #
|
# Target arguments #
|
||||||
#------------------#
|
#------------------#
|
||||||
def get_target():
|
def get_target():
|
||||||
global target
|
global target, multiple
|
||||||
try: target = sys.argv[2]
|
try: target = sys.argv[2]
|
||||||
except: target = ""
|
except: target = ""
|
||||||
|
|
||||||
|
multiple = False
|
||||||
|
if target == "all": multiple = True
|
||||||
|
|
||||||
|
|
||||||
#================================#
|
#================================#
|
||||||
# Searching options in arguments #
|
# Searching options in arguments #
|
||||||
|
|
|
@ -33,7 +33,19 @@
|
||||||
#--------------------------
|
#--------------------------
|
||||||
|
|
||||||
import sys
|
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 #
|
# Create user work domain directories #
|
||||||
#-------------------------------------------#
|
#-------------------------------------------#
|
||||||
def manage(action, target):
|
def manage(action, target):
|
||||||
# Load configuration and website lang
|
# target is "all"
|
||||||
domain.cf_update_values(False)
|
if args.multiple:
|
||||||
domain.ready()
|
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)
|
||||||
|
|
|
@ -36,6 +36,8 @@ import os, configparser
|
||||||
import domain, debug, tools, tyto
|
import domain, debug, tools, tyto
|
||||||
|
|
||||||
|
|
||||||
|
error = 0
|
||||||
|
|
||||||
#============================================#
|
#============================================#
|
||||||
# Check if current directory is in articles/ #
|
# Check if current directory is in articles/ #
|
||||||
# Check if article from target exists #
|
# Check if article from target exists #
|
||||||
|
@ -44,33 +46,85 @@ import domain, debug, tools, tyto
|
||||||
#--------------------------------------------#
|
#--------------------------------------------#
|
||||||
def is_article(target):
|
def is_article(target):
|
||||||
# User MUST be in articles/
|
# User MUST be in articles/
|
||||||
(os.getcwd() + "/").startswith(domain.wrk_articles) or \
|
domain.user_dir.startswith(domain.wrk_articles) or \
|
||||||
debug.out(2, "-> articles/", domain.cf_usr_articles, True, 2, True)
|
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
|
||||||
|
|
||||||
|
global error
|
||||||
|
|
||||||
# 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):
|
||||||
debug.out(20, "./, ../", target, True, 2, True)
|
debug.out(20, "./, ../", target, True, 2, False)
|
||||||
|
error = 20
|
||||||
|
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)
|
||||||
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)
|
# Article is a Tyto format and not empty (exit on errors)
|
||||||
is_tyto_format()
|
if not is_tyto_format():
|
||||||
|
return False
|
||||||
|
|
||||||
#
|
global uri_id, wrk_id, cf_uri, wrk_target
|
||||||
global uri_id, cf_uri
|
# Set post ID from...
|
||||||
|
uri_id = tools.get_filesum(uri, False) # ...URI
|
||||||
# Set post ID from URI
|
wrk_id = tools.get_filesum(uri, True) # ...CONTENTS
|
||||||
uri_id = tools.get_filesum(uri, False)
|
|
||||||
|
|
||||||
# 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/
|
||||||
|
wrk_target = uri.rsplit(domain.wrk_articles)[1]
|
||||||
|
|
||||||
# Load Database
|
# Load Database
|
||||||
db = cf_load() # True or False
|
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) #
|
# return True, or False if unused (yet) #
|
||||||
#---------------------------------------#
|
#---------------------------------------#
|
||||||
def cf_load():
|
def cf_load():
|
||||||
|
global cf
|
||||||
|
cf = False
|
||||||
|
|
||||||
if not os.path.exists(cf_uri):
|
if not os.path.exists(cf_uri):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
global cf
|
|
||||||
cf = configparser.ConfigParser()
|
cf = configparser.ConfigParser()
|
||||||
cf.read(cf_uri)
|
cf.read(cf_uri)
|
||||||
|
|
||||||
|
@ -100,29 +156,3 @@ def cf_valid():
|
||||||
|
|
||||||
print("post: chk_hash", chk_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)
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ targets = (
|
||||||
"domain",
|
"domain",
|
||||||
"domains",
|
"domains",
|
||||||
"title", "date", "about", "mail", "tags", "lang", "server",
|
"title", "date", "about", "mail", "tags", "lang", "server",
|
||||||
|
"all",
|
||||||
)
|
)
|
||||||
|
|
||||||
force_options = ("--force", "-F")
|
force_options = ("--force", "-F")
|
||||||
|
|
Loading…
Reference in New Issue