diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 0409cdd..d5dfb5b 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -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, } diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py index 62c9b7c..e00e599 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -69,6 +69,7 @@ pass_targets = \ 'metas', 'navbar', 'sidebar', + 'stats', 'template' ) diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index fe5bbd8..5b0c470 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -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 diff --git a/src/var/lib/tyto/program/infos.py b/src/var/lib/tyto/program/infos.py index 50135ed..09833ad 100644 --- a/src/var/lib/tyto/program/infos.py +++ b/src/var/lib/tyto/program/infos.py @@ -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' diff --git a/src/var/lib/tyto/program/stats.py b/src/var/lib/tyto/program/stats.py new file mode 100644 index 0000000..6179bf2 --- /dev/null +++ b/src/var/lib/tyto/program/stats.py @@ -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 + diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index d8aba7e..f45d823 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -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 = [ diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 03533fe..c488234 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -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 = '%s'%(hx, hx, title_cont, hx) + title_html = '%s'%( + hx, hx, title_cont, hx + ) article_temp = article_temp.replace(line, title_html) @@ -696,8 +701,10 @@ def wip_tabs(): if line.startswith('