Updated code. Publish works but needs tests
This commit is contained in:
parent
29ee8cc704
commit
6f67fd1d01
|
@ -114,6 +114,7 @@ def check_process(target):
|
|||
global post_bottom, article_bottom
|
||||
global date_wip, hash_wip, date_www, hash_www, post_bottom
|
||||
global post_err
|
||||
|
||||
date_wip = hash_wip = date_www = hash_www = ''
|
||||
post_err = False
|
||||
|
||||
|
@ -348,7 +349,7 @@ def check_needed_tags(post_header):
|
|||
# Check if unused needed tags
|
||||
for tag in tyto.needed_header_tags:
|
||||
if not globals()[tag]:
|
||||
logs.out("17", '%s:'%tag, False)
|
||||
logs.out("38", '%s:'%tag, False)
|
||||
post_err = True
|
||||
|
||||
# Check date format
|
||||
|
@ -372,7 +373,9 @@ def check_date(date):
|
|||
bool(datetime.strptime(date, fmt_article))
|
||||
except ValueError:
|
||||
post_err = True
|
||||
logs.out("3", 'date: "%s" (YYYY-MM-DD) > %s'%(date, db.uri_file), False)
|
||||
logs.out("3", 'date: "%s" (YYYY-MM-DD) > %s'%(
|
||||
date, db.uri_file
|
||||
), False)
|
||||
|
||||
# Create date_check (epoch) from article's Date + now TIME
|
||||
if not post_err:
|
||||
|
@ -385,7 +388,6 @@ def check_date(date):
|
|||
if dom.lang_site == 'fr':
|
||||
date = date.rsplit('-')
|
||||
date_tr = date[2] + '/' + date[1] + '/' + date[0]
|
||||
print("> Convert date in FR >", date_tr)
|
||||
|
||||
|
||||
#===========================================#
|
||||
|
@ -393,13 +395,13 @@ def check_date(date):
|
|||
# Multiple settings for each on 3 lines #
|
||||
#-------------------------------------------#
|
||||
def check_opt_tags(post_header):
|
||||
global stat_links, stat_images, stat_files, stat_raws
|
||||
global stat_links, stat_images, stat_files, stat_raws, stat_codes
|
||||
global stat_snpics, snpic_url, stat_abbrs, post_abbrs
|
||||
global opt_tags_post_name
|
||||
global files_post
|
||||
|
||||
# Statistics
|
||||
stat_links = stat_images = stat_files = stat_raws = 0
|
||||
stat_links = stat_images = stat_files = stat_raws = stat_codes = 0
|
||||
stat_snpics = post_abbrs = stat_abbrs = 0
|
||||
files_post = (())
|
||||
|
||||
|
@ -413,6 +415,7 @@ def check_opt_tags(post_header):
|
|||
'image' : "_image:%s",
|
||||
'file' : "__%s",
|
||||
'raw' : "_raw:%s",
|
||||
'code' : '_code:%s',
|
||||
'abbr' : "(%s)"
|
||||
}
|
||||
|
||||
|
@ -481,6 +484,8 @@ def check_3lines(tag, ln, line):
|
|||
elif l == 2: data_log = "Alt-Text"
|
||||
|
||||
ln += 1
|
||||
data = ''
|
||||
|
||||
try:
|
||||
# ln - 1 as string post_header starts with 0
|
||||
data = post_header.rsplit('\n')[ln - 1].lstrip()
|
||||
|
@ -488,7 +493,7 @@ def check_3lines(tag, ln, line):
|
|||
except:
|
||||
data = ''
|
||||
|
||||
if not data:
|
||||
if not data and not l == 2 and not tag == 'raw':
|
||||
logs.out("2", 'L=%s. "%s" (%s:) > %s'%(
|
||||
ln, data_log, tag, db.uri_file
|
||||
), False)
|
||||
|
@ -502,6 +507,7 @@ def check_3lines(tag, ln, line):
|
|||
return
|
||||
globals()[db_tag] = globals()[db_tag] + ((web_uri),)
|
||||
files_post = files_post + (('%s'%web_uri),)
|
||||
|
||||
else:
|
||||
if post_err:
|
||||
return
|
||||
|
@ -525,14 +531,19 @@ def isin(term, post_file):
|
|||
def check_file_uri(filetype, filename, ln):
|
||||
global post_err, err, web_uri
|
||||
|
||||
filetypes = ('file', 'raw', 'code')
|
||||
|
||||
# Set file uri from filename
|
||||
# (@ = images/, / = articles/, else = post_dir)
|
||||
# (@ = images/ or files/
|
||||
# / = articles/
|
||||
# Else in post_dir
|
||||
if filename.startswith('@'):
|
||||
if filetype == 'image' or filetype == "snpic":
|
||||
fileuri = dom.images_d + filename[1: len(filename)]
|
||||
elif filetype == 'file' or filetype == 'raw':
|
||||
if filetype in filetypes:
|
||||
fileuri = dom.files_d + filename[1: len(filename)]
|
||||
|
||||
elif filetype == 'image' or filetype == "snpic":
|
||||
fileuri = dom.images_d + filename[1: len(filename)]
|
||||
|
||||
else:
|
||||
post_dir = db.uri_file.split("/")[-1]
|
||||
post_dir = db.uri_file.rsplit(post_dir)[0]
|
||||
|
@ -702,6 +713,18 @@ def check_content(post_bottom):
|
|||
post_err = True
|
||||
|
||||
|
||||
# Legacy HTML not paired error
|
||||
for tag in tyto.leg_html_tags:
|
||||
leg1 = post_bottom.count(tag[0])
|
||||
leg2 = post_bottom.count(tag[1])
|
||||
|
||||
if leg1 != leg2:
|
||||
logs.out("8", '"%s" + "%s" > %s'%(
|
||||
tag[0], tag[1], db.uri_file
|
||||
), False)
|
||||
post_err = True
|
||||
|
||||
|
||||
# Template Tags (warning for not paired symbols)
|
||||
#-----------------------------------------------
|
||||
for tag in tyto.tpl_tags:
|
||||
|
@ -778,12 +801,19 @@ def create_database():
|
|||
datas_tag, i, globals()['file_%s'%i]
|
||||
)
|
||||
|
||||
if stat_codes > 0:
|
||||
for i in range(1, stat_codes + 1):
|
||||
datas_tag = '%s\ncode_%s = %s'%(
|
||||
datas_tag, i, globals()['code_%s'%i]
|
||||
)
|
||||
|
||||
if stat_raws > 0:
|
||||
for i in range(1, stat_raws + 1):
|
||||
datas_tag = '%s\nraw_%s = %s'%(
|
||||
datas_tag, i, globals()['raw_%s'%i]
|
||||
)
|
||||
|
||||
|
||||
opt_tags = ''
|
||||
if datas_tag:
|
||||
opt_tags = \
|
||||
|
@ -801,6 +831,7 @@ def create_database():
|
|||
'uniq_links = %d\n'%stat_links + \
|
||||
'uniq_images = %d\n'%stat_images + \
|
||||
'uniq_files = %d\n'%stat_files + \
|
||||
'uniq_codes = %d\n'%stat_codes + \
|
||||
'uniq_raws = %d\n'%stat_raws + \
|
||||
'\n# Statistics from post content\n' + \
|
||||
'post_coms = %d\n'%nbr_coms + \
|
||||
|
|
|
@ -135,10 +135,10 @@ def create_main_page(target, article_bottom):
|
|||
post_html_code = ''
|
||||
if dom.article_code:
|
||||
post_html_code = \
|
||||
' <span id="article_code"> ' + \
|
||||
' <span id="article_code"> \n' + \
|
||||
' <a id="article_code_link"\n' + \
|
||||
' href="./%s"\n'%os.path.basename(db.short_src) + \
|
||||
' title="%s">{%s}</a></span>\n'%(
|
||||
' title="%s">{%s}</a></span> \n'%(
|
||||
langs.site.tyto_psrc,
|
||||
langs.site.source_code
|
||||
)
|
||||
|
@ -157,7 +157,6 @@ def create_main_page(target, article_bottom):
|
|||
' <div id="site_logo">\n' + \
|
||||
' %s\n'%logo_html + \
|
||||
' </div>\n' + \
|
||||
'\n' + \
|
||||
' <div id="site_infos">\n' + \
|
||||
' <a href="/"\n' + \
|
||||
' title="%s"\n'%(langs.site.home) + \
|
||||
|
@ -173,14 +172,15 @@ def create_main_page(target, article_bottom):
|
|||
' <section id="article_infos">\n' + \
|
||||
' <p>\n' + \
|
||||
' <span id="article_title"\n' + \
|
||||
' title="%s %s %s %s %s">%s</span>\n'%(
|
||||
title, langs.site.w_written, db.date, langs.site.by,
|
||||
' title="[%s] %s %s %s %s">%s</span>\n'%(
|
||||
db.title, langs.site.w_written, db.date, langs.site.by,
|
||||
db.author,
|
||||
langs.site.article
|
||||
) + \
|
||||
'%s'%post_html_code + \
|
||||
' <span>%s</span> \n'%langs.site.written_by + \
|
||||
' <span id="article_author">%s</span>. \n'%(db.author) + \
|
||||
'%s\n'%time_html_pub + \
|
||||
' <span id="article_author">%s</span>\n'%db.author + \
|
||||
' </p>\n' + \
|
||||
' </section>\n' + \
|
||||
'%s\n'%article_bottom + \
|
||||
|
@ -198,18 +198,25 @@ def create_main_page(target, article_bottom):
|
|||
#--------------------------------------------#
|
||||
def create_html_time_meta(process):
|
||||
# Need to reload the DB to get last time updated
|
||||
exec(open(db.config).read(), globals())
|
||||
importlib.reload(db)
|
||||
|
||||
global time_html_pub, meta_pub, date_raw
|
||||
|
||||
if process == 'wip':
|
||||
date_raw = date_wip # <time datetime= / meta search_date
|
||||
date_pub = date_wip.rsplit(' ')[0]
|
||||
time_pub = date_wip.rsplit(' ')[1]
|
||||
try:
|
||||
date_raw = db.date_wip # <time datetime= / meta search_date
|
||||
date_pub = db.date_wip.rsplit(' ')[0]
|
||||
time_pub = db.date_wip.rsplit(' ')[1]
|
||||
except:
|
||||
logs.out("23", '"date_wip = ?" > %s'%db.uri_file, True)
|
||||
|
||||
elif process == 'publish':
|
||||
date_raw = date_www # <time datetime=
|
||||
date_pub = date_www.rsplit(' ')[0]
|
||||
time_pub = date_www.rsplit(' ')[1]
|
||||
try:
|
||||
date_raw = db.date_www # <time datetime=
|
||||
date_pub = db.date_www.rsplit(' ')[0]
|
||||
time_pub = db.date_www.rsplit(' ')[1]
|
||||
except:
|
||||
logs.out("23", '"date_www = ?" > %s'%db.uri_file, True)
|
||||
|
||||
if dom.lang_site == 'fr':
|
||||
date_new = date_pub.rsplit('-')
|
||||
|
@ -217,19 +224,19 @@ def create_html_time_meta(process):
|
|||
|
||||
# in <article> > section info : line with new date
|
||||
time_html_pub = \
|
||||
' <!--TYTOPUB-->\n' + \
|
||||
'<!--Tyto_Published-->\n' + \
|
||||
' <time datetime="%s">\n'%date_raw + \
|
||||
' <span id="article_pub"\n' + \
|
||||
' title="%s %s %s">%s %s (%s)</span>\n'%(
|
||||
title, langs.site.w_published, date_pub,
|
||||
langs.site.published, date_pub, time_pub
|
||||
' title="[%s] %s %s (%s)">%s %s</span>\n'%(
|
||||
db.title, langs.site.w_published, date_pub, time_pub,
|
||||
langs.site.published, date_pub
|
||||
) + \
|
||||
' </time> %s\n'%langs.site.by + \
|
||||
' <!--/TYTOPUB-->'
|
||||
' </time>\n' + \
|
||||
'<!--/Tyto_Published-->'
|
||||
|
||||
# meta search_date=
|
||||
meta_pub = \
|
||||
' <meta name="search_date" content="%s" />\n'%(
|
||||
'<!--Tyto_Meta--> <meta name="search_date" content="%s" />\n'%(
|
||||
date_raw.rsplit(' ')[0]
|
||||
)
|
||||
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: logs tools
|
||||
# Description: Show logs and statuses, exit if needed
|
||||
# file: logs.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
# 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 Affero General Public License
|
||||
# as published by the Free Software Foundation, either version 3 of the
|
||||
# License, or 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# XMPP: echolib (im@echolib.re)
|
||||
#
|
||||
# Description: Show logs messages, exit with nbr
|
||||
# File: /var/lib/tyto/program/logs.py
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
|
@ -68,6 +84,7 @@ def out(nbr, value, out):
|
|||
'35' : ' ╞═ %s%s%s %s'%(CG, langs.log.add, CS, value),
|
||||
'36' : ' ╡ %s %s'%(langs.log.file_e, value),
|
||||
'37' : ' ╡ %s %s'%(langs.log.dir_e, value),
|
||||
'38' : ' ╞ %s%s%s "%s ?"'%(CR, langs.log.unused_t, CS, value),
|
||||
'40' : ' ╒ %s%s%s > "%s"'%(CY, langs.log.dom_ina, CS, value),
|
||||
'41' : ' ╒ %s%s%s > "%s"'%(CR, langs.log.dom_inc, CS, value),
|
||||
'42' : ' ╒ %s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value),
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: Command arguments 'new' manager
|
||||
# Description: manage all 'new' from command action argument
|
||||
# file: new.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
# 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 Affero General Public License
|
||||
# as published by the Free Software Foundation, either version 3 of the
|
||||
# License, or 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# XMPP: echolib (im@echolib.re)
|
||||
#
|
||||
# Description: Create something new (domain, sidebar...)
|
||||
# File: /var/lib/tyto/program/new.py
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: Create HTML files in www/
|
||||
# Description: Copy files and replace publish line in article
|
||||
# file: publish.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
# 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 Affero General Public License
|
||||
# as published by the Free Software Foundation, either version 3 of the
|
||||
# License, or 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# XMPP: echolib (im@echolib.re)
|
||||
#
|
||||
# Description: Publish on www server
|
||||
# File: /var/lib/tyto/program/publish.py
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
|
@ -19,15 +35,14 @@
|
|||
|
||||
import os, sys, shutil, importlib
|
||||
from pathlib import Path
|
||||
|
||||
import logs, args, dom, html, tyto, form, stats, rss
|
||||
import logs, args, dom, db, wip, html, tyto, form, stats, rss
|
||||
|
||||
#==============================#
|
||||
# Manage action, get post db #
|
||||
# check if publish can be done #
|
||||
#------------------------------#
|
||||
def manage_publish(target):
|
||||
domain.domain_needed
|
||||
dom.valid()
|
||||
|
||||
# Target is footer, sidebar, navbar, metas
|
||||
# template: create/copy template/ files
|
||||
|
@ -50,17 +65,16 @@ def manage_publish(target):
|
|||
return
|
||||
|
||||
# Database must exists...
|
||||
if not target: logs.out("5", '', True)
|
||||
if not db.post_exists: sys.exit(1)
|
||||
if not db.db_exists: logs.out("25", db.uri_file, True)
|
||||
|
||||
if not target: logs.out("5", '', True)
|
||||
if not db.post: logs.out("1", db.uri_file, True)
|
||||
if not db.exists: logs.out("25", db.uri_file, True)
|
||||
|
||||
# Publish in www server an article
|
||||
check_to_publish('one')
|
||||
publish_article()
|
||||
|
||||
# Create new ATOM/RSS file
|
||||
rss.create_feed()
|
||||
#rss.create_feed()
|
||||
|
||||
|
||||
#===============#
|
||||
|
@ -68,42 +82,60 @@ def manage_publish(target):
|
|||
#---------------#
|
||||
def publish_article():
|
||||
# Copy wip page to www page
|
||||
os.makedirs('%s%s'%(db.srv_www, db.direc_src), exist_ok=True)
|
||||
shutil.copy2(db.post_wip, db.post_www)
|
||||
logs.out("33", db.post_www, False)
|
||||
os.makedirs('%s%s'%(dom.srv_www, db.direc_src), exist_ok=True)
|
||||
logs.out("33", '%s%s'%(dom.srv_www, db.direc_src), False)
|
||||
|
||||
# Replace in DB hash_wip and date_wip
|
||||
tyto.replace_in_db(db.config, 'www', db.hash_post)
|
||||
|
||||
# Copy needed files (Also create sub-folders)
|
||||
tyto.files_to_srv('www')
|
||||
|
||||
# Replace in DB hash_wip and date_wip
|
||||
tyto.replace_in_db(db.post_db, 'www', db.hash_post)
|
||||
|
||||
# Replace publish HTML line
|
||||
replace_line_pub()
|
||||
replace_lines_pub()
|
||||
|
||||
|
||||
#=================================================#
|
||||
# Replace line in article containing publish date #
|
||||
#-------------------------------------------------#
|
||||
def replace_line_pub():
|
||||
# Load config
|
||||
importlib.reload(db)
|
||||
def replace_lines_pub():
|
||||
html.create_html_time_meta('publish')
|
||||
print(html.time_html_pub)
|
||||
|
||||
html.create_html_infos_section('publish')
|
||||
|
||||
newfile = ''
|
||||
in_pub = False
|
||||
time_wip_pub = ''
|
||||
wip_html_post = open(db.post_wip, 'r').read()
|
||||
www_html_post = wip_html_post
|
||||
|
||||
for line in wip_html_post.rsplit('\n'):
|
||||
if line.startswith('%s<p><span id="article_title"'%(8 * ' ')):
|
||||
line = html.post_pub
|
||||
if line.startswith('%s<meta name="search_date"'%(4 * ' ')):
|
||||
line = html.meta_pub
|
||||
if line.startswith('<!--Tyto_Published-->'):
|
||||
in_pub = True
|
||||
time_wip_pub = line
|
||||
continue
|
||||
|
||||
if not newfile: newfile = line
|
||||
else: newfile = '%s\n%s'%(newfile, line)
|
||||
elif line.startswith('<!--/Tyto_Published-->'):
|
||||
time_wip_pub = '%s\n%s'%(time_wip_pub, line)
|
||||
in_pub = False
|
||||
print('> time_wip_pub')
|
||||
print(time_wip_pub)
|
||||
break
|
||||
|
||||
tyto.set_file(db.post_www, 'new', newfile)
|
||||
logs.out("34", '(HTML date: %s): %s'%(db.date_www, db.post_www), False)
|
||||
elif line.startswith('<!--Tyto_Meta-->'):
|
||||
time_wip_meta = line
|
||||
continue
|
||||
|
||||
if in_pub:
|
||||
time_wip_pub = '%s\n%s'%(time_wip_pub, line)
|
||||
|
||||
www_html_post = www_html_post.replace(time_wip_pub,
|
||||
html.time_html_pub
|
||||
)
|
||||
|
||||
www_html_post = www_html_post.replace(time_wip_meta, html.meta_pub)
|
||||
|
||||
#print(www_html_post)
|
||||
tyto.set_file(db.post_www, 'new', www_html_post)
|
||||
logs.out("32", db.post_www, False)
|
||||
|
||||
|
||||
#================================#
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import logs, dom, db, tyto
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ def read_lines(f, alone):
|
|||
print(' ├─%s─┐'%(sp_max * '─'))
|
||||
for ln, line in enumerate(datas.rsplit('\n'), 1):
|
||||
sp = sp_max - len(str(ln))
|
||||
print(' │ %s %s│ %s'%(ln, int(sp) * " ", line))
|
||||
print(' │%s %s │ %s'%(int(sp) * " ", ln, line))
|
||||
|
||||
# Ends for show. False should be for form
|
||||
if alone: decor = '└'
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: DBs tools
|
||||
# Description: Show DBs status
|
||||
# file: status.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
# 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 Affero General Public License
|
||||
# as published by the Free Software Foundation, either version 3 of the
|
||||
# License, or 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# XMPP: echolib (im@echolib.re)
|
||||
#
|
||||
# Description: Show statuses for domain
|
||||
# File: /var/lib/tyto/program/status.py
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#**********************************************************************
|
||||
|
||||
import os, sys, subprocess, locale, base64, datetime, shutil
|
||||
import os, sys, re, subprocess, locale, base64, datetime, shutil
|
||||
from hashlib import blake2b
|
||||
import args, dom, logs
|
||||
|
||||
|
@ -62,6 +62,7 @@ opt_header_tags = \
|
|||
'file',
|
||||
'abbr',
|
||||
'raw',
|
||||
'code',
|
||||
'snpic'
|
||||
)
|
||||
|
||||
|
@ -75,7 +76,8 @@ opt_tags_check_uri = \
|
|||
(
|
||||
'image',
|
||||
'file',
|
||||
'raw'
|
||||
'raw',
|
||||
'code'
|
||||
)
|
||||
|
||||
# Set all tags used in article's header
|
||||
|
@ -90,6 +92,7 @@ headers = \
|
|||
'image:',
|
||||
'file:',
|
||||
'abbr:',
|
||||
'code:',
|
||||
'raw:',
|
||||
'#',
|
||||
'snpic:',
|
||||
|
@ -134,7 +137,8 @@ words_tags[11][0], words_tags[11][1], # quotes
|
|||
words_tags[12][0], words_tags[12][1], # bcodes
|
||||
words_tags[13][0], words_tags[13][1], # lists
|
||||
single_tags[0][0], single_tags[1][0], # New line, anchor
|
||||
'_%s:'%opt_header_tags[1], '_%s:'%opt_header_tags[4] # _image:, _raw:
|
||||
'_%s:'%opt_header_tags[1], '_%s:'%opt_header_tags[4], # _image:, _raw:
|
||||
'_%s:'%opt_header_tags[5] # _code
|
||||
)
|
||||
|
||||
# warning symbols (Check if paired)
|
||||
|
@ -144,7 +148,17 @@ tpl_tags = [
|
|||
('[', ']'),
|
||||
('{', '}'),
|
||||
('«', '»'),
|
||||
('<!--', '-->')
|
||||
]
|
||||
|
||||
# When including HTML in article, check some paired tags
|
||||
#-------------------------------------------------------
|
||||
leg_html_tags = [
|
||||
('<!--', '-->'),
|
||||
('<div', '</div>'),
|
||||
('<ul', '</ul>'),
|
||||
('<li', '</li>'),
|
||||
('<p', '</p>'),
|
||||
('<span','</span>'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -167,7 +181,7 @@ quote_tags = [
|
|||
]
|
||||
|
||||
# Tags to check in header in content _TAG
|
||||
head_tags = ("image:", "raw:")
|
||||
head_tags = ("image:", "raw:", "code;")
|
||||
|
||||
# Stats for icodes, bcodes, quotes
|
||||
nbr_icodes = 0
|
||||
|
@ -208,15 +222,6 @@ def nowdate():
|
|||
return(now.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
|
||||
#=======================================#
|
||||
# Convert date DD/MM/YYYY to YYYY-MM-DD #
|
||||
#---------------------------------------#
|
||||
def set_en_date(date):
|
||||
if db.domain_lang.lower() == 'fr':
|
||||
udate = date.rsplit('/')
|
||||
return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
|
||||
|
||||
|
||||
#======================#
|
||||
# Open and edit a file #
|
||||
#----------------------#
|
||||
|
@ -258,14 +263,16 @@ def set_file(path, new, text):
|
|||
#--------------------------#
|
||||
def get_css(line):
|
||||
# Use this default, if not in conf
|
||||
try: set_css = domain_css
|
||||
except: domain_css = 'tyto'
|
||||
css = 'tyto'
|
||||
|
||||
try: css = dom.css
|
||||
except: pass
|
||||
|
||||
# Get CSS from line
|
||||
try: set_css = line.rsplit(' ')[1]
|
||||
except: set_css = domain_css
|
||||
try: css = re.search (r'(?<=' ') +([^ -.]*)', line).group(1)
|
||||
except: pass
|
||||
|
||||
return set_css
|
||||
return css
|
||||
|
||||
|
||||
#=============================================#
|
||||
|
|
|
@ -76,7 +76,7 @@ def manage(target):
|
|||
logs.out("1", db.uri_file, True)
|
||||
|
||||
elif not db.exists:
|
||||
logs.out("28", '%s %s'%(args.action, args.target), True)
|
||||
logs.out("25", db.uri_file, True)
|
||||
|
||||
elif db.old_chk:
|
||||
logs.out("9", db.uri_file, True)
|
||||
|
@ -153,17 +153,19 @@ def wip_article(target):
|
|||
|
||||
|
||||
# Convert contents from modules
|
||||
wip_single_tags() # br /, anchors
|
||||
wip_words_tags() # Paragraphs, strongs, italics
|
||||
wip_links() # Links_%i from headers in DB
|
||||
wip_abbrs() # Convert abbr
|
||||
wip_images() # Images_%i from headers in DB
|
||||
wip_titles() # Convert #N, remove empty line, add divs
|
||||
wip_quotes() # Quotes. Decode base64 Q64 and convert to HTML
|
||||
wip_icodes() # inline_codes. Decode base64 icode and replace
|
||||
wip_bcodes() # Block-codes. Decode B64 and convert to HTML
|
||||
wip_raws(target) # Read file and convert to HTML
|
||||
wip_tabs() # make HTML tabulations
|
||||
wip_single_tags() # br /, anchors
|
||||
wip_words_tags() # Paragraphs, strongs, italics
|
||||
wip_links() # Links_%i from headers in DB
|
||||
wip_abbrs() # Convert abbr
|
||||
wip_images() # Images_%i from headers in DB
|
||||
wip_titles() # Convert #N, remove empty line, add divs
|
||||
wip_lists() # convert ul/ol lists
|
||||
wip_quotes() # Quotes. Decode base64 Q64 and convert to HTML
|
||||
wip_icodes() # inline_codes. Decode base64 icode and replace
|
||||
wip_filecode(target) # Read file and convert to HTML
|
||||
wip_bcodes() # Block-codes. Decode B64 and convert to HTML
|
||||
wip_fileraws(target) # Read file and add raw content
|
||||
wip_tabs() # make HTML tabulations
|
||||
|
||||
# Replace in DB hash_wip and date_wip
|
||||
tyto.replace_in_db(db.config, 'wip', db.hash_post)
|
||||
|
@ -206,23 +208,30 @@ def file_to_string(post_file):
|
|||
else: post_header = '%s\n%s'%(post_header, line)
|
||||
|
||||
|
||||
#===============================================================#
|
||||
# Simple function to replace source text to HTML in post_bottom #
|
||||
#---------------------------------------------------------------#
|
||||
def replace_in_post(src, html):
|
||||
global post_bottom
|
||||
post_bottom = post_bottom.replace(src, html)
|
||||
|
||||
|
||||
#=============================#
|
||||
# Convert tags (br /, anchor) #
|
||||
#-----------------------------#
|
||||
def wip_single_tags():
|
||||
global post_bottom
|
||||
|
||||
# <br /> from "|"
|
||||
post_bottom = post_bottom.replace(tyto.single_tags[0][0],
|
||||
tyto.single_tags[0][1]
|
||||
)
|
||||
replace_in_post(tyto.single_tags[0][0],
|
||||
tyto.single_tags[0][1]
|
||||
)
|
||||
|
||||
# Anchor source
|
||||
for line in post_bottom.rsplit('\n'):
|
||||
if line.startswith(tyto.single_tags[1][0]):
|
||||
set_css = tyto.get_css(line)
|
||||
post_bottom = post_bottom.replace(line,
|
||||
tyto.single_tags[1][1]%set_css
|
||||
)
|
||||
replace_in_post(line,
|
||||
tyto.single_tags[1][1]%set_css
|
||||
)
|
||||
|
||||
|
||||
#==================================#
|
||||
|
@ -230,8 +239,6 @@ def wip_single_tags():
|
|||
# Convert Paragraphs #
|
||||
#----------------------------------#
|
||||
def wip_words_tags():
|
||||
global post_bottom
|
||||
|
||||
# Strongs, italics...
|
||||
# (Stop after 8 tags)
|
||||
# For anchor (0), must do it differently
|
||||
|
@ -240,14 +247,22 @@ def wip_words_tags():
|
|||
if m == 0:
|
||||
m += 1
|
||||
# Close anchor (generic)
|
||||
post_bottom = post_bottom.replace(tag[1], tag[3])
|
||||
replace_in_post(tag[1],
|
||||
tag[3]
|
||||
)
|
||||
continue
|
||||
elif m > 8: break
|
||||
|
||||
elif m > 8:
|
||||
break
|
||||
|
||||
# Open tag
|
||||
post_bottom = post_bottom.replace(tag[0], tag[2])
|
||||
replace_in_post(tag[0],
|
||||
tag[2]
|
||||
)
|
||||
# Close tag
|
||||
post_bottom = post_bottom.replace(tag[1], tag[3])
|
||||
replace_in_post(tag[1],
|
||||
tag[3]
|
||||
)
|
||||
m += 1
|
||||
|
||||
|
||||
|
@ -257,23 +272,23 @@ def wip_words_tags():
|
|||
if db.post_paragraphs > 0:
|
||||
if line.startswith(tyto.words_tags[10][0]):
|
||||
set_css = tyto.get_css(line)
|
||||
post_bottom = post_bottom.replace(post_bottom.rsplit('\n')[ln],
|
||||
tyto.words_tags[10][2]%set_css
|
||||
)
|
||||
# Close tag
|
||||
replace_in_post(post_bottom.rsplit('\n')[ln],
|
||||
tyto.words_tags[10][2]%set_css
|
||||
)
|
||||
# Close paragraph tag
|
||||
elif line.startswith(tyto.words_tags[10][1]):
|
||||
post_bottom = post_bottom.replace(line,
|
||||
tyto.words_tags[10][3]
|
||||
)
|
||||
# Open anchors
|
||||
replace_in_post(line,
|
||||
tyto.words_tags[10][3]
|
||||
)
|
||||
# Open anchors link
|
||||
if db.post_anchors == 0: continue
|
||||
|
||||
anchor_links = re.findall(r'>_(.+?):', line)
|
||||
for item in anchor_links:
|
||||
anchor_id = '%s%s:'%(tyto.words_tags[0][0], item)
|
||||
post_bottom = post_bottom.replace(anchor_id,
|
||||
tyto.words_tags[0][2]%item
|
||||
)
|
||||
replace_in_post(anchor_id,
|
||||
tyto.words_tags[0][2]%item
|
||||
)
|
||||
|
||||
|
||||
#========================#
|
||||
|
@ -282,10 +297,6 @@ def wip_words_tags():
|
|||
# - link_%i #
|
||||
# from marker to HTML #
|
||||
#------------------------#
|
||||
def wip_link_convert(marker, html):
|
||||
global post_bottom
|
||||
post_bottom = post_bottom.replace(marker, html)
|
||||
|
||||
def wip_links():
|
||||
if db.uniq_files == 0 and db.uniq_links == 0: return
|
||||
|
||||
|
@ -306,8 +317,8 @@ def wip_links():
|
|||
link_css, link_anc, link_title, "%s", link_name
|
||||
)
|
||||
|
||||
wip_link_convert(eval(link)[0]+'+', link_set%link_tb)
|
||||
wip_link_convert(eval(link)[0], link_set%link_ts)
|
||||
replace_in_post(eval(link)[0]+'+', link_set%link_tb)
|
||||
replace_in_post(eval(link)[0], link_set%link_ts)
|
||||
|
||||
|
||||
# Convert simple links
|
||||
|
@ -323,8 +334,8 @@ def wip_links():
|
|||
link_css, link_anc, link_title, "%s", link_name
|
||||
)
|
||||
|
||||
wip_link_convert(eval(link)[0]+'+', link_set%link_tb)
|
||||
wip_link_convert(eval(link)[0], link_set%link_ts)
|
||||
replace_in_post(eval(link)[0]+'+', link_set%link_tb)
|
||||
replace_in_post(eval(link)[0], link_set%link_ts)
|
||||
|
||||
|
||||
#===============#
|
||||
|
@ -333,13 +344,11 @@ def wip_links():
|
|||
def wip_abbrs():
|
||||
if db.uniq_abbrs == 0: return
|
||||
|
||||
global post_bottom
|
||||
|
||||
for i in range(1, db.uniq_abbrs + 1):
|
||||
abbr = 'db.abbr_%s'%i
|
||||
post_bottom = post_bottom.replace(eval(abbr)[0],
|
||||
eval(abbr)[1]
|
||||
)
|
||||
replace_in_post(eval(abbr)[0],
|
||||
eval(abbr)[1]
|
||||
)
|
||||
|
||||
|
||||
#---------------------------------------#
|
||||
|
@ -358,7 +367,6 @@ def get_wh_image(value):
|
|||
def wip_images():
|
||||
if db.uniq_images == 0: return
|
||||
|
||||
global post_bottom
|
||||
image_link = '<a class="%s" href="%s">%s</a>'
|
||||
image_show = '<img class="%s" src="%s" alt="%s" title="%s"%s />'
|
||||
|
||||
|
@ -424,9 +432,9 @@ def wip_images():
|
|||
# Set HTML to replace line number
|
||||
image_html = image_tgt%image_src
|
||||
|
||||
post_bottom = post_bottom.replace(post_bottom.rsplit('\n')[ln],
|
||||
image_html
|
||||
)
|
||||
replace_in_post(post_bottom.rsplit('\n')[ln],
|
||||
image_html
|
||||
)
|
||||
|
||||
|
||||
#--------------------------------------------#
|
||||
|
@ -444,7 +452,6 @@ def quote_params(qline):
|
|||
def wip_quotes() :
|
||||
if db.post_quotes == 0: return
|
||||
|
||||
global post_bottom
|
||||
global author, link, lang, book, date
|
||||
|
||||
for ln, line in enumerate(post_bottom.rsplit('\n')):
|
||||
|
@ -477,12 +484,12 @@ def wip_quotes() :
|
|||
|
||||
# Set tabulation for paragraphs and content
|
||||
if author: tab_p = tab_p + 2 ; tab_c = tab_c + 4
|
||||
else: tab_c = tab_c + 2
|
||||
else: tab_c = tab_c + 2
|
||||
|
||||
# Replace opened paragrph with html line
|
||||
qline_html = '%s%s'%(tab_p * ' ',
|
||||
tyto.words_tags[10][2]%par_css
|
||||
)
|
||||
qline_html = '%s%s'%(
|
||||
tab_p * ' ', tyto.words_tags[10][2]%par_css
|
||||
)
|
||||
|
||||
# Add line to quote_html
|
||||
if quote_html:
|
||||
|
@ -505,10 +512,14 @@ def wip_quotes() :
|
|||
continue
|
||||
|
||||
# Add other lines
|
||||
if quote_html: quote_html = '%s\n%s%s'%(
|
||||
if quote_html:
|
||||
quote_html = '%s\n%s%s'%(
|
||||
quote_html, int(tab_c) * ' ', qline
|
||||
)
|
||||
else: quote_html = '%s%s'%(tab_c * ' ', qline)
|
||||
else:
|
||||
quote_html = '%s%s'%(
|
||||
tab_c * ' ', qline
|
||||
)
|
||||
|
||||
# New quote set, then, repare datas
|
||||
if link: cite = ' cite="%s"'%(link)
|
||||
|
@ -540,9 +551,7 @@ def wip_quotes() :
|
|||
figc = '<span class="figc">%s</span>'%auth_html
|
||||
|
||||
else:
|
||||
if book and date: title_html = ' title="%s (%s)"'%(
|
||||
book, date
|
||||
)
|
||||
if book and date: title_html = ' title="%s (%s)"'%(book, date)
|
||||
elif book: title_html = ' title="%s"'%(book)
|
||||
elif date: title_html = ' title="(%s)"'%(date)
|
||||
|
||||
|
@ -554,31 +563,33 @@ def wip_quotes() :
|
|||
|
||||
# Create HTML Quote with datas
|
||||
if author:
|
||||
quote_html = '<figure class="%s">\n'%set_css + \
|
||||
' <blockquote class="%s"%s%s%s>\n'%(
|
||||
set_css, lang, cite, title_html
|
||||
) + \
|
||||
time_html_o + \
|
||||
'%s\n'%quote_html + \
|
||||
time_html_c + \
|
||||
' </blockquote>\n' + \
|
||||
' <figcaption class="%s">\n'%set_css + \
|
||||
' %s\n'%figc + \
|
||||
' </figcaption>\n' + \
|
||||
'</figure>'
|
||||
quote_html = \
|
||||
'<figure class="%s">\n'%set_css + \
|
||||
' <blockquote class="%s"%s%s%s>\n'%(
|
||||
set_css, lang, cite, title_html
|
||||
) + \
|
||||
time_html_o + \
|
||||
'%s\n'%quote_html + \
|
||||
time_html_c + \
|
||||
' </blockquote>\n' + \
|
||||
' <figcaption class="%s">\n'%set_css + \
|
||||
' %s\n'%figc + \
|
||||
' </figcaption>\n' + \
|
||||
'</figure>'
|
||||
else:
|
||||
quote_html ='<blockquote class="%s"%s%s%s>\n'%(
|
||||
set_css, lang, cite, title_html
|
||||
) + \
|
||||
time_html_o + \
|
||||
'%s\n'%quote_html + \
|
||||
time_html_c + \
|
||||
'</blockquote>'
|
||||
quote_html = \
|
||||
'<blockquote class="%s"%s%s%s>\n'%(
|
||||
set_css, lang, cite, title_html
|
||||
) + \
|
||||
time_html_o + \
|
||||
'%s\n'%quote_html + \
|
||||
time_html_c + \
|
||||
'</blockquote>'
|
||||
|
||||
# Replace line with final HTML Quote
|
||||
post_bottom = post_bottom.replace('Q64.%s.Q64'%line,
|
||||
quote_html
|
||||
)
|
||||
replace_in_post('Q64.%s.Q64'%line,
|
||||
quote_html
|
||||
)
|
||||
|
||||
|
||||
#==========================#
|
||||
|
@ -588,13 +599,13 @@ def wip_quotes() :
|
|||
def wip_icodes():
|
||||
if db.post_icodes == 0: return
|
||||
|
||||
global post_bottom
|
||||
|
||||
matches = re.findall(r'I64.(.*?).I64', post_bottom)
|
||||
for match in matches:
|
||||
rep_icode = 'I64.' + match + '.I64'
|
||||
src_icode = tyto.b64("Decode", match, 'I64.', '.I64')
|
||||
post_bottom = post_bottom.replace(rep_icode, src_icode)
|
||||
replace_in_post(rep_icode,
|
||||
src_icode
|
||||
)
|
||||
|
||||
|
||||
#==================================================#
|
||||
|
@ -604,8 +615,6 @@ def wip_icodes():
|
|||
def wip_bcodes():
|
||||
if db.post_bcodes == 0: return
|
||||
|
||||
global post_bottom
|
||||
|
||||
matches = re.findall(r'B64.(.*?).B64', post_bottom)
|
||||
for match in matches:
|
||||
rep_bcode = 'B64.' + match + '.B64'
|
||||
|
@ -616,19 +625,26 @@ def wip_bcodes():
|
|||
# CSS + opened marker
|
||||
if line.startswith(tyto.words_tags[12][0]):
|
||||
set_css = tyto.get_css(line)
|
||||
html_bcode = '<pre class="%s">\n'%set_css + \
|
||||
' <code class="bcode">'
|
||||
html_bcode = \
|
||||
'<pre class="%s">\n'%set_css + \
|
||||
' <code class="bcode">'
|
||||
|
||||
# closed marker
|
||||
elif line.startswith(tyto.words_tags[12][1]):
|
||||
html_bcode = '%s\n </code>\n'%html_bcode + \
|
||||
'</pre>'
|
||||
html_bcode = \
|
||||
'%s\n </code>\n'%html_bcode + \
|
||||
'</pre>'
|
||||
|
||||
# Block-code content per line
|
||||
else:
|
||||
html_bcode = '%s\n <span class="bcode">%s</span>'%(html_bcode,
|
||||
line
|
||||
)
|
||||
html_bcode = \
|
||||
'%s\n <span class="bcode">%s</span>'%(
|
||||
html_bcode, line
|
||||
)
|
||||
|
||||
post_bottom = post_bottom.replace(rep_bcode, html_bcode)
|
||||
replace_in_post(rep_bcode,
|
||||
html_bcode
|
||||
)
|
||||
|
||||
|
||||
#========================================#
|
||||
|
@ -639,6 +655,7 @@ def wip_titles():
|
|||
if db.post_titles == 0: return
|
||||
|
||||
global post_bottom
|
||||
|
||||
article_temp = post_bottom
|
||||
article_tmp2 = '' # Construct article, without empty lines
|
||||
|
||||
|
@ -656,7 +673,7 @@ def wip_titles():
|
|||
for line in article_temp.rsplit('\n'):
|
||||
if line:
|
||||
if article_tmp2: article_tmp2 = '%s\n%s'%(article_tmp2, line)
|
||||
else: article_tmp2 = line
|
||||
else: article_tmp2 = line
|
||||
|
||||
article_temp = article_tmp2
|
||||
|
||||
|
@ -669,9 +686,10 @@ def wip_titles():
|
|||
if article_tmp2.rsplit('\n')[ln + 1].startswith('<h'):
|
||||
continue
|
||||
else:
|
||||
article_temp = article_temp.replace(
|
||||
line, '%s\n<div class="title_%s">'%(line, hx)
|
||||
)
|
||||
article_temp = \
|
||||
article_temp.replace(line,
|
||||
'%s\n<div class="title_%s">'%(line, hx)
|
||||
)
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
@ -684,9 +702,10 @@ def wip_titles():
|
|||
except: continue
|
||||
|
||||
if line.startswith('<h') and indiv:
|
||||
article_temp = article_temp.replace(
|
||||
line, '</div>\n%s'%line
|
||||
)
|
||||
article_temp = \
|
||||
article_temp.replace(line,
|
||||
'</div>\n%s'%line
|
||||
)
|
||||
indiv = False
|
||||
|
||||
if article_tmp2.rsplit('\n')[ln + 1].startswith('<div'):
|
||||
|
@ -703,31 +722,175 @@ def wip_titles():
|
|||
#==============================================#
|
||||
# Convert raw file to HTML with <pre> + <code> #
|
||||
#----------------------------------------------#
|
||||
def wip_raws(target):
|
||||
if db.uniq_raws == 0: return
|
||||
def wip_filecode(target):
|
||||
if db.uniq_codes == 0: return
|
||||
|
||||
for i in range(1, db.uniq_codes + 1):
|
||||
code = 'db.code_%s'%i
|
||||
code_file = open('%s%s'%(dom.articles_d, eval(code)[1])).read()
|
||||
code_html = '<pre class="%s" title="%s">\n'%(
|
||||
dom.css, eval(code)[2]
|
||||
) + \
|
||||
' <code class="bcode">'
|
||||
|
||||
for line in code_file.rsplit('\n'):
|
||||
code_html = '%s\n <span class="bcode">%s</span>'%(
|
||||
code_html, line
|
||||
)
|
||||
|
||||
code_html = '%s\n </code>\n</pre>'%(code_html)
|
||||
replace_in_post(eval(code)[0],
|
||||
code_html
|
||||
)
|
||||
|
||||
|
||||
#==============================#
|
||||
# Search lines for list marker #
|
||||
#------------------------------#
|
||||
def wip_lists():
|
||||
if not db.post_lists > 0: return
|
||||
|
||||
global post_bottom
|
||||
|
||||
for i in range(1, db.uniq_raws + 1):
|
||||
raw = 'db.raw_%s'%i
|
||||
raw_file = open(
|
||||
'%s%s'%(
|
||||
db.domain_articles, eval(raw)[1]
|
||||
)
|
||||
).read()
|
||||
raw_html = '<pre class="%s" title="%s">\n'%(
|
||||
db.domain_css, eval(raw)[2]
|
||||
) + \
|
||||
' <code class="bcode">'
|
||||
for line in raw_file.rsplit('\n'):
|
||||
raw_html = '%s\n <span class="bcode">%s</span>'%(
|
||||
raw_html, line
|
||||
)
|
||||
content_list = ''
|
||||
in_list = False
|
||||
|
||||
raw_html = '%s\n </code>\n</pre>'%(raw_html)
|
||||
post_bottom = post_bottom.replace(eval(raw)[0],
|
||||
raw_html
|
||||
)
|
||||
for line in post_bottom.rsplit('\n'):
|
||||
# Open list
|
||||
if line.startswith(tyto.words_tags[13][0]):
|
||||
css = tyto.get_css(line)
|
||||
in_list = True
|
||||
content_list = line
|
||||
continue
|
||||
|
||||
# Close list
|
||||
elif line.startswith(tyto.words_tags[13][1]):
|
||||
in_list = False
|
||||
content_list = '%s\n%s'%(content_list, line)
|
||||
html_list = convert_list(
|
||||
content_list
|
||||
).replace('<ul>',
|
||||
'<ul class="%s">'%css, 1
|
||||
).replace('<li>',
|
||||
'<li class="%s">'%css
|
||||
) + '</ul>'
|
||||
replace_in_post(content_list, html_list)
|
||||
|
||||
if in_list:
|
||||
content_list = '%s\n%s'%(content_list, line)
|
||||
|
||||
else:
|
||||
continue
|
||||
|
||||
|
||||
#===================================#
|
||||
# Convert list with markers to HTML #
|
||||
# Def from neox <- Thx a lot #
|
||||
# (Did little few updates) #
|
||||
#-----------------------------------#
|
||||
def convert_list(markdown_str):
|
||||
# First step : reshape lines
|
||||
items = []
|
||||
inside_item = 0
|
||||
index = -1
|
||||
|
||||
# Cut string with \n's
|
||||
strlist = markdown_str.split("\n")
|
||||
|
||||
# Find items
|
||||
for i in range(len(strlist)):
|
||||
if tyto.words_tags[13][0] in strlist[i] or \
|
||||
tyto.words_tags[13][1] in strlist[i]:
|
||||
continue
|
||||
|
||||
# = and +
|
||||
if strlist[i][0] != tyto.markers_lists[1] and \
|
||||
strlist[i][0] != tyto.markers_lists[0]:
|
||||
if inside_item != 1:
|
||||
inside_item = 1
|
||||
else:
|
||||
inside_item = 0
|
||||
|
||||
if inside_item == 0:
|
||||
items.append(strlist[i])
|
||||
index += 1
|
||||
|
||||
if inside_item == 1:
|
||||
items[index] = '%s '%items[index] # Add one space
|
||||
items[index] += strlist[i].lstrip()
|
||||
|
||||
# Second step : parsing
|
||||
UL = 1
|
||||
OL = 2
|
||||
CLOSING = ["ERROR", "</ul>\n", "</ol>\n"]
|
||||
OPENING = ["ERROR", "<ul>\n", "<ol>\n"]
|
||||
|
||||
rank_stack = []
|
||||
rank = 0
|
||||
cur_rank = 0
|
||||
state = 0
|
||||
old_state = 0
|
||||
work_str = ""
|
||||
|
||||
for i in range(len(items)):
|
||||
if tyto.words_tags[13][0] in items[i] or \
|
||||
tyto.words_tags[13][1] in items[i]:
|
||||
continue
|
||||
|
||||
rank = cur_rank
|
||||
descriptor = items[i].split(" ")[0]
|
||||
text = items[i][items[i].find(" "):].lstrip()
|
||||
cur_rank = len(descriptor)
|
||||
|
||||
if "=" in descriptor:
|
||||
state = UL
|
||||
elif "+" in descriptor:
|
||||
state = OL
|
||||
else:
|
||||
raise(Exception)
|
||||
|
||||
# rank up
|
||||
if cur_rank > rank:
|
||||
for i in range(cur_rank - rank - 1):
|
||||
work_str += " "*(rank+i) + OPENING[rank_stack.append(UL)]
|
||||
rank_stack.append(state)
|
||||
|
||||
work_str += " "*rank + OPENING[state]
|
||||
|
||||
# rank down
|
||||
elif cur_rank < rank:
|
||||
for i in range(rank - cur_rank - 1):
|
||||
work_str += " "*(rank-i-1) + CLOSING[rank_stack.pop()]
|
||||
|
||||
work_str += " "*cur_rank + CLOSING[rank_stack.pop()]
|
||||
|
||||
work_str += " "*cur_rank + '<li>' + text + "</li>\n"
|
||||
|
||||
work_str += " "*(cur_rank-1) + CLOSING[rank_stack.pop()]
|
||||
|
||||
return work_str
|
||||
|
||||
|
||||
#=======================================#
|
||||
# Replace tag with contents of raw file #
|
||||
#---------------------------------------#
|
||||
def wip_fileraws(target):
|
||||
for i in range(1, db.uniq_raws + 1):
|
||||
raw = 'db.raw_%s'%i
|
||||
raw_file = open('%s%s'%(dom.articles_d, eval(raw)[1])).read()
|
||||
if eval(raw)[2]:
|
||||
raw_alt = ' # %s'%eval(raw)[2]
|
||||
raw_inc = '<!--Tyto_Include file%s-->'%raw_alt
|
||||
|
||||
for line in raw_file.rsplit('\n'):
|
||||
if not line:
|
||||
continue
|
||||
raw_inc = '%s\n%s'%(raw_inc, line)
|
||||
|
||||
raw_inc = '%s\n<!--/Tyto_Include file%s-->'%(raw_inc, raw_alt)
|
||||
replace_in_post(eval(raw)[0],
|
||||
raw_inc
|
||||
)
|
||||
|
||||
|
||||
#=======================#
|
||||
|
@ -735,6 +898,7 @@ def wip_raws(target):
|
|||
#-----------------------#
|
||||
def wip_tabs():
|
||||
global post_bottom
|
||||
|
||||
article_temp = ''
|
||||
tab = tab_start = 6 # From <article> tag
|
||||
indiv = False
|
||||
|
@ -748,9 +912,17 @@ def wip_tabs():
|
|||
'6' : '16'
|
||||
}
|
||||
|
||||
cs = 0
|
||||
for line in post_bottom.rsplit('\n'):
|
||||
# Titles
|
||||
if line.startswith('<h'):
|
||||
if line.startswith('<!'):
|
||||
if cs != 1:
|
||||
cs += 1
|
||||
article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
tab = int(tab) - 2
|
||||
continue
|
||||
|
||||
elif line.startswith('<h'):
|
||||
get_tab = line[2]
|
||||
tab = tabs_hX[get_tab]
|
||||
if not article_temp:
|
||||
|
@ -760,12 +932,13 @@ def wip_tabs():
|
|||
continue
|
||||
|
||||
# div
|
||||
if line.startswith('<div'):
|
||||
elif line.startswith('<div'):
|
||||
tab = int(tab) + 2
|
||||
indiv = True
|
||||
article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
tab = int(tab) + 2
|
||||
continue
|
||||
|
||||
elif line.startswith('</div>'):
|
||||
tab = int(tab) - 2
|
||||
article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
|
@ -781,94 +954,3 @@ def wip_tabs():
|
|||
|
||||
post_bottom = article_temp
|
||||
|
||||
|
||||
#=================================#
|
||||
# Convert list in markers to HTML #
|
||||
# Def from neox <- Thx a lot #
|
||||
#---------------------------------#
|
||||
def convert_list(markdown_str):
|
||||
|
||||
# First step : reshape lines
|
||||
|
||||
items = []
|
||||
inside_item = 0
|
||||
index = -1
|
||||
|
||||
# Cut string with \n's
|
||||
strlist = markdown_slangs.site.split("\n")
|
||||
|
||||
# Find items
|
||||
for i in range(len(strlist)):
|
||||
if "-(" in strlist[i] or "-)" in strlist[i]:
|
||||
continue
|
||||
|
||||
if strlist[i][0] != "=" and strlist[i][0] != "+":
|
||||
if inside_item != 1:
|
||||
inside_item = 1
|
||||
else:
|
||||
inside_item = 0
|
||||
|
||||
if inside_item == 0:
|
||||
items.append(strlist[i])
|
||||
index += 1
|
||||
|
||||
if inside_item == 1:
|
||||
items[index] += strlist[i].lstrip()
|
||||
|
||||
#print("[{}] index {}, inside_item {}, curstr {}\n".format(i, index, inside_item, strlist[i]))
|
||||
|
||||
# Second step : parsing
|
||||
UL = 1
|
||||
OL = 2
|
||||
CLOSING = ["ERROR", "</ul>\n", "</ol>\n"]
|
||||
OPENING = ["ERROR", "<ul>\n", "<ol>\n"]
|
||||
|
||||
rank_stack = []
|
||||
rank = 0
|
||||
cur_rank = 0
|
||||
state = 0
|
||||
old_state = 0
|
||||
work_str = ""
|
||||
|
||||
for i in range(len(items)):
|
||||
if "-(" in items[i] or "-)" in items[i]:
|
||||
continue
|
||||
rank = cur_rank
|
||||
descriptor = items[i].split(" ")[0]
|
||||
text = items[i][items[i].find(" "):]
|
||||
cur_rank = len(descriptor)
|
||||
|
||||
if "=" in descriptor:
|
||||
state = UL
|
||||
elif "+" in descriptor:
|
||||
state = OL
|
||||
else:
|
||||
raise(Exception)
|
||||
|
||||
# rank up
|
||||
if cur_rank > rank:
|
||||
for i in range(cur_rank - rank - 1):
|
||||
work_str += " "*(rank+i) + OPENING[rank_stack.append(UL)]
|
||||
rank_stack.append(state)
|
||||
|
||||
work_str += " "*rank + OPENING[state]
|
||||
|
||||
# rank down
|
||||
elif cur_rank < rank:
|
||||
for i in range(rank - cur_rank - 1):
|
||||
work_str += " "*(rank-i-1) + CLOSING[rank_stack.pop()]
|
||||
|
||||
work_str += " "*cur_rank + CLOSING[rank_stack.pop()]
|
||||
|
||||
|
||||
work_str += " "*cur_rank + "<li>" + text + "</li>\n"
|
||||
|
||||
print("[{}] rank_stack {}, state {}, old_state {}, rank {}, cur_rank {}, text {}\n".format(
|
||||
i, rank_stack, state, old_state, rank, cur_rank, text))
|
||||
|
||||
work_str += " "*(cur_rank-1) + CLOSING[rank_stack.pop()]
|
||||
|
||||
return(work_str)
|
||||
|
||||
|
||||
#print(convert_list(str_exemple))
|
||||
|
|
|
@ -46,6 +46,7 @@ post_val = "Article is valid"
|
|||
post_chg = "Article changed: 'check' it first"
|
||||
sep_inv = "Unused separator in article"
|
||||
unused_v = "Unused value in article"
|
||||
unused_t = "Unused value in header"
|
||||
unused_p = "Empty article"
|
||||
mark_np = "Not paired marks"
|
||||
symb_np = "Not paired symbols"
|
||||
|
|
|
@ -46,6 +46,7 @@ post_val = "Article valide"
|
|||
post_chg = "Article modifié : commencer par 'check'"
|
||||
sep_inv = "Séparateur manquant dans l'article"
|
||||
unused_v = "Valeur manquante dans l'article"
|
||||
unused_t = "Valeur manquante dans l'entête"
|
||||
unused_p = "L'article est vide"
|
||||
mark_np = "Marqueurs non jumelés"
|
||||
symb_np = "Symboles non jumelés"
|
||||
|
|
|
@ -29,7 +29,7 @@ footer = 'Footer'
|
|||
title = 'Title'
|
||||
File = 'File'
|
||||
name = 'Name'
|
||||
by = 'par'
|
||||
by = "by"
|
||||
q = '?'
|
||||
i = '!'
|
||||
pp = ":"
|
||||
|
@ -45,7 +45,8 @@ tyto_psrc = "Show this article's source code in Tyto format"
|
|||
w_written = "was written the"
|
||||
w_published = "was published the"
|
||||
written = "written the"
|
||||
published = "wpublished the"
|
||||
written_by = 'written by'
|
||||
published = "Published the"
|
||||
|
||||
# Sidebar
|
||||
site_sdb_t = "Featured..."
|
||||
|
|
|
@ -29,7 +29,7 @@ footer = 'Pied de Page'
|
|||
title = 'Titre'
|
||||
File = 'Fichier'
|
||||
name = 'Nom'
|
||||
by = 'par'
|
||||
by = "par"
|
||||
q = ' ?'
|
||||
i = ' !'
|
||||
pp = " :"
|
||||
|
@ -45,7 +45,8 @@ tyto_psrc = "Voir le code source au format Tyto de cet article"
|
|||
w_written = "a été écrit le"
|
||||
w_published = "a été publié le"
|
||||
written = "écrit le"
|
||||
published = "publié le"
|
||||
written_by = 'écrit par'
|
||||
published = "Publié le"
|
||||
|
||||
# Barre latérale
|
||||
site_sdb_t = "À l'affiche..."
|
||||
|
|
Loading…
Reference in New Issue