[1.9.27] - See changelog

This commit is contained in:
Cyrille L 2023-10-26 18:59:56 +02:00
parent 3406954067
commit b9a41bb8bb
9 changed files with 400 additions and 152 deletions

View File

@ -9,6 +9,15 @@ Tyto - Littérateur
# CURRENTLY IN DEV ! # CURRENTLY IN DEV !
## [1.9.27]
- fix when target article .tyto is missing
- Nearly all stats are added in DB from modules
- Only used tags and stats (or nearly) are added to DB
- cleaner code
- check:
- - added words_tags (strong, italics...)
- - "all" target now ready
## [1.9.26] ## [1.9.26]
- user can indent titles in text - user can indent titles in text
- prepared words markers (strong, bolds) (some to add soon) - prepared words markers (strong, bolds) (some to add soon)

106
README.md
View File

@ -16,3 +16,109 @@ tyto
- stats for article words - stats for article words
- Translate logs in english ! - Translate logs in english !
## Exemple d'article
```
Pour ne pas inclure cet article dans les sitemaps :
! NoSitemap
title: tests d'un article
about: À propos de cet article de test
tags: hello, my big world,here
author: echolib
date: 2023-09-30
logo: /testimg/hi.png
link: Lien à reprendre
https://
Text alternatif
link: Réservez ici
https://
Billets
file: voir l'image
PNGs/hi.png
Un png !
image: MyCar
PNGs/hi.png
Un png !
file: télécharger ce fichier
@PDFs/hello.pdf
Un PDF !
abbr: css
Cascading StyleSheet
CSS
abbr: HTML
Hyper Text Markup Langage
HTML
code: test
@RAWS/test.py
Du code à afficher en HTML
-----
# La ligne suivante est un commentaire HTML "<!-- Commentaire -->"
;; Commentaire
-> top
#1 Titre en h2
((
;; HTML comment
# Show logo set in header, using '_image:logo'
_image:logo tyto_logo w=120
))
-> newtitle
#2 Titre en h3 décalé dans le texte
((
Parce que c'est *_bien_* comme /_présentation_/ *_erreur
ou pas, si fermé_*
/_ ;_echolib_; _/
))
((
Il /_faut_/ ce __Lien à reprendre et __Réservez ici et --télécharger ce fichier
ou encore faire une ::css pour du ::HTML. __Réservez ici et --voir l'image
icode 1 : {_hello(_world_)_}, icode 2 : {_print("")_}
icode 3 : {_{__}_}, icode 4 : {_echo "Hello"_}
))
((
_image:MyCar
<: mylist
+ Item 1
++ Sub-Item 1
+++ Sub-Sub-item 1
==== >_top: Go to Top_<
==== >_top: Another anchor_<
:>
))
_code:test
{{
# Du code brut pour Tyto
{{
Un exemple de code
}}
}}
[[
["
;; A great quote here !
cite: Someone
date: 2023-10-13
book: A History
lang: EN
link: https://...
((
Here, i am
))
"]
]]
```

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Version: 1.9.26 # Version: 1.9.27
# Updated: 2023-10-18 1697613100 # Updated: 2023-10-18 1697613100
# Tyto - Littérateur # Tyto - Littérateur

View File

