[1.9.22] - new bcodes, icodes process done first in text article

This commit is contained in:
Cyrille L 2023-10-11 17:52:15 +02:00
parent ff4ecf7d6f
commit 34afac630b
18 changed files with 682 additions and 347 deletions

View File

@ -9,6 +9,13 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.22] (Not Yet push)
- new bcode process (html prepared for wip)
- new post database management values
- new icode process (html prepared for wip)
- bcodes and icodes are FIRST processed in text article
- lots more
## [1.9.21]
- new indentation (3 spaces)
- added 'raw:' marker

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Version: 1.9.21
# Updated: 2023-10-08 1696756865
# Version: 1.9.22
# Updated: 2023-10-11 1697039459
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>

View File

@ -32,10 +32,10 @@
# file program :
#--------------------------
import sys, os
import sys, os, re
from dateutil.parser import parse
import args, domain, langs, debug, post, tools, tyto
import args, domain, langs, debug, post, tools, tyto, wip
#=====================================#
@ -71,14 +71,12 @@ def manage(action, target):
# Also used with multiple (loop) #
#--------------------------------#
def is_article(target):
valid(target)
valid(target) or tools.exit(targets, post.error)
# When all is OK
# Will create post database, but now, show some values
print("chk_date", chk_date)
print()
print("Final text_contents string")
for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines):
print("Final texts string")
for ln, line in enumerate(texts, post.head_lines + 1):
print(">", ln, line)
print()
@ -91,38 +89,48 @@ def is_article(target):
# In error case, exit or return if targetS #
#-------------------------------------------#
def valid(target):
global targets
targets = args.targets
# Target is a tyto article format
post.is_article(target) or tools.exit(targets, post.error)
if not post.do_chk:
post.error = debug.out(210, post.chk_date, post.uri, True, 0, False)
return False
# Reset post database (Old values are prepared)
tools.create_file(post.cf_uri, post.ini_template)
post.cf_load()
global css
css = domain.cf.get("WEBSITE", "css")
css = domain.css
global headers, texts
headers = post.head_contents.rsplit("\n")
texts = post.text_contents.rsplit("\n")
# =============
# Head contents
# =============
# One Line targs in head_contents
post.error == 0 and ol_tags() or tools.exit(targets, post.error)
#Multiple and optional Tags on 3 linges
post.error == 0 and ml_tags() or tools.exit(targets, post.error)
texts = post.text_contents.rsplit("\n")
# ============
# Text article
# ============
# Process bcodes and icodes first to protect their contents
post.error == 0 and bcodes() or tools.exit(targets, post.error)
post.error == 0 and icodes() 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)
# Multiple and optional Tags on 3 linges
post.error == 0 and ml_tags() or tools.exit(targets, post.error)
# ============
# Text article
# ============
# Start Lines
# -----------
# Paired tags.
post.error == 0 and sl_paired("bcodes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("quotes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("parags") or tools.exit(targets, post.error)
# Single tags
post.error == 0 and titles() or tools.exit(targets, post.error)
post.error == 0 and sl_tags() or tools.exit(targets, post.error)
return True
#===========================================#
@ -144,14 +152,23 @@ def ol_tags():
sitemap = "True"
for ln, line in enumerate(headers, 1):
if not line or line.isspace(): continue
# Optional one line markers
if line.startswith("#"):
post.stats_tyto_head_coms += 1
continue
elif line.startswith(post.nositemap):
sitemap = "False"
elif line.startswith(post.logo[0]):
if not post.logo[1]:
post.logo = (post.logo[0], ol_tag_value(line, False))
logo_ln = ln
if is_value2_file_exists(logo_ln, "logo:", post.logo[1]):
src_uri = "%s%s"%(domain.www_url, src_uri)
else:
return False
# One Line tags (Must be set)
# ===========================
if 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))
elif not post.about[1] and line.startswith(post.about[0]):
@ -166,17 +183,7 @@ def ol_tags():
elif not post.tags[1] and line.startswith(post.tags[0]):
post.tags = (post.tags[0], ol_tag_value(line, True))
# Optional tags
# -------------
elif not post.logo[1] and line.startswith(post.logo[0]):
post.logo = (post.logo[0], ol_tag_value(line, False))
logo_ln = ln
elif line.startswith(post.nositemap):
sitemap = "False"
# Sets are done from loop
# Check if tag value exists
# =========================
@ -188,14 +195,10 @@ def ol_tags():
if not is_ol_tag(post.tags[0], post.tags[1]): return False
# Default domain logo for this post
src_uri = "%stemplate/%s"%(domain.www_url, domain.logo)
# logo is set with specific uri
if is_value2_file_exists(logo_ln, "logo:", post.logo[1]):
src_uri = "%s%s"%(domain.www_url, src_uri)
else:
return False
post.logo = (post.logo[0], src_uri)
post.cf.set("HEADERS", "logo", src_uri)
if not post.logo[1]:
src_uri = "%stemplate/%s"%(domain.www_url, domain.logo)
post.logo = (post.logo[0], src_uri)
post.cf_set("HEADERS", "logo", src_uri)
return True
@ -255,8 +258,6 @@ def is_valid_date(date):
# Tags are stric start line #
#----------------------------#
def ml_tags():
#global value1
c = 0 # Continue for next x lines, as tags are 3 lines values
for ln, line in enumerate(headers):
@ -302,12 +303,12 @@ def ml_tag_values(ln, tag, stats):
# value1 must not starts or contains:o
elif value1.startswith("_"):
debug.out(56, "%s) '_...'"%(ln+1), post.uri, True, 2, False)
post.error = debug.out(56, "%s) '_...'"%(ln+1), post.uri, True, 2, False)
return False
# Specific for image: logo name is reserved
elif tag == post.ml_tags[1] and value1 == "logo":
debug.out(56, "%s) 'logo'"%(ln+1), post.uri, True, 2, False)
post.error = debug.out(56, "%s) 'logo'"%(ln+1), post.uri, True, 2, False)
return False
# value2
@ -350,24 +351,25 @@ def ml_tag_values(ln, tag, stats):
if tag == post.ml_tags[0]:
section = "LINKS"
post.stats_text_links += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
html_value = tyto.a_link%(
value2, "%s link"%css, "%%s", value3, value1
)
# file:
elif tag == post.ml_tags[2]:
section = "FILES"
post.stats_text_files += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_file" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
html_value = tyto.a_link%(
value2, "%s file"%css, "%%s", value3, value1
)
# image:
elif tag == post.ml_tags[1]:
section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, "%%s", "%%s", value3, "%%s"
html_value = tyto.image_link%(
value2, "%%s image", "%%s",
value3, value3, "%%s"
)
# raw: (content file converted to base64)
@ -386,18 +388,15 @@ def ml_tag_values(ln, tag, stats):
post.stats_text_codes += post.text_contents.count(tyto_value)
htmlbcode = "<!-- %s -->"%value3
with open(value2_uri, "r") as f:
for line in f.read().rsplit("\n"):
for ln, line in enumerate(f.read().rsplit("\n"), 1):
line = tools.convert_html_signs(line)
line = '<li class="%s_blockcode">%s</li>'%(domain.css, line)
line = tyto.code_line%(ln, line)
htmlbcode = "%s\n%s"%(htmlbcode, line)
html_value = tyto.pre_bcode%(
domain.css, domain.css, domain.css,
htmlbcode
)
print()
print(html_value)
print()
html_value = tyto.code_bcode%(css, htmlbcode)
#print()
#print(html_value)
#print()
html_value = tools.b64_convert("encode", html_value)
# abbr:
@ -405,11 +404,11 @@ def ml_tag_values(ln, tag, stats):
section = "ABBRS"
post.stats_text_abbrs += post.text_contents.count(tyto_value)
html_value = '<abbr class="%s" title="%s">%s</abbr>'%(
domain.css, value2, value3
css, value2, value3
)
post.cf.set(section, link_var, tyto_value)
post.cf.set(section, html_var, html_value)
post.cf_set(section, link_var, tyto_value)
post.cf_set(section, html_var, html_value)
return True
@ -458,7 +457,7 @@ def is_value2_file_exists(ln, tag, val2):
# Add file to [SOURCE_FILES] post database
post.stats_total_files += 1
post.cf.set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri)
post.cf_set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri)
return True
@ -466,99 +465,181 @@ def is_value2_file_exists(ln, tag, val2):
#=====================#
# check text contents #========================================================
#=====================#
#========================================#
# First process ! #
# Used for bvodes, quotes, parags #
# Check if opened and closed tags match #
# Check if contents in tags are indented #
# Count tags for stats #
# Remove bcodes, quotes lines #
# - Create new post.text_contents #
# Return True/False #
#----------------------------------------#
def sl_paired(markers):
#=======================================#
# bcodes: first process ! #
# Check if opened and closed tags match #
# Count bcodes for stats #
# Remove bcodes lines #
# - Create new post "texts" contents #
# Return True/False #
#---------------------------------------#
def bcodes():
global texts
markers = post.bcodes
index0 = index1 = -1
new_text_contents = ""
opened = closed = in_tag = False
stats_opened = stats_closed = 0
tags = ()
if markers == "bcodes" : tags = post.bcodes
elif markers == "quotes" : tags = post.quotes
elif markers == "parags" : tags = post.parags
# loop lines in text_contents
for ln, line in enumerate(texts, post.head_lines + 1):
# Tag was closed, but not in_tag content line
if closed and in_tag:
in_tag = False
# Tag is opened
if line.startswith(tags[0]):
# Tag was already opened
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# check next line if exists or is a closed tag
try:
next_line = post.contents.rsplit("\n")[ln]
if next_line.startswith(tags[1]):
if index0 >= 0 :
#print(">>>", ln, line)
bcode = "%s\n%s"%(bcode, line)
texts[ln - 1 - post.head_lines] = ""
# Opened mark
if line.lstrip().startswith(markers[0]):
# Mark was opened yet
if index0 >= 0:
# at the same position
if line.index(markers[0][0]) == index0:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
except:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
opened = in_tag = True
closed = False
stats_opened += 1
# Tag is closed
if line.startswith(tags[1]):
# Tag was already closed
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
closed = True
opened = False
stats_closed += 1
if in_tag:
# Contents must be indented
if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) '\t'%s..."%(
ln+1, line[0:10]
debug.out(53, '%s...%s) "%s"'%(
tag_ln, ln, markers[1]
), post.uri, True, 2, False)
return False
line = ""
continue
index0 = line.index(markers[0][0])
tag_ln = ln
bcode = line
#print(">>>", ln, line)
texts[ln - 1 - post.head_lines] = ""
# Create new string, removing in_tag line if in bcodes or quotes
if markers in post.raw_contents:
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
# Closed mark
if line.lstrip().startswith(markers[1]):
if index0 < 0:
post.error = \
debug.out(53, '%s) "%s"...'%(
ln, markers[0]
), post.uri, True, 2, False)
return False
index1 = line.index(markers[1][0])
# at same position as opened
if index1 == index0:
index0 = index1 = -1
tag_ln = ""
post.stats_bcodes += 1
# create ini values for this bcode
var_name = "bcode_%s"%post.stats_bcodes
val_raws = tools.b64_convert("encode", bcode)
var_html = "html_%s"%post.stats_bcodes
val_html = tools.b64_convert("encode", wip.bcode(bcode))
post.cf_set("BCODES", var_name, val_raws)
post.cf_set("BCODES", var_html, val_html)
# bcode not opened, but closed tag found
elif index0 < 0:
tag_ln = ln
# Check if markers match
# ----------------------
if index1 >= 0 and index0 < 0:
post.error = \
debug.out(53, '%s) "%s"...'%(tag_ln, markers[0]), post.uri, True,2, False)
return False
if index0 >= 0 and index1 < 0:
post.error = \
debug.out(53, '%s) ..."%s"'%(tag_ln, markers[1]), post.uri, True,2, False)
return False
if index0 != index1:
post.error = \
debug.out(53, '%s) "%s"..."%s"'%(
tag_ln, markers[0], markers[1]
), post.uri, True,2, False)
return False
return True
#
# icodes (SAME LINE)
# Check if opened and closed markers match #
#
def icodes():
global texts
markers = post.icodes
for ln, line in enumerate(texts, post.head_lines + 1):
# Search for opened, closed markers
# markers cannot be at same position on line
m0 = line.find(markers[0])
m1 = line.find(markers[1])
if m0 == m1:
continue
texts = new_text_contents.rsplit("\n")
# Simple 3 cases errors
# ---------------------
# First marker is a closed one
if m1 < m0:
post.error = \
debug.out(53, '%s) "%s"..."%s"'%(
ln, markers[1], markers[0]
), post.uri, True,2, False)
return False
# First marker but unused closed one
if m0 >= 0 and m1 == -1:
post.error = \
debug.out(53, '%s) ..."%s"'%(
ln, markers[1]
), post.uri, True,2, False)
return False
# Last marker but unused opened one
elif m1 >= 0 and m0 == -1:
post.error = \
debug.out(53, '%s) "%s"...'%(
ln, markers[0]
), post.uri, True,2, False)
return False
if post.words_markers[0][0] in line:
line = line.replace(post.words_markers[0][0], post.words_markers[0][4])
line = line.replace(post.words_markers[0][1], post.words_markers[0][5])
icodes = re.findall('%s(.*?)%s'%(
post.words_markers[0][4], post.words_markers[0][5]
), line)
# Create post.stats
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
for icode in icodes:
post.stats_text_icodes += 1
icnew = post.words_markers[0][4] + icode + post.words_markers[0][5]
line = line.replace(icnew, "")
# Set HTML [ICODES] to post database
icode_var = "icode_%s"%post.stats_text_icodes
icleg = post.words_markers[0][0] + icode + post.words_markers[0][1]
html_var = "html_%s"%post.stats_text_icodes
html_val = icnew.replace(post.words_markers[0][4],
post.words_markers[0][2]%css)
html_val = html_val.replace(post.words_markers[0][5],
post.words_markers[0][3])
post.cf_set("ICODES", icode_var, icleg)
post.cf_set("ICODES", html_var, html_val)
line = line.replace(post.words_markers[1][0], post.words_markers[1][4])
line = line.replace(post.words_markers[1][1], post.words_markers[1][5])
icodes = re.findall('%s(.*?)%s'%(
post.words_markers[1][4], post.words_markers[1][5]
), line)
for icode in icodes:
post.stats_text_icodes += 1
icnew = post.words_markers[1][4] + icode + post.words_markers[1][5]
line = line.replace(icnew, "")
# Set HTML [ICODES] to post database
icode_var = "icode_%s"%post.stats_text_icodes
icleg = post.words_markers[1][0] + icode + post.words_markers[1][1]
html_var = "html_%s"%post.stats_text_icodes
html_val = icnew.replace(post.words_markers[1][4],
post.words_markers[1][2]%css)
html_val = html_val.replace(post.words_markers[1][5],
post.words_markers[1][3])
post.cf_set("ICODES", icode_var, icleg)
post.cf_set("ICODES", html_var, html_val)
texts[ln - 1 - post.head_lines] = line
return True
@ -568,7 +649,7 @@ def sl_paired(markers):
# Add stat for _image:logo #
# Return True/False #
#----------------------------#
def titles():
def sl_tags():
for ln, line in enumerate(texts, post.head_lines + 1):
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
@ -587,13 +668,13 @@ def titles():
# Create html value for this title in database
link_var = "title_%s"%post.stats_titles
post.cf.set("TITLES", link_var, line)
post.cf_set("TITLES", link_var, line)
html_var = "html_%s"%post.stats_titles
mark = line[0:2]
title = line[3:]
html_val = post.html_titles[mark]%(domain.css, title)
post.cf.set("TITLES", html_var, html_val)
html_val = post.html_titles[mark]%(css, title)
post.cf_set("TITLES", html_var, html_val)
# Count Tyto Comments
elif line.lstrip().startswith("#"):
@ -606,9 +687,9 @@ def titles():
if line.lstrip().startswith(post.text_comments[0]):
real_com = line.lstrip()[3:]
link_var = "comm_%s"%post.stats_html_coms
post.cf.set("COMMENTS", link_var, line.lstrip())
post.cf_set("COMMENTS", link_var, line.lstrip())
html_var = "html_%s"%post.stats_html_coms
post.cf.set("COMMENTS", html_var, '<!-- %s -->'%real_com)
post.cf_set("COMMENTS", html_var, '<!-- %s -->'%real_com)
# Add stat + html for [IMAGES] when user wants to show logo in post
@ -617,12 +698,13 @@ def titles():
link_var = "image_%s"%(post.ml_tags_stats["image:"] + 1)
link_val = "_image:logo"
html_var = "html_%s"%(post.ml_tags_stats["image:"] + 1)
html_val = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
post.logo[1], "%%s", "%%s", post.title[1], "%%s"
html_val = tyto.image_link%(
post.logo[1], "post_logo image", "%%s",
post.title[1], post.title[1], "%%s"
)
post.cf.set("IMAGES", link_var, link_val)
post.cf.set("IMAGES", html_var, html_val)
post.cf_set("IMAGES", link_var, link_val)
post.cf_set("IMAGES", html_var, html_val)
return True
@ -632,56 +714,79 @@ def titles():
def cf_update_values():
post.date = ("date:", tools.local_date(post.date[1]))
post.cf.set("DOMAIN", "name", domain.name)
post.cf_set("DOMAIN", "name", domain.name)
post.cf.set("FILE", "id", post.uri_id)
post.cf.set("FILE", "uri", post.uri)
post.cf.set("FILE", "db", post.cf_uri)
post.cf.set("FILE", "target", post.wrk_target)
# [FILE]
post.cf_set("FILE", "id", post.uri_id)
post.cf_set("FILE", "uri", post.uri)
post.cf_set("FILE", "db", post.cf_uri)
post.cf_set("FILE", "target", post.wrk_target)
post.cf.set("HEADERS", "title", post.title[1])
post.cf.set("HEADERS", "about", post.about[1])
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))
# [HEADERS]
# ---------
post.cf_set("HEADERS", "title", post.title[1])
post.cf_set("HEADERS", "about", post.about[1])
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))
post.cf.set("CHECK", "hash", post.wrk_id)
post.cf.set("CHECK", "date", chk_date)
post.cf.set("CHECK", "static", str(domain.static))
# [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("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf.set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
# [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))
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))
# [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_tyto_all_coms = post.stats_tyto_text_coms + post.stats_tyto_head_coms
post.cf.set("STATS_FILE", "lines", str(post.lines))
post.cf.set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf.set("STATS_FILE", "files", str(post.stats_total_files))
post.cf_set("STATS_FILE", "lines", str(post.lines))
post.cf_set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf_set("STATS_FILE", "files", str(post.stats_total_files))
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_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:"]))
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", "titles", str(post.stats_titles))
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", "codes", str(post.stats_text_codes))
post.cf.set("STATS_TEXTS", "raws", str(post.stats_text_raws))
# [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", "titles", str(post.stats_titles))
post.cf_set("STATS_TEXTS", "bcodes", str(post.stats_bcodes))
post.cf_set("STATS_TEXTS", "bcodes_lines", str(post.stats_bcodes_lines))
# 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))
with open(post.cf_uri, "w") as f:
post.cf.write(f)
# Write new values in database
post.cf_write()

