Added check process for block-codes

This commit is contained in:
Cyrille L 2023-10-01 11:35:20 +02:00
parent 171de8808c
commit 2a8cdf0084
11 changed files with 148 additions and 39 deletions

View File

@ -9,6 +9,9 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.14]
- added 'check' process on block-codes
## [1.9.13]
- Check: One-Line needed tags, titles
- Added first stats

View File

@ -8,6 +8,7 @@ tyto
```
## ToDo next (working on)
- check action
- 'check' action processes
- create template post database
- Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Version: 1.9.13
# Updated: 2023-10-01 1696117427
# Version: 1.9.14
# Updated: 2023-10-01 1696152727
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -75,20 +75,30 @@ def is_article(target):
print("pass", post.error, args.targets)
print("chk_date", chk_date)
print("post.stats_comments =", post.stats_comments)
#
#
#
print("Stats coms =", post.stats_tyto_coms, post.stats_html_coms)
print("Titles =", post.stats_titles)
#===========================================#
# Check full article contents (head + text) #
# In error case, exit or return if targetS #
#-------------------------------------------#
def valid(target):
targets = args.targets
# Target is a tyto article
# Target is a tyto article format
post.is_article(target) or tools.exit(targets, post.error)
# Head contents
# =============
# One Line targs in head_contents
post.error == 0 and ol_tags() or tools.exit(targets, post.error)
post.error == 0 and titles() or tools.exit(targets, post.error)
# Text article
# ============
post.error == 0 and bcodes() or tools.exit(targets, post.error)
post.error == 0 and titles() or tools.exit(targets, post.error)
#===========================================#
@ -98,9 +108,9 @@ def multiple_targets():
ready()
#==============#
# check header #===============================================================
#==============#
#=====================#
# check head contents #===============================================================
#=====================#
#======================#
# One Line needed tags #
#----------------------#
@ -167,7 +177,7 @@ def ol_tag_value(line, commas):
#===========================#
# Check if tag value is set #
# return True/False #
# Return True/False #
#---------------------------#
def is_ol_tag(tag, value):
if not value:
@ -178,9 +188,8 @@ def is_ol_tag(tag, value):
#======================================#
# Check validity date #
# set date of check (YYYY-MM-DD H:M:S) #
# Also set epoch date #
# Check if date id valid #
# Set date of check (YYYY-MM-DD H:M:S) #
# Return True/False #
#--------------------------------------#
def is_valid_date(date):
@ -195,9 +204,85 @@ def is_valid_date(date):
return False
#===============#
# check article #==============================================================
#===============#
#=====================#
# check text contents #========================================================
#=====================#
#=======================================#
# First process ! #
# Check if opened and closed tags match #
# Check if bcodes contents are indented #
# Count bcodes for stats #
# Remove bcodes lines (for next steps) #
# Create new post.text_contents #
# Return True/False #
#---------------------------------------#
def bcodes():
new_text_contents = ""
opened = closed = False
closed_bcodes_nbr = 0 # To compare with post.stats_bcodes
for ln, line in enumerate(post.text_contents.rsplit("\n"),
post.head_lines + 1):
# Opened tag
if line.startswith(post.bcodes[0]):
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln,
post.bcodes[0], post.bcodes[1]
), post.uri, True, 2, False)
return False
opened = True
post.stats_bcodes += 1
continue
# Close tag
elif line.startswith(post.bcodes[1]):
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln,
post.bcodes[0], post.bcodes[1]
), post.uri, True, 2, False)
return False
closed = True
closed_bcodes_nbr += 1
if not opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln,
post.bcodes[0], post.bcodes[1]
), post.uri, True, 2, False)
return False
# Contents must be indented
if opened and not closed:
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) %s..."%(ln, line[0:10]), post.uri, True, 2, False)
return False
# Create new string
if not opened and not closed:
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
# Check if tags are paired
if post.stats_bcodes != closed_bcodes_nbr:
post.error = \
debug.out(53, "%s ... %s"%(
post.bcodes[0], post.bcodes[1]
), post.uri, True, 2, False)
return False
post.text_contents = new_text_contents
return True
#============================#
# Check optional title tags #
# Count tyto + html comments #
@ -209,6 +294,7 @@ def titles():
if not line or line.isspace():
continue
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
if not line[3:]:
post.error = \
@ -216,12 +302,18 @@ def titles():
return False
post.stats_titles += 1
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
elif line[1].isdigit() and int(line[1]) >= 6:
post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
return False
# Count Tyto Comments
elif line.startswith("#"):
post.stats_tyto_coms += 1
# Count HTML comments
elif line.startswith(post.text_comments):
post.stats_comments += 1
post.stats_html_coms += 1
return True

View File

@ -91,6 +91,8 @@ def out(nbr, var, val, show, color, stop):
50 : langs.logs.err_date,
51 : langs.logs.err_post_data,
52 : langs.logs.err_post_title,
53 : langs.logs.err_post_paired,
54 : langs.logs.err_post_indent,
# WARNINGS (100-200)
100 : langs.logs.warn_no_dom,
101 : langs.logs.domain_created,

View File

@ -163,7 +163,9 @@ def cf_valid():
nositemap = "! NoSitemap" # Article will not be included in sitemap
# One Line needed
sep = "-----" # Splitter between header and article
sep = "-----" # Splitter between header and article
# Will replace "Fals" with title value
title = ("title:", False)
about = ("about:", False)
date = ("date:", False)
@ -173,6 +175,11 @@ author = ("author:", False)
# text_contents
# =============
# Start lines tags
bcodes = ("{{", "}}")
quotes = ("[[", "]]")
parags = ("((", "))")
# Comments
text_comments = (";;", "<!--")
html_comment = { text_comments[0] : "<!-- %s -->" }
@ -189,5 +196,7 @@ html_titles = {
# Statistics
# ==========
stats_comments = 0
stats_titles = 0
stats_tyto_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0

View File

@ -47,22 +47,24 @@ domain_srv = "URI du serveur"
# logs for debug
#---------------
# Errors
err_arg = "Argument invalide"
err_hole = "Dossier courant invalide"
err_date = "Date invalide"
err_lang = "Format de langue invalide"
err_dir = "Dossier non compatible"
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 = "Entête vide"
err_post_empty = "Article vide"
err_ini_file = "Configuration invalide"
err_post_data = "Donnée manquante"
err_post_title = "Titre invalide"
err_arg = "Argument invalide"
err_hole = "Dossier courant invalide"
err_date = "Date invalide"
err_lang = "Format de langue invalide"
err_dir = "Dossier non compatible"
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 = "Entête vide"
err_post_empty = "Article vide"
err_ini_file = "Configuration invalide"
err_post_data = "Donnée manquante"
err_post_title = "Titre invalide"
err_post_paired = "Marqueurs non apairés"
err_post_indent = "Ligne non indentée"
# Warnings
warn_no_dom = "Domaine non configuré"