Preparing articles databases

This commit is contained in:
Cyrille L 2023-09-25 14:55:51 +02:00
parent de5c93c668
commit 7a1eca5aa0
15 changed files with 200 additions and 27 deletions

View File

@ -7,10 +7,13 @@ Tyto - Littérateur
- 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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -56,6 +56,10 @@ 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é"