Added check process for block-codes
This commit is contained in:
parent
171de8808c
commit
2a8cdf0084
|
@ -9,6 +9,9 @@ Tyto - Littérateur
|
||||||
|
|
||||||
# CURRENTLY IN DEV !
|
# CURRENTLY IN DEV !
|
||||||
|
|
||||||
|
## [1.9.14]
|
||||||
|
- added 'check' process on block-codes
|
||||||
|
|
||||||
## [1.9.13]
|
## [1.9.13]
|
||||||
- Check: One-Line needed tags, titles
|
- Check: One-Line needed tags, titles
|
||||||
- Added first stats
|
- Added first stats
|
||||||
|
|
|
@ -8,6 +8,7 @@ tyto
|
||||||
```
|
```
|
||||||
|
|
||||||
## ToDo next (working on)
|
## ToDo next (working on)
|
||||||
- check action
|
- 'check' action processes
|
||||||
- create template post database
|
- create template post database
|
||||||
|
- Translate logs in english !
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Version: 1.9.13
|
# Version: 1.9.14
|
||||||
# Updated: 2023-10-01 1696117427
|
# Updated: 2023-10-01 1696152727
|
||||||
# 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.
|
@ -75,19 +75,29 @@ def is_article(target):
|
||||||
|
|
||||||
print("pass", post.error, args.targets)
|
print("pass", post.error, args.targets)
|
||||||
print("chk_date", chk_date)
|
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):
|
def valid(target):
|
||||||
targets = args.targets
|
targets = args.targets
|
||||||
|
|
||||||
# Target is a tyto article
|
# Target is a tyto article format
|
||||||
post.is_article(target) or tools.exit(targets, post.error)
|
post.is_article(target) or tools.exit(targets, post.error)
|
||||||
|
|
||||||
|
# Head contents
|
||||||
|
# =============
|
||||||
# One Line targs in head_contents
|
# One Line targs in head_contents
|
||||||
post.error == 0 and ol_tags() or tools.exit(targets, post.error)
|
post.error == 0 and ol_tags() 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)
|
post.error == 0 and titles() or tools.exit(targets, post.error)
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,9 +108,9 @@ def multiple_targets():
|
||||||
ready()
|
ready()
|
||||||
|
|
||||||
|
|
||||||
#==============#
|
#=====================#
|
||||||
# check header #===============================================================
|
# check head contents #===============================================================
|
||||||
#==============#
|
#=====================#
|
||||||
#======================#
|
#======================#
|
||||||
# One Line needed tags #
|
# One Line needed tags #
|
||||||
#----------------------#
|
#----------------------#
|
||||||
|
@ -167,7 +177,7 @@ def ol_tag_value(line, commas):
|
||||||
|
|
||||||
#===========================#
|
#===========================#
|
||||||
# Check if tag value is set #
|
# Check if tag value is set #
|
||||||
# return True/False #
|
# Return True/False #
|
||||||
#---------------------------#
|
#---------------------------#
|
||||||
def is_ol_tag(tag, value):
|
def is_ol_tag(tag, value):
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -178,9 +188,8 @@ def is_ol_tag(tag, value):
|
||||||
|
|
||||||
|
|
||||||
#======================================#
|
#======================================#
|
||||||
# Check validity date #
|
# Check if date id valid #
|
||||||
# set date of check (YYYY-MM-DD H:M:S) #
|
# Set date of check (YYYY-MM-DD H:M:S) #
|
||||||
# Also set epoch date #
|
|
||||||
# Return True/False #
|
# Return True/False #
|
||||||
#--------------------------------------#
|
#--------------------------------------#
|
||||||
def is_valid_date(date):
|
def is_valid_date(date):
|
||||||
|
@ -195,9 +204,85 @@ def is_valid_date(date):
|
||||||
return False
|
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 #
|
# Check optional title tags #
|
||||||
# Count tyto + html comments #
|
# Count tyto + html comments #
|
||||||
|
@ -209,6 +294,7 @@ def titles():
|
||||||
if not line or line.isspace():
|
if not line or line.isspace():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# legacy Tyto Titles
|
||||||
if line.startswith(post.tyto_titles):
|
if line.startswith(post.tyto_titles):
|
||||||
if not line[3:]:
|
if not line[3:]:
|
||||||
post.error = \
|
post.error = \
|
||||||
|
@ -216,12 +302,18 @@ def titles():
|
||||||
return False
|
return False
|
||||||
post.stats_titles += 1
|
post.stats_titles += 1
|
||||||
|
|
||||||
|
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
|
||||||
elif line[1].isdigit() and int(line[1]) >= 6:
|
elif line[1].isdigit() and int(line[1]) >= 6:
|
||||||
post.error = \
|
post.error = \
|
||||||
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
|
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Count Tyto Comments
|
||||||
|
elif line.startswith("#"):
|
||||||
|
post.stats_tyto_coms += 1
|
||||||
|
|
||||||
|
# Count HTML comments
|
||||||
elif line.startswith(post.text_comments):
|
elif line.startswith(post.text_comments):
|
||||||
post.stats_comments += 1
|
post.stats_html_coms += 1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -91,6 +91,8 @@ def out(nbr, var, val, show, color, stop):
|
||||||
50 : langs.logs.err_date,
|
50 : langs.logs.err_date,
|
||||||
51 : langs.logs.err_post_data,
|
51 : langs.logs.err_post_data,
|
||||||
52 : langs.logs.err_post_title,
|
52 : langs.logs.err_post_title,
|
||||||
|
53 : langs.logs.err_post_paired,
|
||||||
|
54 : langs.logs.err_post_indent,
|
||||||
# WARNINGS (100-200)
|
# WARNINGS (100-200)
|
||||||
100 : langs.logs.warn_no_dom,
|
100 : langs.logs.warn_no_dom,
|
||||||
101 : langs.logs.domain_created,
|
101 : langs.logs.domain_created,
|
||||||
|
|
|
@ -164,6 +164,8 @@ nositemap = "! NoSitemap" # Article will not be included in sitemap
|
||||||
|
|
||||||
# One Line needed
|
# One Line needed
|
||||||
sep = "-----" # Splitter between header and article
|
sep = "-----" # Splitter between header and article
|
||||||
|
|
||||||
|
# Will replace "Fals" with title value
|
||||||
title = ("title:", False)
|
title = ("title:", False)
|
||||||
about = ("about:", False)
|
about = ("about:", False)
|
||||||
date = ("date:", False)
|
date = ("date:", False)
|
||||||
|
@ -173,6 +175,11 @@ author = ("author:", False)
|
||||||
|
|
||||||
# text_contents
|
# text_contents
|
||||||
# =============
|
# =============
|
||||||
|
# Start lines tags
|
||||||
|
bcodes = ("{{", "}}")
|
||||||
|
quotes = ("[[", "]]")
|
||||||
|
parags = ("((", "))")
|
||||||
|
|
||||||
# Comments
|
# Comments
|
||||||
text_comments = (";;", "<!--")
|
text_comments = (";;", "<!--")
|
||||||
html_comment = { text_comments[0] : "<!-- %s -->" }
|
html_comment = { text_comments[0] : "<!-- %s -->" }
|
||||||
|
@ -189,5 +196,7 @@ html_titles = {
|
||||||
|
|
||||||
# Statistics
|
# Statistics
|
||||||
# ==========
|
# ==========
|
||||||
stats_comments = 0
|
stats_tyto_coms = 0
|
||||||
|
stats_html_coms = 0
|
||||||
stats_titles = 0
|
stats_titles = 0
|
||||||
|
stats_bcodes = 0
|
||||||
|
|
Binary file not shown.
|
@ -63,6 +63,8 @@ err_post_empty = "Article vide"
|
||||||
err_ini_file = "Configuration invalide"
|
err_ini_file = "Configuration invalide"
|
||||||
err_post_data = "Donnée manquante"
|
err_post_data = "Donnée manquante"
|
||||||
err_post_title = "Titre invalide"
|
err_post_title = "Titre invalide"
|
||||||
|
err_post_paired = "Marqueurs non apairés"
|
||||||
|
err_post_indent = "Ligne non indentée"
|
||||||
|
|
||||||
# Warnings
|
# Warnings
|
||||||
warn_no_dom = "Domaine non configuré"
|
warn_no_dom = "Domaine non configuré"
|
||||||
|
|
Loading…
Reference in New Issue