View File

@ -113,6 +113,7 @@ def out(nbr, var, val, show, color, stop):
207 : langs.logs.updated_file,
208 : langs.logs.website_lang,
209 : langs.logs.domain_on,
210 : langs.logs.post_chk_yet,
255 : langs.logs.later,
}

View File

@ -178,7 +178,7 @@ def cf_create():
# Create section, set key if not exists #
# Ask yser when default is a key form and not value #
#---------------------------------------------------#
def cf_set_value(section, key, default):
def cf_set(section, key, default):
global new_val
try: new_val
except: new_val = False
@ -223,270 +223,270 @@ def cf_update_values(write):
# ========
global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no")
except: activated = cf_set("DOMAIN", "activated", "no")
cf_set_value("DOMAIN", "name", name)
cf_set("DOMAIN", "name", name)
title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
title = cf_set("DOMAIN", "title", "title")
date = cf_set("DOMAIN", "date", "date")
about = cf_set("DOMAIN", "about", "about")
mail = cf_set("DOMAIN", "mail", "mail")
tags = cf_set("DOMAIN", "tags", "tags")
license = cf_set("DOMAIN", "lincese", "")
if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url",
license = cf_set("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","")
license_url = cf_set("DOMAIN", "lincese_url","")
# Optional
global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
legals_url = cf_set("DOMAIN", "legals_url", "")
terms_url = cf_set("DOMAIN", "terms_url", "")
statuses_url = cf_set("DOMAIN", "statuses_url", "")
# [SERVER]
# ========
global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server")
srv = cf_set("SERVER", "root", "server")
if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server")
srv = cf_set("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name)
cf_set("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip)
cf_set("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www)
cf_set("SERVER", "www", www)
# [WIP_DIRS]
# ==========
global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl)
cf_set("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images)
cf_set("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files)
cf_set("WIP_DIRS", "files", wip_files)
# [WWW_DIRS]
# ==========
global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl)
cf_set("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images)
cf_set("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files)
cf_set("WWW_DIRS", "files", www_files)
# [WEBSITE]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "")
wip_url = cf_set("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
wip_url = cf_set("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "")
www_url = cf_set("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
www_url = cf_set("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "")
lang = cf_set("WEBSITE", "lang", "")
if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
lang = cf_set("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang()
langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "")
css = cf_set("WEBSITE", "css", "")
if not css:
css = cf_set_value("WEBSITE", "css", "tyto")
css = cf_set("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "")
sep = cf_set("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|")
sep = cf_set("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
except: article_code = cf_set("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
except: static = cf_set("WEBSITE", "static", "no")
# [WEBSITE_MODULES]
# =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
except: navbar = cf_set("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
sidebar_title = cf_set("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
sidebar_title = cf_set("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
sidebar_items = cf_set("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
sidebar_items = cf_set("WEBSITE_MODULES", "sidebar_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
rss_items = cf_set("WEBSITE_MODULES", "rss_items", "")
if not rss_items or not rss_items.isdigit():
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0")
rss_items = cf_set("WEBSITE_MODULES", "rss_items", "0")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
except: sitemaps = cf_set("WEBSITE_MODULES", "sitemaps", "yes")
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
favicon = cf_set("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
favicon = cf_set("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
logo = cf_set("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
logo = cf_set("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
styles = cf_set("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
styles = cf_set("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
rss = cf_set("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
rss = cf_set("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
stats = cf_set("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
stats = cf_set("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS]
# ===========
cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db)
cf_set("USER_DIRS", "root", wrk_dir)
cf_set("USER_DIRS", "articles", wrk_articles)
cf_set("USER_DIRS", "images", wrk_images)
cf_set("USER_DIRS", "files", wrk_files)
cf_set("USER_DIRS", "template", wrk_tpl)
cf_set("USER_DIRS", "modules", wrk_mods)
cf_set("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES]
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
cf_set("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
cf_set("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
cf_set("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES]
# ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
cf_set("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header)
cf_set("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
cf_set("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
cf_set("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
cf_set("USER_MODULES_FILES", "footer", wrk_footer)
# [WIP_FILES]
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon)
cf_set("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo)
cf_set("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles)
cf_set("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss)
cf_set("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats)
cf_set("WIP_FILES", "stats", wip_stats)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas)
cf_set("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header)
cf_set("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar)
cf_set("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
cf_set("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer)
cf_set("WIP_FILES", "footer", wip_footer)
# [WWW_FILES]
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon)
cf_set("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo)
cf_set("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles)
cf_set("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss)
cf_set("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats)
cf_set("WWW_FILES", "stats", www_stats)
global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas)
cf_set("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header)
cf_set("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar)
cf_set("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar)
cf_set("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer)
cf_set("WWW_FILES", "footer", www_footer)
# [TYTO]
# ======
cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri)
cf_set("TYTO", "domain_hash", cf_id)
cf_set("TYTO", "domain_conf", cf_uri)
cf_set("TYTO", "domain_user", ult_cf_uri)
# ================================= #

View File

@ -33,10 +33,11 @@
#--------------------------
import os, sys, configparser
import domain, debug, tools, tyto
import args, domain, debug, tools, tyto
error = 0
write = False # When updating database in cf_set(), cf_write()
#============================================#
@ -57,7 +58,7 @@ def is_article(target):
# Article exists
global uri
uri = os.path.join(domain.wrk_articles, target)
uri = os.path.join(domain.user_dir, target)
if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False)
return False
@ -77,11 +78,10 @@ def is_article(target):
# Set target from articles/
wrk_target = uri.rsplit(domain.wrk_articles)[1]
# Load Database
global db
db = False
db = cf_load() # True or False
# Load Database, get and compare values
cf_load()
cf_datas()
compare_datas()
return True
@ -131,19 +131,112 @@ def cf_load():
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
#================================#
# Return value from section, key #
#--------------------------------#
def cf_get(section, key, boolean):
if boolean:
try: return cf.getboolean(section, key)
except: return False
chk_hash = cf.get("CHECK", "hash")
wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash")
try: return cf.get(section, key)
except: return ""
#=============================================#
# Get and prepare new vars from post database #
#---------------------------------------------#
def cf_datas():
# [CHECK]
# -------
global chk_hash, chk_date, chk_static, chk_errors
chk_hash = cf_get("CHECK", "hash", False)
chk_date = cf_get("CHECK", "date", False)
chk_static = cf_get("CHECK", "static", True)
chk_errors = cf_get("CHECK", "errors", True)
# [WIP]
# -----
global wip_hash, wip_date, wip_uri, wip_static
wip_hash = cf_get("WIP", "hash", False)
wip_date = cf_get("WIP", "date", False)
wip_uri = cf_get("WIP", "uri", False)
wip_static = cf_get("WIP", "static", True)
# [WIP]
# -----
global www_hash, www_date, www_uri, www_static
www_hash = cf_get("WWW", "hash", False)
www_date = cf_get("WWW", "date", False)
www_uri = cf_get("WWW", "uri", False)
www_static = cf_get("WWW", "static", True)
#===============================#
# Do some datas comparisons #
# after post cf_datas() setup #
# Used to do processes (mainly) #
#-------------------------------#
def compare_datas():
global do_chk, do_wip
do_chk = False
if chk_errors:
do_chk = True
do_wip = False
if chk_static != domain.static:
do_chk = True
if args.force:
do_chk = do_wip = True
else:
do_chk = tools.compare_values(wrk_id, chk_hash)
do_wip = tools.compare_values(chk_hash, wip_hash)
#===============================#
# Set a value in post database #
# only if changed value #
# check for [section] in file #
# or create it with key and val #
# config file must be loaded #
#-------------------------------#
def cf_set(section, key, value):
global write
try: cf
except: cf_load()
if not cf.has_section(section):
cf.add_section(section)
try: curval = cf.get(section, key)
except: curval = ""
if not curval or curval != value:
cf.set(section, key, value)
write = True
#=====================#
# Write post database #
# if new value is set #
#---------------------#
def cf_write():
global write
if write:
with open(cf_uri, "w") as f:
cf.write(f)
write = False
#======#
@ -156,16 +249,16 @@ stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_bcodes_lines = 0
stats_quotes = 0
stats_parags = 0
stats_lists = 0
stats_links = 0
stats_images = 0
stats_files = 0
stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_codes = 0
stats_raws = 0
stats_total_files = 0
@ -175,27 +268,26 @@ stats_text_images = 0
stats_text_abbrs = 0
stats_text_codes = 0
stats_text_raws = 0
stats_text_icodes = 0
# head_contents
#==============
# Optional Tags
nositemap = "! NoSitemap" # Article will not be included in sitemap
# One Line needed
sep = "-----" # Splitter between header and article
sep = "-----" # Splitter between header and article texts
# Will replace "Fals" with title value
title = ("title:", False)
about = ("about:", False)
date = ("date:", False)
tags = ("tags:", False)
title = ("title:", False)
about = ("about:", False)
date = ("date:", False)
tags = ("tags:", False)
author = ("author:", False)
# optional
logo = ("logo:", False)
logo = ("logo:", False) # optional
# Multiple lines (3)
# Multiple lines (3) markers
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_tags_marks = {
"link:" : "__",
@ -224,12 +316,7 @@ value2s_ext_uris = ("http", "ftp")
bcodes = ("{{", "}}")
quotes = ("[[", "]]")
parags = ("((", "))")
# markers with "protected" contents
raw_contents = ("bcodes", "quotes")
# Comments
text_comments = (";;", "<!--")
lists = ("<<", ">>", "=", "+")
# Tyto Titles #1 = <h2>
tyto_titles = ("#1", "#2", "#3", "#4", "#5")
@ -241,6 +328,24 @@ html_titles = {
"#5" : '<h6 class="%s">%s</h6>',
}
html_brline = ("|", '<br class="%s%s">')
html_hrline = ("--", '<hr class="%s%s">')
text_comments = (";;", "<!--")
html_parag_start = (parags[0], '<p class="%s%s">')
html_parag_close = (parags[1], '</p>')
# IN-texts contents markers (bold, icodes...)
icodes = ("{_", "_}")
# Specifics convertion
words_markers = \
(
("{_{_", "_}_}", '<code class="%s icode">{_', '_}</code>', "IC21", "IC22"),
("{_", "_}", '<code class="%s icode">', '</code>', "IC11", "IC12"),
)
#=============================#
# articles configuration file #
@ -267,12 +372,16 @@ ini_template = """[DOMAIN]
[IMAGES]
[BCODES]
[RAWS]
[CODES]
[ABBRS]
[ICODES]
[SOURCE_FILES]
[STATS_FILE]

View File

@ -34,13 +34,18 @@
from hashlib import blake2b
import sys, os, configparser, datetime, time, base64
import debug, domain
import debug, domain, post
#
#
#
#=========================================#
# Write to post database, error was found #
# Return if error found (multi articles) #
# Exit if error found (single article) #
#-----------------------------------------#
def exit(targets, error):
post.cf_set("CHECK", "errors", "True")
post.cf_write()
if targets: return
sys.exit(error)
@ -191,3 +196,30 @@ def convert_html_signs(string):
string = string.replace("'", '&apos;')
return string
#==========================#
# Get CSS value after mark #
# Only take the first name #
#--------------------------#
def get_css(line, mark):
css = line.rsplit(mark)[1].lstrip().rsplit(" ")[0]
if not css:
css = domain.css
return css
#==========================================#
# Compare 2 values #
# used for hashes and more... #
# return True if not same values #
# ex: do_wip = True #
# (as chk_hash and wip_hash are different) #
#------------------------------------------#
def compare_values(val1, val2):
if val1 != val2:
return True
return False

View File

@ -97,10 +97,14 @@ notarget = ("./", "../")
#======#
# HTML #=======================================================================
#======#
pre_bcode = """<pre class="%s_blockcode">
<code class="%s_blockcode">
<ol class="%s_blockcode">
code_bcode = """<code class="%s bcode">
%s
</ol>
</code>
</pre>"""
</code>"""
code_line = '<p class="bcode">' + \
'<span class="ln bcode">%s</span>' + \
'<span class="line bcode">%s</span>' +\
'</p>'
image_link = '<a href="%s" class="%s" target="%s" alt="%s" title="%s">%s</a>'
a_link = '<a href="%s" class="%s" target="%s" title="%s">%s</a>'

View File

@ -0,0 +1,76 @@
#!/usr/bin/env python3
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#----------------------------------------------------------------------
# XMPP: echolib (im@echolib.re)
#
# Description: Convert texts to HTML
# File: /var/lib/tyto/program/wip.py
#----------------------------------------------------------------------
#-------------------------
# Funny Stats Project
#-------------------------
# file lines :
# file comments :
# file functions:
# file program :
#--------------------------
import tyto, tools, post
#===========================#
# bcode #
# Used by check module that #
# convert raw lines to HTML #
#---------------------------#
def bcode(lines):
lines = lines.rsplit("\n")
html_lines = ""
for ln, line in enumerate(lines):
if ln == 0:
css = tools.get_css(line, post.bcodes[0])
continue
if ln == len(lines) - 1:
continue
# Count lines (add this to all other bcodes)
post.stats_bcodes_lines += 1
# Get first char from fisrt line
if ln == 1:
fc = len(line) - len(line.lstrip())
line = tyto.code_line%(ln, line[fc:])
if not html_lines: html_lines = line
else: html_lines = "%s\n%s"%(html_lines, line)
html_lines = tyto.code_bcode%(css, html_lines)
#print(html_lines)
return html_lines
#============================#
# code #
# Used by check module that #
# convert file lines to HTML #
#----------------------------#
def code(lines):
print("soon...")

View File

@ -86,6 +86,7 @@ domain_new = "Domaine créé"
created_dir = "Dossier créé"
created_file = "Fichier créé"
updated_file = "Fichier mis à jour"
post_chk_yet = "Article déjà vérifié"
later = "Peut-être plus tard..."