Preparing articles databases
This commit is contained in:
parent
de5c93c668
commit
7a1eca5aa0
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -7,10 +7,13 @@ Tyto - Littérateur
|
||||||
- License:
|
- License:
|
||||||
- Documentation:
|
- Documentation:
|
||||||
|
|
||||||
## [1.9.1]
|
## [1.9.5]
|
||||||
- Auto update configuration domain
|
- Preparing post database
|
||||||
- Better managing configuration domain values
|
|
||||||
- Better checking if valid domain
|
## [1.9.4]
|
||||||
|
- Added start/strop action to activate (or deactivate) domain
|
||||||
|
- Directories creation for user working domain
|
||||||
|
- better log management for user
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
11
README.md
11
README.md
|
@ -7,10 +7,9 @@ This program can ve tested but not at all usable. Lots of work to do...
|
||||||
tyto
|
tyto
|
||||||
```
|
```
|
||||||
|
|
||||||
# Working on
|
## ToDo next (working on)
|
||||||
- Managing domain(s)
|
- check action
|
||||||
- - needs more checks to be validated
|
- user is in articles/ directory
|
||||||
- english logs translation file (French only, for now)
|
- target post exists and compatible
|
||||||
|
- create template post database
|
||||||
|
|
||||||
# Next
|
|
||||||
- Create all directories for valid domain
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Version: 1.9.4
|
# Version: 1.9.5
|
||||||
# Updated: 2023-09-25 1695630197
|
# Updated: 2023-09-25 1695637945
|
||||||
# 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.
|
@ -33,7 +33,7 @@
|
||||||
#--------------------------
|
#--------------------------
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import domain, langs, debug
|
import domain, langs, debug, post
|
||||||
|
|
||||||
|
|
||||||
#===========================================#
|
#===========================================#
|
||||||
|
@ -42,9 +42,8 @@ import domain, langs, debug
|
||||||
# Create user work domain directories #
|
# Create user work domain directories #
|
||||||
#-------------------------------------------#
|
#-------------------------------------------#
|
||||||
def manage(action, target):
|
def manage(action, target):
|
||||||
# Load domain configuration, update if needed, check if valid
|
# Load domain configuration (update it if needed), check if valid
|
||||||
if not domain.cf_valid():
|
domain.cf_valid() or debug.out(105, domain.name, domain.cf_uri, True, 1, True)
|
||||||
debug.out(105, domain.name, domain.cf_uri, True, 1, True)
|
target.endswith(".tyto") and post.is_article(target)
|
||||||
|
|
||||||
langs.load_website_lang()
|
langs.load_website_lang()
|
||||||
print("check:", action, target)
|
|
||||||
|
|
|
@ -82,6 +82,10 @@ def out(nbr, var, val, show, color, stop):
|
||||||
6 : langs.logs.err_no_dir,
|
6 : langs.logs.err_no_dir,
|
||||||
7 : langs.logs.err_cr_file,
|
7 : langs.logs.err_cr_file,
|
||||||
8 : langs.logs.err_lang,
|
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,
|
50 : langs.logs.err_date,
|
||||||
# WARNINGS (100-200)
|
# WARNINGS (100-200)
|
||||||
100 : langs.logs.warn_no_dom,
|
100 : langs.logs.warn_no_dom,
|
||||||
|
|
|
@ -57,6 +57,12 @@ def cf_load():
|
||||||
cf = configparser.ConfigParser()
|
cf = configparser.ConfigParser()
|
||||||
cf.read(cf_uri)
|
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 #
|
# Load User Domain Configuration file #
|
||||||
|
|
|
@ -31,3 +31,104 @@
|
||||||
# file functions:
|
# file functions:
|
||||||
# file program :
|
# 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)
|
||||||
|
|
|
@ -55,6 +55,8 @@ git_url = "https://git.a-lec.org/echolib/tyto-litterateur"
|
||||||
|
|
||||||
#===========================#
|
#===========================#
|
||||||
# Templates #==================================================
|
# Templates #==================================================
|
||||||
|
#===========================#
|
||||||
|
#===========================#
|
||||||
# Domain configuration file #
|
# Domain configuration file #
|
||||||
#---------------------------#
|
#---------------------------#
|
||||||
ini_domain = """[DOMAIN]
|
ini_domain = """[DOMAIN]
|
||||||
|
@ -173,8 +175,63 @@ conf =
|
||||||
root =
|
root =
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Domains list ini file
|
||||||
ini_domains_list = """[DOMAINS]
|
ini_domains_list = """[DOMAINS]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Domain keys that can be empty
|
# Domain keys that can be empty
|
||||||
opt_domain_keys = ("legals_url", "terms_url", "statuses_url")
|
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 = "-----"
|
||||||
|
|
Binary file not shown.
|
@ -47,15 +47,19 @@ domain_srv = "URI du serveur"
|
||||||
# logs for debug
|
# logs for debug
|
||||||
#---------------
|
#---------------
|
||||||
# Errors
|
# Errors
|
||||||
err_arg = "Argument invalide"
|
err_arg = "Argument invalide"
|
||||||
err_hole = "Dossier courant invalide"
|
err_hole = "Dossier courant invalide"
|
||||||
err_date = "Format de date invalide"
|
err_date = "Format de date invalide"
|
||||||
err_lang = "Format de langue invalide"
|
err_lang = "Format de langue invalide"
|
||||||
err_dir = "Dossier non compatible"
|
err_dir = "Dossier non compatible"
|
||||||
err_no_dir = "Dossier inexistant"
|
err_no_dir = "Dossier inexistant"
|
||||||
err_cd = "Dossier non créé"
|
err_cd = "Dossier non créé"
|
||||||
err_no_file = "Fichier manquant"
|
err_no_file = "Fichier manquant"
|
||||||
err_cr_file = "Fichier non créé"
|
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
|
# Warnings
|
||||||
warn_no_dom = "Domaine non configuré"
|
warn_no_dom = "Domaine non configuré"
|
||||||
|
|
Loading…
Reference in New Issue