Statoolinfos. Indev to create stat files on command for wip/www server
This commit is contained in:
parent
7a93bfccc3
commit
8a43b795bb
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# Version: 0.9.0
|
||||
# Version: 0.9.1
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: Executable
|
||||
# Description: Multiple Static Websites generator and manager
|
||||
|
@ -57,7 +57,7 @@ actions = {
|
|||
'show-db' : show.manage_show,
|
||||
'show-wip' : show.manage_show,
|
||||
'show-www' : show.manage_show,
|
||||
'template' : publish.manage_publish,
|
||||
'template' : publish.manage_publish,
|
||||
'wip' : wip.manage_wip,
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ pass_targets = \
|
|||
'metas',
|
||||
'navbar',
|
||||
'sidebar',
|
||||
'stats',
|
||||
'template'
|
||||
)
|
||||
|
||||
|
|
|
@ -138,8 +138,7 @@ def manage_check(target):
|
|||
# Check if separator or exit #
|
||||
#---------------------------------#
|
||||
def file_to_string(post_file):
|
||||
global article
|
||||
global post_header, post_bottom
|
||||
global article, post_header, post_bottom
|
||||
|
||||
post_header = post_bottom = ''
|
||||
sep = False
|
||||
|
|
|
@ -79,7 +79,8 @@ def tyto(target):
|
|||
' footer : Create/Show footer HTML config\'s file\n'
|
||||
' metas : Create/Show metas HTML config\'s file\n'
|
||||
' navbar : Create/Show navbar config\'s file\n'
|
||||
' sidebar : Create/Show sidebar config\'s file\n\n'
|
||||
' sidebar : Create/Show sidebar config\'s file\n'
|
||||
' stats : Create statistics file in root srv\n\n'
|
||||
'# Examples:\n'
|
||||
' - Check article\'s syntax: tyto check mysubdir/index.tyto\n'
|
||||
' - Create default _configs/tyto.sidebar: tyto new sidebar\n'
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: Statistics generator
|
||||
# Description: Create/Show statistics (wip, publish...)
|
||||
# file: stats.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
#------------
|
||||
# lines:
|
||||
# functions:
|
||||
# comments:
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#**********************************************************************
|
||||
|
||||
import os, importlib
|
||||
import args, logs, db, domain, tyto
|
||||
|
||||
sti_anchors = sti_abbrs = sti_links = 0
|
||||
sti_images = sti_files = sti_raws = 0
|
||||
sti_tags = sti_words = sti_titles = sti_paragraphs = sti_anclink = 0
|
||||
sti_strongs = sti_bolds = sti_emphasis = sti_italics = sti_dels = 0
|
||||
sti_underlines = sti_cites = sti_customs = sti_icodes = 0
|
||||
sti_bcodes = sti_quotes = sti_lists = 0
|
||||
|
||||
#=======================#
|
||||
# Manage "stats" option #
|
||||
#-----------------------#
|
||||
def manage_stats(process):
|
||||
domain.domain_needed()
|
||||
|
||||
do = {
|
||||
'wip' : loop_articles,
|
||||
'www' : loop_articles,
|
||||
'show-wip' : count_stats, # NO
|
||||
'show_www' : count_stats, # NO
|
||||
}
|
||||
|
||||
do[args.action](process)
|
||||
|
||||
|
||||
def loop_articles(process):
|
||||
if process == 'wip':
|
||||
file_stats = '%s%s'%(db.srv_wip, tyto.stats_f)
|
||||
elif process == 'www':
|
||||
file_stats = '%s%s'%(db.srv_www, tyto.stats_f)
|
||||
|
||||
# Get databases of wip's articles
|
||||
for post_db in os.listdir(db.articles_db):
|
||||
if post_db.endswith('.conf'):
|
||||
# Load DB
|
||||
post_db = '%s%s'%(db.articles_db, post_db)
|
||||
exec(open(post_db).read(),globals())
|
||||
args.target = post_src.rsplit('%s/'%db.in_dir)[1]
|
||||
importlib.reload(db)
|
||||
|
||||
# Check hash status (wip/www)
|
||||
# wip
|
||||
if process == 'wip':
|
||||
if not db.hash_wip: continue
|
||||
|
||||
print(':> [%s] | %s'%(db.title, db.post_src))
|
||||
|
||||
# Article has changed and could have different stats
|
||||
if not db.hash_wip == db.hash_chk:
|
||||
logs.out("9", db.post_src, False)
|
||||
continue
|
||||
|
||||
count_stats()
|
||||
|
||||
# www
|
||||
elif process == 'www':
|
||||
if not db.hash_www: continue
|
||||
|
||||
print("> anchors", sti_anchors, sti_strongs)
|
||||
logs.out("33", file_stats, False)
|
||||
|
||||
#
|
||||
# Set Statistics and count
|
||||
#
|
||||
def count_stats():
|
||||
# Set Statistics
|
||||
global sti_anchors, sti_abbrs, sti_links
|
||||
global sti_images, sti_files, sti_raws
|
||||
global sti_tags, sti_words, sti_titles, sti_paragraphs, sti_anclink
|
||||
global sti_strongs, sti_bolds, sti_emphasis, sti_italics, sti_dels
|
||||
global sti_underlines, sti_cites, sti_customs, sti_icodes
|
||||
global sti_bcodes, sti_quotes, sti_lists
|
||||
|
||||
# Set statistics
|
||||
sti_anchors = sti_anchors + db.uniq_anchors
|
||||
sti_abbrs = sti_abbrs + db.uniq_abbrs
|
||||
sti_links = sti_links + db.uniq_links
|
||||
sti_images = sti_images + db.uniq_images
|
||||
sti_files = sti_files + db.uniq_files
|
||||
sti_raws = sti_raws + db.uniq_raws
|
||||
sti_tags = sti_tags + db.stat_tags
|
||||
sti_words = sti_words + db.stat_words
|
||||
sti_titles = sti_titles + db.stat_titles
|
||||
sti_paragraphs = sti_paragraphs + db.stat_paragraphs
|
||||
sti_anclink = sti_anclink + db.stat_anchors
|
||||
sti_strongs = sti_strongs + db.stat_strongs
|
||||
sti_bolds = sti_bolds + db.stat_bolds
|
||||
sti_emphasis = sti_emphasis + db.stat_emphasis
|
||||
sti_italics = sti_italics + db.stat_italics
|
||||
sti_dels = sti_dels + db.stat_dels
|
||||
sti_underlines = sti_underlines + db.stat_underlines
|
||||
sti_cites = sti_cites + db.stat_cites
|
||||
sti_customs = sti_customs + db.stat_customs
|
||||
sti_icodes = sti_icodes + db.stat_icodes
|
||||
sti_bcodes = sti_bcodes + db.stat_bcodes
|
||||
sti_quotes = sti_quotes + db.stat_quotes
|
||||
sti_lists = sti_lists + db.stat_lists
|
||||
|
|
@ -38,6 +38,7 @@ else: n = 1
|
|||
Tyto = 'Tyto - Littérateur'
|
||||
Tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur'
|
||||
Tytoweb = 'https://tyto.echolib.re'
|
||||
stats_f = 'tyto_statoolinfos.conf'
|
||||
|
||||
# Translations French/English
|
||||
trans = [
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
import os, re, shutil, importlib
|
||||
import logs, args, db, tyto, html, domain
|
||||
import logs, args, db, tyto, html, domain, stats
|
||||
|
||||
|
||||
#=========================================#
|
||||
|
@ -30,45 +30,18 @@ def manage_wip(target):
|
|||
# Check if can process
|
||||
domain.domain_needed()
|
||||
|
||||
wip_article(db.post_src)
|
||||
return
|
||||
|
||||
# Option 'all' to wip again, based on DB
|
||||
#---------------------------------------
|
||||
if target == 'all':
|
||||
ask = ''
|
||||
ask = input(" ├ Wip again all already converted articles ? ")
|
||||
if not ask in ['y', 'Y']:
|
||||
return
|
||||
|
||||
# Load domain configuration DB
|
||||
for post_db in os.listdir(db.articles_db):
|
||||
if post_db.endswith('.conf'):
|
||||
# Load DB
|
||||
post_db = '%s%s'%(db.articles_db, post_db)
|
||||
exec(open(post_db).read(),globals())
|
||||
args.target = post_src.rsplit('%s/'%db.in_dir)[1]
|
||||
importlib.reload(db)
|
||||
if not db.hash_wip:
|
||||
continue
|
||||
|
||||
print(':> [%s] | %s'%(db.title, db.post_src))
|
||||
hash_post = tyto.get_filesum(db.post_src, True) # From content file
|
||||
if hash_post != db.hash_chk:
|
||||
logs.out("25", db.uri_file, False)
|
||||
ocontinue
|
||||
wip_article(db.post_src)
|
||||
return
|
||||
|
||||
# wip_article(db.post_src) ; return # Force wip without checking
|
||||
|
||||
# Target is footer, sidebar, navbar, metas
|
||||
#-----------------------------------------
|
||||
if target in args.pass_targets:
|
||||
do = {
|
||||
'all' : wip_all,
|
||||
'sidebar' : html.create_sidebar,
|
||||
'navbar' : html.create_navbar,
|
||||
'metas' : html.create_user_metas,
|
||||
'footer' : html.create_user_footer
|
||||
'footer' : html.create_user_footer,
|
||||
'stats' : stats.manage_stats
|
||||
}
|
||||
|
||||
do[target]('wip')
|
||||
|
@ -100,6 +73,37 @@ def manage_wip(target):
|
|||
wip_article(db.uri_file)
|
||||
|
||||
|
||||
#========================================#
|
||||
# Option 'all' to wip again, based on DB #
|
||||
#----------------------------------------#
|
||||
def wip_all(process):
|
||||
|
||||
# if target == 'all':
|
||||
ask = ''
|
||||
ask = input(" ├ Wip again all already converted articles ? ")
|
||||
if not ask in ['y', 'Y']:
|
||||
return
|
||||
|
||||
# Load domain configuration DB
|
||||
for post_db in os.listdir(db.articles_db):
|
||||
if post_db.endswith('.conf'):
|
||||
# Load DB
|
||||
post_db = '%s%s'%(db.articles_db, post_db)
|
||||
exec(open(post_db).read(),globals())
|
||||
args.target = post_src.rsplit('%s/'%db.in_dir)[1]
|
||||
importlib.reload(db)
|
||||
if not db.hash_wip:
|
||||
continue
|
||||
|
||||
print(':> [%s] | %s'%(db.title, db.post_src))
|
||||
hash_post = tyto.get_filesum(db.post_src, True) # From content file
|
||||
if hash_post != db.hash_chk:
|
||||
logs.out("25", db.uri_file, False)
|
||||
continue
|
||||
wip_article(db.post_src)
|
||||
return
|
||||
|
||||
|
||||
#===================#
|
||||
# Start wip modules #
|
||||
# Set DB #
|
||||
|
@ -153,12 +157,9 @@ def wip_article(target):
|
|||
|
||||
#=================================#
|
||||
# Create string article from file #
|
||||
# post is string splitted '\n' #
|
||||
# article is string not splitted #
|
||||
#---------------------------------#
|
||||
def file_to_string(post_file):
|
||||
global article
|
||||
global post_header, post_bottom
|
||||
global article, post_header, post_bottom
|
||||
|
||||
post_header = post_bottom = ''
|
||||
sep = False
|
||||
|
@ -442,7 +443,9 @@ def wip_quotes() :
|
|||
if qline.startswith(tyto.words_tags[10][1]):
|
||||
# Replace closed paragrph with html line
|
||||
qline_html = tyto.words_tags[10][3]
|
||||
quote_html = '%s\n%s%s'%(quote_html, int(tab_p) * ' ',qline_html)
|
||||
quote_html = '%s\n%s%s'%(
|
||||
quote_html, int(tab_p) * ' ', qline_html
|
||||
)
|
||||
continue
|
||||
|
||||
# End of marker quote
|
||||
|
@ -591,7 +594,9 @@ def wip_titles():
|
|||
if line.startswith('#'):
|
||||
hx = line[1]
|
||||
title_cont = line[2: len(line)].lstrip()
|
||||
title_html = '<h%s class="title_%s">%s</h%s>'%(hx, hx, title_cont, hx)
|
||||
title_html = '<h%s class="title_%s">%s</h%s>'%(
|
||||
hx, hx, title_cont, hx
|
||||
)
|
||||
article_temp = article_temp.replace(line, title_html)
|
||||
|
||||
|
||||
|
@ -696,8 +701,10 @@ def wip_tabs():
|
|||
if line.startswith('<h'):
|
||||
get_tab = line[2]
|
||||
tab = tabs_hX[get_tab]
|
||||
if not article_temp: article_temp = '%s%s'%(int(tab) * ' ', line)
|
||||
else: article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
if not article_temp:
|
||||
article_temp = '%s%s'%(int(tab) * ' ', line)
|
||||
else:
|
||||
article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
continue
|
||||
|
||||
# div
|
||||
|
@ -715,8 +722,10 @@ def wip_tabs():
|
|||
|
||||
# Other contents
|
||||
else:
|
||||
if not article_temp: article_temp = '%s%s'%(int(tab) * ' ', line)
|
||||
else: article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
if not article_temp:
|
||||
article_temp = '%s%s'%(int(tab) * ' ', line)
|
||||
else:
|
||||
article_temp = '%s\n%s%s'%(article_temp, int(tab) * ' ', line)
|
||||
|
||||
post_bottom = article_temp
|
||||
|
||||
|
|
Loading…
Reference in New Issue