@ -58,7 +58,7 @@ def ready():
def manage(action, target): def manage(action, target):
# target is "all" # target is "all"
if args.targets: if args.targets:
multiple_targets multiple_targets()
return return
# target is not "all" # target is not "all"
@ -71,7 +71,9 @@ def manage(action, target):
# Also used with multiple (loop) # # Also used with multiple (loop) #
#--------------------------------# #--------------------------------#
def is_article(target): def is_article(target):
valid(target) or tools.exit(targets, post.error) if not valid(target):
if targets: return
else: sys.exit(post.error)
# When all is OK # When all is OK
# Will create post database, but now, show some values # Will create post database, but now, show some values
@ -83,7 +85,7 @@ def is_article(target):
print() print()
""" """
# Write to post database # Write to post database
cf_update_values() cf_update_values("after")
#===========================================# #===========================================#
@ -95,7 +97,9 @@ def valid(target):
targets = args.targets targets = args.targets
# Target is a tyto article format # Target is a tyto article format
post.is_article(target) or tools.exit(targets, post.error) if not post.is_article(target):
return False
if not post.do_chk: if not post.do_chk:
post.error = debug.out(210, post.chk_date, post.uri, True, 0, False) post.error = debug.out(210, post.chk_date, post.uri, True, 0, False)
return False return False
@ -104,6 +108,9 @@ def valid(target):
tools.create_file(post.cf_uri, post.ini_template) tools.create_file(post.cf_uri, post.ini_template)
post.cf_load() post.cf_load()
# Add statistics to post database
cf_update_values("before")
global css global css
css = domain.css css = domain.css
@ -141,6 +148,10 @@ def valid(target):
post.error == 0 and anchors_links() \ post.error == 0 and anchors_links() \
or tools.exit(targets, post.error) or tools.exit(targets, post.error)
# Words Tags (Strong, bold...)
post.error == 0 and words_tags() \
or tools.exit(targets, post.error)
# Quotes # Quotes
post.error == 0 and sl_ptags(post.ptags[1]) \ post.error == 0 and sl_ptags(post.ptags[1]) \
or tools.exit(targets, post.error) or tools.exit(targets, post.error)
@ -165,6 +176,7 @@ def valid(target):
#-------------------------------------------# #-------------------------------------------#
def multiple_targets(): def multiple_targets():
ready() ready()
post.find_tyto_article()
#=====================# #=====================#
@ -174,16 +186,22 @@ def multiple_targets():
# One Line needed tags # # One Line needed tags #
#----------------------# #----------------------#
def ol_tags(): def ol_tags():
global sitemap, src_uri global sitemap, src_uri, stats_tyto_head_coms
global stats_total_files
stats_total_files = 0
sitemap = "True" sitemap = "True"
stats_tyto_head_coms = 0
for ln, line in enumerate(headers, 1): for ln, line in enumerate(headers, 1):
# Optional one line markers # Optional one line markers
if line.startswith("#"): if line.startswith("#"):
post.stats_tyto_head_coms += 1 stats_tyto_head_coms += 1
post.cf_set("STATS_HEADERS", "tyto_coms", str(stats_tyto_head_coms))
elif line.startswith(post.nositemap): elif line.startswith(post.nositemap):
sitemap = "False" post.cf_set("HEADERS", "sitemap", "False")
elif line.startswith(post.logo[0]): elif line.startswith(post.logo[0]):
if not post.logo[1]: if not post.logo[1]:
post.logo = (post.logo[0], ol_tag_value(line, False)) post.logo = (post.logo[0], ol_tag_value(line, False))
@ -197,29 +215,36 @@ def ol_tags():
# =========================== # ===========================
elif not post.title[1] and line.startswith(post.title[0]): elif not post.title[1] and line.startswith(post.title[0]):
post.title = (post.title[0], ol_tag_value(line, False)) post.title = (post.title[0], ol_tag_value(line, False))
if not is_ol_tag(post.title[0], post.title[1]):
return False
post.cf_set("HEADERS", "title", post.title[1])
elif not post.about[1] and line.startswith(post.about[0]): elif not post.about[1] and line.startswith(post.about[0]):
post.about = (post.about[0], ol_tag_value(line, False)) post.about = (post.about[0], ol_tag_value(line, False))
if not is_ol_tag(post.about[0], post.about[1]):
return False
post.cf_set("HEADERS", "about", post.about[1])
elif not post.date[1] and line.startswith(post.date[0]): elif not post.date[1] and line.startswith(post.date[0]):
post.date = (post.date[0], ol_tag_value(line, False)) post.date = (post.date[0], ol_tag_value(line, False))
if not is_ol_tag(post.date[0], post.date[1]):
return False
elif not is_valid_date(post.date[1]):
return False
post.date = ("date:", tools.local_date(post.date[1]))
post.cf_set("HEADERS", "date", post.date[1])
elif not post.author[1] and line.startswith(post.author[0]): elif not post.author[1] and line.startswith(post.author[0]):
post.author = (post.author[0], ol_tag_value(line, True)) post.author = (post.author[0], ol_tag_value(line, True))
if not is_ol_tag(post.author[0], post.author[1]):
return False
post.cf_set("HEADERS", "authors", post.author[1])
elif not post.tags[1] and line.startswith(post.tags[0]): elif not post.tags[1] and line.startswith(post.tags[0]):
post.tags = (post.tags[0], ol_tag_value(line, True)) post.tags = (post.tags[0], ol_tag_value(line, True))
if not is_ol_tag(post.tags[0], post.tags[1]):
return False
# Sets are done from loop post.cf_set("HEADERS", "tags", post.tags[1])
# Check if tag value exists
# =========================
if not is_ol_tag(post.date[0], post.date[1]): return False
if not is_valid_date(post.date[1]): return False
if not is_ol_tag(post.title[0], post.title[1]): return False
if not is_ol_tag(post.about[0], post.about[1]): return False
if not is_ol_tag(post.author[0], post.author[1]): return False
if not is_ol_tag(post.tags[0], post.tags[1]): return False
# Default domain logo for this post # Default domain logo for this post
if not post.logo[1]: if not post.logo[1]:
@ -273,6 +298,7 @@ def is_valid_date(date):
try: try:
parse(date) parse(date)
chk_date = tools.nowdate() chk_date = tools.nowdate()
post.cf_set("CHECK", "date", chk_date)
return True return True
except: except:
post.error = debug.out(50, "%s"%date, post.uri, True, 2, False) post.error = debug.out(50, "%s"%date, post.uri, True, 2, False)
@ -293,13 +319,19 @@ def ml_tags():
continue continue
if line.startswith(post.ml_tags): if line.startswith(post.ml_tags):
tag = line.rsplit(":")[0] + ":" tag_name = line.rsplit(":")[0]
tag = tag_name + ":"
post.ml_tags_stats[tag] = post.ml_tags_stats[tag] + 1 post.ml_tags_stats[tag] = post.ml_tags_stats[tag] + 1
if not ml_tag_values(ln, tag, post.ml_tags_stats[tag]): if not ml_tag_values(ln, tag, post.ml_tags_stats[tag]):
return False return False
c = 2 c = 2
post.cf_set("STATS_HEADERS",
"%ss"%tag_name,
str(post.ml_tags_stats[tag])
)
continue continue
return True return True
@ -375,6 +407,7 @@ def ml_tag_values(ln, tag, stats):
if tag == post.ml_tags[0]: if tag == post.ml_tags[0]:
section = "LINKS" section = "LINKS"
post.stats_text_links += post.text_contents.count(tyto_value) post.stats_text_links += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "links", str(post.stats_text_links))
html_value = tyto.a_link%( html_value = tyto.a_link%(
value2, "%s link"%css, "%%s", value3, value1 value2, "%s link"%css, "%%s", value3, value1
) )
@ -383,6 +416,7 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[2]: elif tag == post.ml_tags[2]:
section = "FILES" section = "FILES"
post.stats_text_files += post.text_contents.count(tyto_value) post.stats_text_files += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "files", str(post.stats_text_files))
html_value = tyto.a_link%( html_value = tyto.a_link%(
value2, "%s file"%css, "%%s", value3, value1 value2, "%s file"%css, "%%s", value3, value1
) )
@ -391,6 +425,7 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[1]: elif tag == post.ml_tags[1]:
section = "IMAGES" section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value) post.stats_text_images += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "images", str(post.stats_text_images))
html_value = tyto.image_link%( html_value = tyto.image_link%(
value2, "%%s image", "%%s", value2, "%%s image", "%%s",
value3, value3, "%%s" value3, value3, "%%s"
@ -400,6 +435,7 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[3]: elif tag == post.ml_tags[3]:
section = "RAWS" section = "RAWS"
post.stats_text_raws += post.text_contents.count(tyto_value) post.stats_text_raws += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "raws", str(post.stats_text_raws))
html_value = "<!-- %s -->"%value3 html_value = "<!-- %s -->"%value3
with open(value2_uri, "r") as f: with open(value2_uri, "r") as f:
html_value = "%s\n%s"%(html_value, f.read()) html_value = "%s\n%s"%(html_value, f.read())
@ -410,6 +446,7 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[4]: elif tag == post.ml_tags[4]:
section = "CODES" section = "CODES"
post.stats_text_codes += post.text_contents.count(tyto_value) post.stats_text_codes += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "codes", str(post.stats_text_codes))
htmlbcode = "<!-- %s -->"%value3 htmlbcode = "<!-- %s -->"%value3
with open(value2_uri, "r") as f: with open(value2_uri, "r") as f:
for ln, line in enumerate(f.read().rsplit("\n"), 1): for ln, line in enumerate(f.read().rsplit("\n"), 1):
@ -424,10 +461,12 @@ def ml_tag_values(ln, tag, stats):
elif tag == post.ml_tags[5]: elif tag == post.ml_tags[5]:
section = "ABBRS" section = "ABBRS"
post.stats_text_abbrs += post.text_contents.count(tyto_value) post.stats_text_abbrs += post.text_contents.count(tyto_value)
post.cf_set("STATS_TEXTS", "abbrs", str(post.stats_text_abbrs))
html_value = '<abbr class="%s" title="%s">%s</abbr>'%( html_value = '<abbr class="%s" title="%s">%s</abbr>'%(
css, value2, value3 css, value2, value3
) )
# Set in post database, source and HTML content
post.cf_set(section, "%s_%s"%(tag.replace(":", ""), stats), tyto_value) post.cf_set(section, "%s_%s"%(tag.replace(":", ""), stats), tyto_value)
post.cf_set(section, "html_%s"%stats, html_value) post.cf_set(section, "html_%s"%stats, html_value)
@ -442,7 +481,7 @@ def ml_tag_values(ln, tag, stats):
# - ... for post directory # # - ... for post directory #
#--------------------------------# #--------------------------------#
def is_value2_file_exists(ln, tag, val2): def is_value2_file_exists(ln, tag, val2):
global value2, src_uri, value2_uri global value2, src_uri, value2_uri, stats_total_files
# uri "@..." means generic folders # uri "@..." means generic folders
if val2[0].startswith("@"): if val2[0].startswith("@"):
@ -477,8 +516,9 @@ def is_value2_file_exists(ln, tag, val2):
return False return False
# Add file to [SOURCE_FILES] post database # Add file to [SOURCE_FILES] post database
post.stats_total_files += 1 stats_total_files += 1
post.cf_set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri) post.cf_set("SOURCE_FILES", "file_%s"%stats_total_files, src_uri)
post.cf_set("STATS_FILE", "files", str(stats_total_files))
return True return True
@ -548,6 +588,10 @@ def sl_ptags(markers):
index0 = index1 = -1 index0 = index1 = -1
tag_ln = "" tag_ln = ""
post.ptags_stats[markers[2]] += 1 post.ptags_stats[markers[2]] += 1
post.cf_set("STATS_TEXTS",
markers[2],
str(post.ptags_stats[markers[2]])
)
# paragraphs don't need html wip yet # paragraphs don't need html wip yet
if markers[2] in ("parags", "divs"): if markers[2] in ("parags", "divs"):
@ -594,7 +638,6 @@ def sl_ptags(markers):
), post.uri, True,2, False) ), post.uri, True,2, False)
return False return False
print(": stats", markers[2], post.ptags_stats[markers[2]])
return True return True
@ -609,6 +652,7 @@ def sl_ptags(markers):
def icodes(): def icodes():
global texts global texts
stats_text_icodes = 0
markers = post.words_markers markers = post.words_markers
for ln, line in enumerate(texts, post.head_lines + 1): for ln, line in enumerate(texts, post.head_lines + 1):
@ -652,7 +696,7 @@ def icodes():
icodes = re.findall('%s(.*?)%s'%(markers[0][4], markers[0][5]), line) icodes = re.findall('%s(.*?)%s'%(markers[0][4], markers[0][5]), line)
for icode in icodes: for icode in icodes:
post.stats_text_icodes += 1 stats_text_icodes += 1
icnew = markers[0][4] + icode + markers[0][5] icnew = markers[0][4] + icode + markers[0][5]
line = line.replace(icnew, "") line = line.replace(icnew, "")
@ -660,12 +704,12 @@ def icodes():
html_val = icnew.replace(markers[0][4], markers[0][2]%css) html_val = icnew.replace(markers[0][4], markers[0][2]%css)
post.cf_set( post.cf_set(
"ICODES", "ICODES",
"icode_%s"%post.stats_text_icodes, "icode_%s"%stats_text_icodes,
markers[0][0] + icode + markers[0][1] markers[0][0] + icode + markers[0][1]
) )
post.cf_set( post.cf_set(
"ICODES", "ICODES",
"html_%s"%post.stats_text_icodes, "html_%s"%stats_text_icodes,
html_val.replace(markers[0][5], markers[0][3]) html_val.replace(markers[0][5], markers[0][3])
) )
@ -675,7 +719,7 @@ def icodes():
icodes = re.findall('%s(.*?)%s'%(markers[1][4], markers[1][5]), line) icodes = re.findall('%s(.*?)%s'%(markers[1][4], markers[1][5]), line)
for icode in icodes: for icode in icodes:
post.stats_text_icodes += 1 stats_text_icodes += 1
icnew = markers[1][4] + icode + markers[1][5] icnew = markers[1][4] + icode + markers[1][5]
line = line.replace(icnew, "") line = line.replace(icnew, "")
@ -683,17 +727,19 @@ def icodes():
html_val = icnew.replace(markers[1][4], markers[1][2]%css) html_val = icnew.replace(markers[1][4], markers[1][2]%css)
post.cf_set( post.cf_set(
"ICODES", "ICODES",
"icode_%s"%post.stats_text_icodes, "icode_%s"%stats_text_icodes,
markers[1][0] + icode + markers[1][1] markers[1][0] + icode + markers[1][1]
) )
post.cf_set( post.cf_set(
"ICODES", "ICODES",
"html_%s"%post.stats_text_icodes, "html_%s"%stats_text_icodes,
html_val.replace(markers[1][5], markers[1][3]) html_val.replace(markers[1][5], markers[1][3])
) )
texts[ln - 1 - post.head_lines] = line texts[ln - 1 - post.head_lines] = line
post.cf_set("STATS_TEXTS", "icodes", str(stats_text_icodes))
return True return True
@ -705,10 +751,14 @@ def icodes():
# Return True/False # # Return True/False #
#----------------------------# #----------------------------#
def sl_stags(): def sl_stags():
global anchors_ids global anchors_ids, stats_tyto_text_coms
anchors_ids = () # Uniq anchors IDs
for ln, line in enumerate(texts, post.head_lines + 1): anchors_ids = () # Uniq anchors IDs
stats_tyto_text_coms = stats_html_coms = 0
stats_text_anc_ids = 0
stats_titles = 0
for ln, line in enumerate(texts, post.head_lines + 1):
linels = line.lstrip() linels = line.lstrip()
# legacy Tyto Titles # legacy Tyto Titles
@ -724,40 +774,43 @@ def sl_stags():
debug.out(52, "%s) %s..."%(ln, linels[0:10]), post.uri, True, 1, False) debug.out(52, "%s) %s..."%(ln, linels[0:10]), post.uri, True, 1, False)
return False return False
post.stats_titles += 1 stats_titles += 1
post.cf_set("STATS_TEXTS", "titles", str(stats_titles))
# Create html value for this title in database # Create html value for this title in database
post.cf_set( post.cf_set(
"TITLES", "TITLES",
"title_%s"%post.stats_titles, "title_%s"%stats_titles,
line line
) )
post.cf_set( post.cf_set(
"TITLES", "TITLES",
"html_%s"%post.stats_titles, "html_%s"%stats_titles,
post.html_titles[linels[0:2]]%(css, line[3:]) post.html_titles[linels[0:2]]%(css, line[3:])
) )
# Count Tyto Comments # Count Tyto Comments
elif line.lstrip().startswith("#"): elif line.lstrip().startswith("#"):
post.stats_tyto_text_coms += 1 stats_tyto_text_coms += 1
post.cf_set("STATS_TEXTS", "tyto_coms", str(stats_tyto_text_coms))
# Count HTML comments # Count HTML comments
elif line.lstrip().startswith(post.text_comments): elif line.lstrip().startswith(post.text_comments):
post.stats_html_coms += 1 stats_html_coms += 1
post.cf_set("STATS_TEXTS", "html_coms", str(stats_html_coms))
# Convert tyto commented marker to HTML # Convert tyto commented marker to HTML
if line.lstrip().startswith(post.text_comments[0]): if line.lstrip().startswith(post.text_comments[0]):
real_com = line.lstrip()[3:] real_com = line.lstrip()[3:]
post.cf_set( post.cf_set(
"COMMENTS", "COMMENTS",
"comm_%s"%post.stats_html_coms, "comm_%s"%stats_html_coms,
line.lstrip() line.lstrip()
) )
post.cf_set( post.cf_set(
"COMMENTS", "COMMENTS",
"html_%s"%post.stats_html_coms, "html_%s"%stats_html_coms,
'<!-- %s -->'%real_com '<!-- %s -->'%real_com
) )
@ -782,16 +835,17 @@ def sl_stags():
# Anchor source # Anchor source
elif line.lstrip().startswith(post.anchor_target[0]): elif line.lstrip().startswith(post.anchor_target[0]):
anchor_id = tools.get_css(line, post.anchor_target[0]) anchor_id = tools.get_css(line, post.anchor_target[0])
if anchor_id in anchors_ids: if anchor_id in anchors_ids:
post_error = \ post_error = \
debug.out(54, '%s) "%s"'%(ln, anchor_id), post.uri, True, 2, False) debug.out(54, '%s) "%s"'%(ln, anchor_id), post.uri, True, 2, False)
return False return False
anchors_ids = (*anchors_ids, anchor_id) anchors_ids = (*anchors_ids, anchor_id)
post.stats_text_anc_ids += 1
stats_text_anc_ids += 1
post.cf_set("STATS_TEXTS", "anc_targets", str(stats_text_anc_ids))
return True return True
#===========================# #===========================#
@ -800,6 +854,8 @@ def sl_stags():
#---------------------------# #---------------------------#
def anchors_links(): def anchors_links():
markers = post.anchor_link markers = post.anchor_link
stats_text_anc_links = 0
for ln, line in enumerate(texts, post.head_lines + 1): for ln, line in enumerate(texts, post.head_lines + 1):
anc_links = re.findall('%s(.*?)%s'%(markers[0], markers[1]), line) anc_links = re.findall('%s(.*?)%s'%(markers[0], markers[1]), line)
if not anc_links: if not anc_links:
@ -823,13 +879,13 @@ def anchors_links():
return False return False
# Set to post Database # Set to post Database
post.stats_text_anc_links += 1 stats_text_anc_links += 1
post.cf_set("ANCHORS", post.cf_set("ANCHORS",
"anchor_%s"%post.stats_text_anc_links, "anchor_%s"%stats_text_anc_links,
post.anchor_set[0]%anc_link post.anchor_set[0]%anc_link
) )
post.cf_set("ANCHORS", post.cf_set("ANCHORS",
"html_%s"%post.stats_text_anc_links, "html_%s"%stats_text_anc_links,
post.anchor_set[1]%(css, anc_id, anc_title) post.anchor_set[1]%(css, anc_id, anc_title)
) )
else: else:
@ -837,103 +893,157 @@ def anchors_links():
debug.out(51, '%s) "-> %s"'%(ln, anc_id), post.uri, True, 2, False) debug.out(51, '%s) "-> %s"'%(ln, anc_id), post.uri, True, 2, False)
return False return False
post.cf_set("STATS_TEXTS", "anc_links", str(stats_text_anc_links))
return True return True
#======================================#
# Count and return sub indices in text #
#--------------------------------------#
def find_sub_indices(full, sub):
return [index for index in range(len(full)) if full.startswith(sub, index)]
#================================================#
# From position of sub tag: return article line #
# When error, to let user know real line article #
# char is indice tag position #
#------------------------------------------------#
def find_line_sub(char):
for fc, lc, ln in lines_chars:
if fc <= char and char <= lc:
return ln
#======================================= #=======================================
# CHeck paired words marks # # CHeck paired words tagss #
# Count for stats # # Count for tags stats + words #
# ! No neeed to create HTML in post db # # ! No neeed to create HTML in post db #
#--------------------------------------# #--------------------------------------#
def words_tags(): def words_tags():
print("words_tags: soon...") global lines_chars
# Create List lines number and number of characters in line
# (In error case, show line number)
old_len = 0 # len(line)
lines_chars = (())
stats_text_chars = 0
for ln, line in enumerate(texts, post.head_lines + 1):
stats_text_chars = stats_text_chars + len(line)
lines_chars = lines_chars + ((old_len, stats_text_chars, ln),)
old_len = stats_text_chars
post.cf_set("STATS_TEXTS", "chars", str(stats_text_chars))
# Create article in block text format
# Also count words written
block_texts = ''
for line in texts:
block_texts = block_texts + line
post.cf_set("STATS_TEXTS",
"words",
str(sum(1 for w in block_texts.split()))
)
# For each word tag, get position indicies
for i, tags in enumerate(post.words_tags):
indices_o = find_sub_indices(block_texts, tags[0])
indices_c = find_sub_indices(block_texts, tags[1])
if not indices_o and not indices_c:
continue
# Count and compare opened and closes tags numbers
len_o = len(indices_o)
len_c = len(indices_c)
# Not paired tags
if len_o != len_c:
post.error = \
debug.out(53, "%s %s, %s %s"%(
len_o, tags[0],
len_c, tags[1]
), post.uri, True, 2, False)
return False
# Test if tags are opened > closed
for n in range(len_o):
# Current opened must be smaller than current closed
if indices_o[n] > indices_c[n]:
post.error = \
debug.out(53, '%s) "%s...%s"'%(
find_line_sub(indices_o[n]), tags[1], tags[0]
), post.uri, True, 2, False)
return False
# Other mismatches opens/closed tags
else:
# Current closed must be higher than opened + 1
try:
if indices_c[n] > indices_o[n+1]:
post.error = \
debug.out(53, '%s) "%s...%s"'%(
find_line_sub(indices_c[n]), tags[0], tags[0]
), post.uri, True, 2, False)
return False
except:
continue
# Add tag statistic to post database
post.cf_set("STATS_TEXTS", tags[2], str(len_o))
return True
#==================================#
# Update post configuration file #
# part: #
# before > first generic datas #
# after > after all check modules #
#----------------------------------#
def cf_update_values(part):
# Generic known first datas, before check modules
if part == "before":
post.cf_set("DOMAIN", "name", domain.name)
post.cf_set("CHECK", "static", str(domain.static))
post.cf_set("CHECK", "hash", post.wrk_id)
#================================# # [FILE]
# Update post configuration file # post.cf_set("FILE", "id", post.uri_id)
#--------------------------------# post.cf_set("FILE", "uri", post.uri)
def cf_update_values(): post.cf_set("FILE", "db", post.cf_uri)
post.date = ("date:", tools.local_date(post.date[1])) post.cf_set("FILE", "target", post.wrk_target)
post.cf_set("DOMAIN", "name", domain.name) # [WIP]
# -----
post.cf_set("WIP", "hash", post.wip_hash)
post.cf_set("WIP", "date", post.wip_date)
post.cf_set("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf_set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
# [FILE] # [WWW]
post.cf_set("FILE", "id", post.uri_id) # -----
post.cf_set("FILE", "uri", post.uri) post.cf_set("WWW", "hash", post.www_hash)
post.cf_set("FILE", "db", post.cf_uri) post.cf_set("WWW", "date", post.www_date)
post.cf_set("FILE", "target", post.wrk_target) post.cf_set("WWW", "web", "%s%s"%(domain.www_url, post.wrk_target))
post.cf_set("WWW", "uri", "%s%s"%(domain.www, post.wrk_target))
# [HEADERS] # Stats (these, cause i want them first)
# --------- post.cf_set("STATS_FILE", "lines", str(post.lines))
post.cf_set("HEADERS", "title", post.title[1]) post.cf_set("STATS_HEADERS", "lines", str(post.head_lines))
post.cf_set("HEADERS", "about", post.about[1]) post.cf_set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf_set("HEADERS", "date", post.date[1])
post.cf_set("HEADERS", "tags", post.tags[1])
post.cf_set("HEADERS", "authors", post.author[1])
post.cf_set("HEADERS", "sitemap", str(sitemap))
# [check] return
# Datas after check modules
# -------------------------
# [CHECK]
# ------- # -------
post.cf_set("CHECK", "hash", post.wrk_id)
post.cf_set("CHECK", "date", chk_date)
post.cf_set("CHECK", "static", str(domain.static))
post.cf_set("CHECK", "errors", "False") post.cf_set("CHECK", "errors", "False")
# [WIP]
# -----
post.cf_set("WIP", "hash", post.wip_hash)
post.cf_set("WIP", "date", post.wip_date)
post.cf_set("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf_set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
# [WWW]
# -----
post.cf_set("WWW", "hash", post.www_hash)
post.cf_set("WWW", "date", post.www_date)
post.cf_set("WWW", "web", "%s%s"%(domain.www_url, post.wrk_target))
post.cf_set("WWW", "uri", "%s%s"%(domain.www, post.wrk_target))
# [STATS_FILE] # [STATS_FILE]
# ------------ # ------------
stats_tyto_all_coms = post.stats_tyto_text_coms + post.stats_tyto_head_coms stats_tyto_all_coms = stats_tyto_text_coms + stats_tyto_head_coms
post.cf_set("STATS_FILE", "lines", str(post.lines)) stats_tyto_all_coms > 0 and \
post.cf_set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms)) post.cf_set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf_set("STATS_FILE", "files", str(post.stats_total_files))
# [STATS_HEADERS]
# ---------------
post.cf_set("STATS_HEADERS", "lines", str(post.head_lines))
post.cf_set("STATS_HEADERS", "tyto_coms", str(post.stats_tyto_head_coms))
post.cf_set("STATS_HEADERS", "links", str(post.ml_tags_stats["link:"]))
post.cf_set("STATS_HEADERS", "files", str(post.ml_tags_stats["file:"]))
post.cf_set("STATS_HEADERS", "images", str(post.ml_tags_stats["image:"]))
post.cf_set("STATS_HEADERS", "abbrs", str(post.ml_tags_stats["abbr:"]))
post.cf_set("STATS_HEADERS", "codes", str(post.ml_tags_stats["code:"]))
post.cf_set("STATS_HEADERS", "raws", str(post.ml_tags_stats["raw:"]))
# [STATS_TEXTS]
# -------------
post.cf_set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf_set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
post.cf_set("STATS_TEXTS", "html_coms", str(post.stats_html_coms))
post.cf_set("STATS_TEXTS", "anc_targets", str(post.stats_text_anc_ids))
post.cf_set("STATS_TEXTS", "anc_links", str(post.stats_text_anc_links))
post.cf_set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf_set("STATS_TEXTS", "parags", str(post.ptags_stats["parags"]))
post.cf_set("STATS_TEXTS", "divs", str(post.ptags_stats["divs"]))
post.cf_set("STATS_TEXTS", "bcodes", str(post.ptags_stats["bcodes"]))
post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))
post.cf_set("STATS_TEXTS", "quotes", str(post.ptags_stats["quotes"]))
post.cf_set("STATS_TEXTS", "lists", str(post.ptags_stats["lists"]))
# Founds from header tags
post.cf_set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf_set("STATS_TEXTS", "files", str(post.stats_text_files))
post.cf_set("STATS_TEXTS", "images", str(post.stats_text_images))
post.cf_set("STATS_TEXTS", "abbrs", str(post.stats_text_abbrs))
post.cf_set("STATS_TEXTS", "icodes", str(post.stats_text_icodes))
post.cf_set("STATS_TEXTS", "codes", str(post.stats_text_codes))
post.cf_set("STATS_TEXTS", "raws", str(post.stats_text_raws))
# ============================ # ============================
# Write new values in database # Write new values in database

