diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 3cc37cb..5daf1c0 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -858,6 +858,6 @@ def create_database(): # Create Post DB #--------------- database = '%s\n%s\n%s'%(database, opt_tags, db_stats) - tyto.set_file(db.config, 'new', database) + tyto.set_file(db.config, 'New', database) logs.out("21", db.uri_file, False) diff --git a/src/var/lib/tyto/program/form.py b/src/var/lib/tyto/program/form.py index 82b472c..b597485 100644 --- a/src/var/lib/tyto/program/form.py +++ b/src/var/lib/tyto/program/form.py @@ -37,7 +37,6 @@ from datetime import datetime import os, sys, re, locale, importlib - import logs, dom, tyto, html, show, langs # locale translation directory @@ -184,7 +183,6 @@ def create_domain(target): # Start registering variables in domain database #----------------------------------------------- - global navbars_conf local_user = '%s/.local/tyto/%s/'%(dom.home_dir, shortname) modules_dir = '%s/articles/_configs/'%dom.folder footer_about_f = '%sfooter_about.html'%modules_dir @@ -215,7 +213,6 @@ def create_domain(target): 'wip_url = "%s"\n'%wip_url tyto.set_file(dom.config, True, set_f) - logs.out("32", dom.config, False) # Get srv root @@ -254,33 +251,34 @@ def create_domain(target): root_srv_dom = '%s/%s'%(srv, shortname) srv_wip_tpl = "%s/wip/template/"%root_srv_dom srv_www_tpl = "%s/www/template/"%root_srv_dom - set_f = '# Servers directories\n' + \ - 'srv_root = "%s/"\n'%srv + \ - 'srv_domain = "%s/"\n'%root_srv_dom + \ - 'srv_wip = "%s/wip/"\n'%root_srv_dom + \ - 'srv_wip_tpl_d = "%s"\n'%srv_wip_tpl + \ - 'srv_wip_images_d = "%s/wip/images/"\n'%root_srv_dom + \ - 'srv_wip_files_d = "%s/wip/files/"\n'%root_srv_dom + \ - 'srv_www = "%s/www/"\n'%root_srv_dom + \ - 'srv_www_tpl_d = "%s"\n'%srv_www_tpl + \ - 'srv_www_images_d = "%s/www/images/"\n'%root_srv_dom + \ - 'srv_www_files_d = "%s/www/files/"\n'%root_srv_dom + \ - '\n' + \ - '# Servers files (wip)\n' + \ - 'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \ - 'wip_css_f = "%sstyles.css"\n'%srv_wip_tpl + \ - 'wip_navbar_f = "%snavbar.html"\n'%srv_wip_tpl + \ - 'wip_sidebar_f = "%ssidebar.html"\n'%srv_wip_tpl + \ - 'wip_metas_f = "%smetas.html"\n'%srv_wip_tpl + \ - 'wip_footer_f = "%sfooter.html"\n'%srv_wip_tpl + \ - '\n' + \ - '# Servers files (www)\n' + \ - 'www_logo_f = "%s%s"\n'%(srv_www_tpl, logo) + \ - 'www_css_f = "%sstyles.css"\n'%srv_www_tpl + \ - 'www_navbar_f = "%snavbar.html"\n'%srv_www_tpl + \ - 'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \ - 'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \ - 'www_footer_f = "%sfooter.html"'%srv_www_tpl + set_f = \ + '# Servers directories\n' + \ + 'srv_root = "%s/"\n'%srv + \ + 'srv_domain = "%s/"\n'%root_srv_dom + \ + 'srv_wip = "%s/wip/"\n'%root_srv_dom + \ + 'srv_wip_tpl_d = "%s"\n'%srv_wip_tpl + \ + 'srv_wip_images_d = "%s/wip/images/"\n'%root_srv_dom + \ + 'srv_wip_files_d = "%s/wip/files/"\n'%root_srv_dom + \ + 'srv_www = "%s/www/"\n'%root_srv_dom + \ + 'srv_www_tpl_d = "%s"\n'%srv_www_tpl + \ + 'srv_www_images_d = "%s/www/images/"\n'%root_srv_dom + \ + 'srv_www_files_d = "%s/www/files/"\n'%root_srv_dom + \ + '\n' + \ + '# Servers files (wip)\n' + \ + 'wip_logo_f = "%s%s"\n'%(srv_wip_tpl, logo) + \ + 'wip_css_f = "%sstyles.css"\n'%srv_wip_tpl + \ + 'wip_navbar_f = "%snavbar.html"\n'%srv_wip_tpl + \ + 'wip_sidebar_f = "%ssidebar.html"\n'%srv_wip_tpl + \ + 'wip_metas_f = "%smetas.html"\n'%srv_wip_tpl + \ + 'wip_footer_f = "%sfooter.html"\n'%srv_wip_tpl + \ + '\n' + \ + '# Servers files (www)\n' + \ + 'www_logo_f = "%s%s"\n'%(srv_www_tpl, logo) + \ + 'www_css_f = "%sstyles.css"\n'%srv_www_tpl + \ + 'www_navbar_f = "%snavbar.html"\n'%srv_www_tpl + \ + 'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \ + 'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \ + 'www_footer_f = "%sfooter.html"'%srv_www_tpl tyto.set_file(dom.config, False, set_f) @@ -758,8 +756,7 @@ def create_metas(option): '\n' + \ '' - tyto.set_file(dom.metas_f, 'new', metas_tags) - logs.out("32", dom.metas_f, False) + tyto.set_file(dom.metas_f, 'New', metas_tags) # Create an empty html file in wip/www server if not exists if not tyto.exists(dom.wip_metas_f): @@ -820,8 +817,7 @@ def create_navbar(option): navbar_lang = navbar_lang%(tyto.Tyto, dom.navbar_f) - tyto.set_file(dom.navbar_f, 'new', navbar_lang) - logs.out("32", dom.navbar_f, False) + tyto.set_file(dom.navbar_f, 'New', navbar_lang) # Create wip navbar file html.create_navbar('wip') @@ -836,7 +832,6 @@ def create_sidebar(option): # Create an empty html file in wip/www server if not exists if not tyto.exists(dom.wip_sidebar_f): tyto.set_file(dom.wip_sidebar_f, 'new', '') - logs.out("32", dom.wip_sidebar_f, False) # Create new config file, or ask if exists with option = 'reset' if tyto.exists(dom.sidebar_f): @@ -887,8 +882,7 @@ def create_sidebar(option): dom.sidebar_items ) - tyto.set_file(dom.sidebar_f, 'new', sidebar_lang) - logs.out("32", dom.sidebar_f, False) + tyto.set_file(dom.sidebar_f, 'New', sidebar_lang) #=============================# @@ -1054,8 +1048,7 @@ def create_footer(option): if option == "form": return logs.out("255", '', True) - tyto.set_file(dom.footer_f, 'new', footer) - logs.out("32", dom.footer_f, False) + tyto.set_file(dom.footer_f, 'New', footer) # Create footer file in wip server if not exists if not tyto.exists(dom.wip_footer_f): @@ -1083,4 +1076,4 @@ def create_footer_about(option): ''%dom.about tyto.set_file(dom.footer_about_f, False, set_f) - logs.out("32", dom.footer_about_f, False) + diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index fa68e76..b5385e2 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -270,8 +270,7 @@ def create_user_metas(option): if user_metas: user_metas = "%s\n%s%s"%(user_metas, tab, line) else: user_metas = '%s%s'%(tab, line) - tyto.set_file(target, True, user_metas) - logs.out("32", target, False) + tyto.set_file(target, 'New', user_metas) #==============================================# @@ -366,7 +365,6 @@ def create_navbar(option): if not navbar_items: if not tyto.exists(target): tyto.set_file(target, 'New', '') - logs.out("32", target, False) logs.out('28', '%s'%langs.log.navbar, False) return @@ -382,7 +380,6 @@ def create_navbar(option): ), True) tyto.set_file(target, 'New', menu_html) - logs.out("32", target, False) #==============================================# @@ -483,7 +480,6 @@ def create_sidebar(option): if not sidebar_items: if not tyto.exists(target): tyto.set_file(target, 'New', '') - logs.out("32", target, False) logs.out('28', '%s'%langs.log.sidebar, False) return @@ -504,7 +500,6 @@ def create_sidebar(option): ), True) tyto.set_file(target, True, sidebar_content) - logs.out("32", target, False) #===================================================# @@ -533,5 +528,4 @@ def create_user_footer(option): else: footer = '%s%s'%(tab, line) tyto.set_file(target, 'New', footer) - logs.out("32", target, False) diff --git a/src/var/lib/tyto/program/logs.py b/src/var/lib/tyto/program/logs.py index 9777c5a..3d254f8 100644 --- a/src/var/lib/tyto/program/logs.py +++ b/src/var/lib/tyto/program/logs.py @@ -90,6 +90,8 @@ def out(nbr, value, out): '42' : ' ╒ %s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value), '43' : ' ╒ %s%s%s'%(CY, langs.log.dom_no, CS), '44' : ' ╞ %s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value), + '45' : ' ╞ %s%s %s%s > %s'%(CY, langs.log.meta_t, langs.log.no_up, CS, value), + '46' : ' ╞ %s%s %s%s > %s'%(CY, langs.log.time_t, langs.log.no_up, CS, value), '51' : ' ╞ %s%s%s > %s'%(CY, langs.log.data_inc, CS, value), '60' : ' │\n ╞ %s'%langs.log.status_r, '255' : ' ╘ %s'%langs.log.laterout diff --git a/src/var/lib/tyto/program/publish.py b/src/var/lib/tyto/program/publish.py index 1665548..7bf1d2e 100644 --- a/src/var/lib/tyto/program/publish.py +++ b/src/var/lib/tyto/program/publish.py @@ -74,7 +74,7 @@ def manage_publish(target): publish_article() # Create new ATOM/RSS file - #rss.create_feed() + rss.create_feed() #===============# @@ -100,10 +100,8 @@ def publish_article(): #-------------------------------------------------# def replace_lines_pub(): html.create_html_time_meta('publish') - print(html.time_html_pub) in_pub = False - time_wip_pub = '' wip_html_post = open(db.post_wip, 'r').read() www_html_post = wip_html_post @@ -116,8 +114,6 @@ def replace_lines_pub(): elif line.startswith(''): time_wip_pub = '%s\n%s'%(time_wip_pub, line) in_pub = False - print('> time_wip_pub') - print(time_wip_pub) break elif line.startswith(''): @@ -127,15 +123,27 @@ def replace_lines_pub(): 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) + # Update file with new time meta + try: + www_html_post = \ + www_html_post.replace(time_wip_meta, + html.meta_pub + ) + except: + logs.out("45", db.post_www, False) + + # update file with new article time + try: + www_html_post = \ + www_html_post.replace(time_wip_pub, + html.time_html_pub + ) + except: + logs.out("46", db.post_www, False) + #print(www_html_post) - tyto.set_file(db.post_www, 'new', www_html_post) - logs.out("32", db.post_www, False) + tyto.set_file(db.post_www, 'New', www_html_post) #================================# diff --git a/src/var/lib/tyto/program/rss.py b/src/var/lib/tyto/program/rss.py index c8c465c..6833547 100644 --- a/src/var/lib/tyto/program/rss.py +++ b/src/var/lib/tyto/program/rss.py @@ -1,11 +1,27 @@ #!/usr/bin/env python3 -# Name: Tyto - Littérateur -# Type: ATOM/RSS template -# Description: Create raw RSS template -# file: rss.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 +# +# 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 . + +#---------------------------------------------------------------------- +# XMPP: echolib (im@echolib.re) +# +# Description: Create feed RSS/Atom +# File: /var/lib/tyto/program/rss.py +#---------------------------------------------------------------------- #------------ # funny stats @@ -33,42 +49,48 @@ def create_feed(): '\n' + \ ' \n' + \ ' %s - %s - Flux RSS 2.0\n'%( - db.domain_title, db.domain_www_url - ) + \ - ' %s\n'%db.domain_www_url + \ - ' %s %s (%s)\n'%( - tyto.trans[19][tyto.n], db.domain_title, db.domain_about - ) + \ + dom.title, dom.www_url + ) + \ + ' %s\n'%dom.www_url + \ + ' RSS 2.0 - %s (%s)\n'%( + dom.title, dom.about + ) + \ ' \n' + \ - ' %s/%s\n'%(db.domain_www_url, db.domain_logo) + \ - ' logo %s\n'%db.domain_title + \ - ' %s\n'%db.domain_www_url + \ + ' %s/%s\n'%(dom.www_url, dom.logo) + \ + ' logo %s\n'%dom.title + \ + ' %s\n'%dom.www_url + \ ' \n' + \ - ' %s\n'%db.domain_lang + \ - ' %s\n'%db.domain_tags + \ + ' %s\n'%dom.lang_site + \ + ' %s\n'%dom.tags + \ ' %s\n'%tyto.nowdate() + \ - ' %s\n'%db.domain_license + \ - ' %s\n'%db.domain_mail + \ + ' %s\n'%dom.license + \ + ' %s\n'%dom.mail + \ ' %s'%tyto.Tyto # Sort by newer articles (created by last check) - db_articles = sorted(Path(db.articles_db).iterdir(), + db_articles = sorted(Path(dom.articles_db_d).iterdir(), key=os.path.getmtime, reverse=True ) + rss_item = False nbr_item = 0 + # Loop published articles. Get databases of articles for post_db in db_articles: - if not str(post_db).endswith('.conf'): continue + if not str(post_db).endswith('.config'): + continue # Load DB exec(open(post_db).read(),globals()) - if not hash_www or hash_chk != hash_www: continue + if not hash_www or hash_chk != hash_www: + continue rss_item = True nbr_item += 1 - if nbr_item > dom.rss_items: break + + if nbr_item > dom.rss_items: + break set_f = \ '%s\n'%set_f + \ @@ -81,7 +103,7 @@ def create_feed(): ' %s\n'%author + \ ' \n' + \ ' %s\n'%snpic + \ - ' %s %s\n'%(tyto.trans[20][tyto.n], title) + \ + ' %s\n'%(title) + \ ' %s\n'%http_www + \ ' \n' + \ ' %s\n'%tags + \ @@ -98,6 +120,5 @@ def create_feed(): ' \n' + \ '' - tyto.set_file(db.www_rss, 'New', set_f) - logs.out("33", db.www_rss, False) + tyto.set_file(dom.www_rss_f, 'New', set_f) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 87f8d57..2ce06b4 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -241,11 +241,12 @@ def edit_file(edit_file): logs.out("1", "/usr/bin/nano", True) -#=================# -# Create a file # -# Or append text # -# new: True/false # -#-----------------# +#=====================# +# Create a file # +# Or append text # +# new: True = create # +# False = Append # +#---------------------# def set_file(path, new, text): if new: opt = "w" else: opt = "a" @@ -254,6 +255,8 @@ def set_file(path, new, text): file = open(path, opt) file.write(text + '\n') file.close() + if opt == 'w': + logs.out("32", path, False) except: logs.out("4", path, True) diff --git a/src/var/lib/tyto/program/wip.py b/src/var/lib/tyto/program/wip.py index 2b8c201..5f3fa5d 100644 --- a/src/var/lib/tyto/program/wip.py +++ b/src/var/lib/tyto/program/wip.py @@ -178,7 +178,6 @@ def wip_article(target): os.makedirs('%s%s'%(dom.srv_wip, db.direc_src), exist_ok=True) logs.out("33", '%s%s'%(dom.srv_wip, db.direc_src), False) tyto.set_file(db.post_wip, 'New', html.main_page) - logs.out("32", db.post_wip, False) # Copy needed files (Also create sub-folders) tyto.files_to_srv('wip') diff --git a/src/var/lib/tyto/translations/logs_en.py b/src/var/lib/tyto/translations/logs_en.py index ae40f69..e315034 100644 --- a/src/var/lib/tyto/translations/logs_en.py +++ b/src/var/lib/tyto/translations/logs_en.py @@ -13,10 +13,13 @@ # Generic sidebar = 'Sidebar' navbar = 'Navbar' +meta_t = ' tag' +time_t = '