View File

@ -33,7 +33,7 @@
#-------------------------- #--------------------------
import os, sys, configparser import os, sys, configparser
import args, domain, debug, tools, tyto import args, domain, debug, tools, tyto, check
error = 0 error = 0
@ -47,6 +47,8 @@ write = False # When updating database in cf_set(), cf_write()
# load database # # load database #
#--------------------------------------------# #--------------------------------------------#
def is_article(target): def is_article(target):
global error
# User MUST be in articles/ # User MUST be in articles/
domain.user_dir.startswith(domain.wrk_articles) or \ domain.user_dir.startswith(domain.wrk_articles) or \
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True) debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
@ -58,7 +60,9 @@ def is_article(target):
# Article exists # Article exists
global uri global uri
uri = os.path.join(domain.user_dir, target) if args.targets: cur_dir = domain.wrk_articles
else: cur_dir = domain.user_dir
uri = os.path.join(cur_dir, target)
if not os.path.exists(uri): if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False) error = debug.out(5, "False", uri, True, 2, False)
return False return False
@ -82,6 +86,7 @@ def is_article(target):
cf_load() cf_load()
cf_datas() cf_datas()
compare_datas() compare_datas()
return True return True
@ -239,21 +244,40 @@ def cf_write():
write = False write = False
#====================================================#
# Search and return .tyto file in domain root folder #
#----------------------------------------------------#
def find_tyto_article():
nothere = (domain.wrk_files, domain.wrk_images)
os.chdir(domain.wrk_articles)
for root,dirs,files in os.walk(domain.wrk_articles):
if root.startswith(nothere):
continue
for f in files:
if f.endswith(".tyto"):
f_uri = os.path.join(root, f)
target = f_uri.rsplit(domain.wrk_articles)[1]
args.action == "check" and check.is_article(target)
#======# #======#
# MAIN #======================================================================= # MAIN #=======================================================================
#======# #======#
# Statistics # Statistics
# ========== # ==========
stats_tyto_head_coms = 0
stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_bcodes_lines = 0 stats_bcodes_lines = 0
stats_bcodes = 0
stats_quotes = 0 stats_quotes = 0
stats_parags = 0 stats_parags = 0
stats_lists = 0 stats_lists = 0
stats_divs = 0 stats_divs = 0
stats_links = 0 stats_links = 0
stats_images = 0 stats_images = 0
stats_files = 0 stats_files = 0
@ -261,17 +285,12 @@ stats_raws = 0
stats_codes = 0 stats_codes = 0
stats_abbrs = 0 stats_abbrs = 0
stats_total_files = 0
stats_text_anc_ids = 0
stats_text_anc_links = 0
stats_text_links = 0 stats_text_links = 0
stats_text_files = 0 stats_text_files = 0
stats_text_images = 0 stats_text_images = 0
stats_text_abbrs = 0 stats_text_abbrs = 0
stats_text_codes = 0 stats_text_codes = 0
stats_text_raws = 0 stats_text_raws = 0
stats_text_icodes = 0
# head_contents # head_contents
@ -288,7 +307,7 @@ about = ("about:", False)
date = ("date:", False) date = ("date:", False)
tags = ("tags:", False) tags = ("tags:", False)
author = ("author:", False) author = ("author:", False)
logo = ("logo:", False) # optional logo = ("logo:", False) # optional
# Multiple lines (3) markers # Multiple lines (3) markers
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:") ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
@ -310,7 +329,7 @@ ml_tags_stats = {
} }
# Markers with uri in value2 # Markers with uri in value2
value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3], ml_tags[4]) value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3], ml_tags[4])
value2s_ext_uris = ("http", "ftp") value2s_ext_uris = ("http", "ftp")
# text_contents # text_contents
@ -359,6 +378,7 @@ words_tags = (
("~_", "_~", "dels", '<del class="%s">', '</del>'), ("~_", "_~", "dels", '<del class="%s">', '</del>'),
("._", "_.", "underlines", '<u class="%s">', '</u>'), ("._", "_.", "underlines", '<u class="%s">', '</u>'),
("/_", "_/", "emphasis", '<em class="%s">', '</em>'), ("/_", "_/", "emphasis", '<em class="%s">', '</em>'),
(";_", "_;", "italics", '<i class="%s">', '</i>'),
) )
# Specifics convertion # Specifics convertion

View File

@ -49,6 +49,7 @@ import tyto, tools, post, domain
def bcode(lines): def bcode(lines):
lines = lines.rsplit("\n") lines = lines.rsplit("\n")
html_bcode = "" html_bcode = ""
for ln, line in enumerate(lines): for ln, line in enumerate(lines):
if ln == 0: # Opened marker if ln == 0: # Opened marker
css = tools.get_css(line, post.ptags[0][0]) css = tools.get_css(line, post.ptags[0][0])
@ -69,7 +70,9 @@ def bcode(lines):
else: html_bcode = "%s\n%s"%(html_bcode, line) else: html_bcode = "%s\n%s"%(html_bcode, line)
html_bcode = tyto.code_bcode%(css, html_bcode) html_bcode = tyto.code_bcode%(css, html_bcode)
#print(html_bcode)
post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))
return html_bcode return html_bcode