Some cleaning. wip_links Ok. New processes

This commit is contained in:
Cyrille L 2023-03-31 16:37:58 +02:00
parent d08b96cf37
commit e43f2eaaa4
13 changed files with 923 additions and 1038 deletions

View File

@ -5,8 +5,8 @@
#
# 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.
# 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
@ -39,33 +39,7 @@ import time, importlib, sys, os, re, datetime
from datetime import datetime
from time import gmtime, strftime
import args, dom, logs, status, db, form, tyto
# load locale translation
trans_dir = '/var/lib/tyto/translations'
sys.path.insert(0, trans_dir)
# Get default system language
# or set "en" (english) if no translation file
try:
lang_site = locale.getdefaultlocale()[0].split('_')[0]
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
except:
lang_site = 'en'
lang_sys = lang_site
# Set language site/form from configuration domain
# or set default english if not known
try:
dom.exists
lang_site = dom.lang_site
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
tr = importlib.import_module('site_%s'%lang_site, package=None)
except:
tr = importlib.import_module('site_%s'%lang_site, package=None)
import args, dom, logs, status, db, form, tyto, langs
post_err = False
@ -86,14 +60,10 @@ def manage(target):
and db.exists \
and not db.old_chk:
logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False)
ask = ''
try:
ask = input('%s%s '%(tr.check_a, tr.q))
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in form.answer_yes:
return
answer = form.asking('%s%s '%(
langs.site.check_a, langs.site.q
), True)
check_process(target)
# All
@ -416,7 +386,7 @@ def check_date(date):
date_check = time.mktime(time.strptime(date_check, fmt_check))
# Set franch format in post DB
if lang_site == 'fr':
if dom.lang_site == 'fr':
date = date.rsplit('-')
date = date[2] + '/' + date[1] + '/' + date[0]
@ -486,7 +456,7 @@ def check_3lines(tag, ln, line):
if not name:
logs.out("2", 'L=%s. "%s: %s" > %s'%(
ln, tag, tr.name, db.uri_file
ln, tag, langs.site.name, db.uri_file
), False)
post_err = True

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
# Tyto - Littérateur
#
# Copyright (C) 2023 Cyrille Louarn <echolib@dismail.de>
# 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.
# 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
@ -34,31 +34,13 @@
import os, sys, importlib
import logs, db, dom, tyto, form
import logs, db, dom, tyto, form, langs
# load locale translation
trans_dir = '/var/lib/tyto/translations'
sys.path.insert(0, trans_dir)
# Get default system language
# or set "en" (english) if no translation file
try:
lang_site = locale.getdefaultlocale()[0].split('_')[0]
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
except:
lang_site = 'en'
# Set language site/form from configuration domain
# or set default english if not known
try:
dom.exists
lang_site = dom.lang_site
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
tr = importlib.import_module('site_%s'%lang_site, package=None)
except:
tr = importlib.import_module('site_%s'%lang_site, package=None)
# Publish option can be
pub_opts = ('www', 'pub')
# Not a line if it starts with...(for sidebar, navbar)
nolines = ('#', '/')
#==========================#
# Load article DB #
@ -259,56 +241,190 @@ def create_html_infos_section(process):
)
#=================================================#
# Create metas.html from _configs/tyto.metas.html #
# Opiton 'pub' force create (when publish) #
#-------------------------------------------------#
def create_user_metas(option):
dom.valid()
if option == 'wip': target = dom.wip_metas_f
elif option in pub_opts: target = dom.www_metas_f
# Create wip metas.html file according to option
#-----------------------------------------------
if option == 'www' and tyto.exists(target):
form.asking('%s. %s%s '%(
langs.site.metas, langs.site.form_rep, langs.site.q
), True)
try: user_file = open(dom.metas_f, 'r').read()
except: logs.out("1", dom.metas_f, True)
user_metas = ''
tab = 4 * ' '
metas_used = ('<meta ', '<link ')
for line in user_file.rsplit('\n'):
if line.startswith(metas_used):
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("33", target, False)
#==================================#
# Create HTML navbar from config #
# If no index in src: STOP #
# For wip, create if no index.html #
# for publish all/navbar, STOP #
#----------------------------------#
def create_navbar(option):
dom.valid()
if not tyto.exists(dom.navbar_f):
logs.out("1", dom.navbar_f, True)
if option == 'wip': target = dom.wip_navbar_f
elif option in pub_opts: target = dom.www_navbar_f
# navbar has items
navbar_items = False
# Set first HTML line
menu_html = \
'%s<nav id="site_menu">\n'%(6 * ' ') + \
'%s<ul id="site_menu_items">'%(8 * ' ')
navbar_lines = open(db.navbar_load, 'r').read()
for line in navbar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue
# Get HTML title if defined (commented after)
if '#' in line:
direc = line.rsplit('#')[0].rstrip()
title = '%stitle="%s"\n'%(15 * ' ', line.rsplit('#')[1].lstrip())
else:
direc = line
title = ''
# Check if directory exists in articles/
dir_uri = os.path.join(dom.articles_d, direc)
if not os.path.isdir(dir_uri):
logs.out("24", '%s/'%dir_uri, False)
continue
# Check if an index.[ext] exists (src, wip, www)
no_wip_index = False
no_www_index = False
src_index = ''
wip_index = '%s%s/index.html'%(dom.srv_wip, direc)
www_index = '%s%s/index.html'%(dom.srv_www, direc)
# Source index article must exist
src_index = [ \
filename \
for filename in os.listdir(dir_uri) \
if filename.startswith("index.") \
and os.path.isfile \
]
if not src_index:
src_index = '%s%s/index.tyto'%(dom.articles_d, direc)
logs.out('26', '> %s'%(src_index), False)
continue
# index.html server files must exist (or 404 error)
if option == 'wip':
if not tyto.exists(wip_index):
logs.out('26', '> %s'%(wip_index), False)
no_wip_index = True
continue
elif option in pub_opts:
if not tyto.exists(www_index):
logs.out('26', '> %s'%(www_index), False)
no_www_index = True
continue
# Add link to HTML structure
navbar_items = True
menu_item = \
'\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
'%s<a class="site_menu_link"\n'%(12 * ' ') + \
'%s'%title + \
'%shref="/%s/">%s</a>\n'%(
15 * ' ', direc, direc
) + \
'%s</li>'%(10 * ' ')
menu_html = '%s%s'%(menu_html, menu_item)
# Nothing to do
if not navbar_items:
if not tyto.exists(target):
tyto.set_file(target, 'New', '')
logs.out("32", target, False)
return
logs.out('28', '%s'%langs.log.navbar, False)
return
# Create ending HTML file
else:
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
# Ask to replace only for www
if option == 'www':
form.asking('%s. %s(%s)%s '%(
langs.site.navbar, langs.site.form_rep,
option, langs.site.q
), True)
tyto.set_file(target, 'New', menu_html)
logs.out("32", target, False)
#============================================#
# Create HTML sidebar from file tyto.sidebar #
#--------------------------------------------#
def create_sidebar(option):
dom.valid()
try:
if not tyto.exists(dom.sidebar_f):
logs.out("1", dom.sidebar_f, True)
except:
logs.out("1", 'Sidebar ?', True)
if not tyto.exists(dom.sidebar_f):
logs.out("1", dom.sidebar_f, True)
try:
if int(dom.sidebar_items) > 16: db.sidebar_items = 6
except:
db.sidebar_items = 6
if int(dom.sidebar_items) > 16: db.sidebar_items = 6
if option == 'wip': target = dom.wip_sidebar_f
elif option in pub_opts: target = dom.www_sidebar_f
pub_opts = ('www', 'pub')
if option == 'wip': target = dom.wip_sidebar_f
elif option == 'www': target = dom.www_sidebar_f
elif option == 'pub': target = dom.www_sidebar_f
# If content in sidebar, go True
sidebar_new = False
sidebar_has = False
sidebar_items = False
# Set HTML sidebar
sidebar_list = ''
sidebar_html = '<aside>\n' + \
' <h1 id="sidebar_title">%s</h1>\n' + \
' <ul id="sidebar_list">\n' + \
'%s' + \
' </ul>\n' + \
'</aside>'
counter = 0
nolines = ('#', '/')
sidebar_html = \
'<aside>\n' + \
' <h1 id="sidebar_title">%s</h1>\n' + \
' <ul id="sidebar_list">\n' + \
'%s' + \
' </ul>\n' + \
'</aside>'
sidebar_title = dom.sidebar_title
sidebar_lines = open(dom.sidebar_f, 'r').read()
counter = 0
for line in sidebar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue
if not line or line.startswith(nolines):
continue
if line.startswith(':'):
sidebar_title = line.rsplit(':')[1].lstrip()
continue
# Get full article URI and check if exists
sidebar_has = True
f_uri = '%s%s'%(dom.articles_d, line)
if not tyto.exists(f_uri):
logs.out("24", f_uri, False)
@ -321,255 +437,82 @@ def create_sidebar(option):
logs.out('25', line, False)
continue
# Load article"s database
exec(open(db_uri).read(),globals())
# Check wip status and if wip article exists
# Check wip status and if article exists in server
if option == 'wip':
if not hash_wip == hash_chk:
logs.out("30", '%s "%s"'%(line, title), False)
if hash_wip != hash_chk:
logs.out("30", line, False)
continue
if not tyto.exists(post_wip):
logs.out("24", 'in wip: %s'%post_wip, False)
logs.out("24", post_wip, False)
continue
elif option in pub_opts:
if not hash_www == hash_chk:
logs.out("30", '%s "%s"'%(line, title), False)
if hash_www != hash_chk:
logs.out("30", line, False)
continue
if not tyto.exists(post_www):
logs.out("24", 'in www: %s'%post_www, False)
logs.out("24", post_www, False)
continue
# Valid article
sidebar_new = True
# Count: no more than max configured items
# Add item if not max
sidebar_items = True
counter += 1
if counter > dom.sidebar_items:
logs.out("31", '(%s): %s "%s"'%(
dom.sidebar_items, line, title),
False
)
continue
if counter > dom.sidebar_items: break
# Show item to add
logs.out("35", '"%s": %s'%(title, line), False)
logs.out("35", '"%s" > %s'%(title, line), False)
# Create HTML list for this article
link_title = '%s [%s]'%(about, author)
link_title = '%s [%s]'%(title, author)
sidebar_list = sidebar_list + \
' <li class="sidebar_item">\n' + \
' <a class="sidebar_item_link"\n' + \
' href="/%s"\n'%short_srv + \
' title="%s">\n'%link_title + \
' href="/%s">\n'%short_srv + \
' <h2 class="sidebar_item_title">%s</h2>\n'%title + \
' <p class="sidebar_item_about">%s [%s] - %s</p>\n'%(
date[0], author, about) + \
' <p class="sidebar_item_about"\n' + \
' title="%s">\n'%link_title + \
' %s [%s] - %s\n'%(date, author, about) + \
' </p>\n' + \
' </a>\n' + \
' </li>\n'
if not sidebar_new:
# Empty file
if not sidebar_has:
logs.out('29', '(sidebar): %s'%db.sidebar_load, False)
# Nothing to do
if not sidebar_items:
if not tyto.exists(target):
tyto.set_file(target, 'New', '')
logs.out("32", target, False)
return
else: # Some items, but no one is valid
logs.out('28', '(sidebar)', False)
return
# Create HTML complete sidebar
sidebar_temp = sidebar_html%(sidebar_title, sidebar_list)
# Indent HTML code
sidebar_content = ''
for line in sidebar_temp.rsplit('\n'):
sidebar_content = sidebar_content + '%s%s\n'%(4 * ' ', line)
# Create file if sidebar has content
if sidebar_new:
ask_html = ' ├ Replace %s ? '%target
res = ''
if not option == 'pub' and tyto.exists(target):
res = input(ask_html)
if not res in ['y', 'Y']:
logs.out("255", '', True)
tyto.set_file(target, True, sidebar_content)
logs.out("33", target, False)
#==================================#
# Create HTML navbar from config #
# If no index in src: STOP #
# For wip, create if no index.html #
# for publish all/navbar, STOP #
#----------------------------------#
def create_navbar(option):
domain.domain_needed()
# more confitions to pass
try:
db.navbar_load
if not tyto.exists(db.navbar_load):
logs.out("1", db.navbar_load, True)
except:
logs.out("1", 'Navbar load file', True)
# Set target from option
pub_opts = ('www', 'pub')
if option == 'wip': target = db.wip_navbar
elif option == 'www': target = db.www_navbar
elif option == 'pub': target = db.www_navbar
# If content and error
navbar_new = False
navbar_has = False
e_src_index = False
e_www_index = False # If error, do not create file in www server
# Set first HTML line
menu_html = '%s<nav id="site_menu">\n'%(6 * ' ') + \
'%s<ul id="site_menu_items">'%(8 * ' ')
# Not a line if it starts with...
nolines = ('#', '/')
navbar_lines = open(db.navbar_load, 'r').read()
for line in navbar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue
# A line is registred
navbar_has = True
# Get HTML title if defined (commented after)
if '#' in line:
direc = line.rsplit('#')[0].rstrip()
title = '%stitle="%s"\n'%(15 * ' ', line.rsplit('#')[1].lstrip())
else:
direc = line
title = ''
# Check if dir exists in articles/
dir_uri = os.path.join(db.domain_articles, direc)
if not os.path.isdir(dir_uri):
logs.out("24", '%s/'%dir_uri, False)
continue
# Check if an index.[ext] exists (src, wip, www)
src_index = ''
wip_index = '%s%s/index.html'%(db.srv_wip, direc)
www_index = '%s%s/index.html'%(db.srv_www, direc)
src_index = [ \
filename \
for filename in os.listdir(dir_uri) \
if filename.startswith("index.") \
and os.path.isfile \
]
if not src_index:
src_index = '%s%s/index.[ext]'%(db.domain_articles, direc)
e_src_index = True
logs.out('26', 'in src "%s/": %s'%(direc, src_index), False)
# Showing unused index.html server file
if option == 'wip':
if not tyto.exists(wip_index):
logs.out('26', 'in wip "%s/": %s'%(direc, wip_index), False)
elif option in pub_opts:
if not tyto.exists(www_index):
logs.out('26', 'in www "%s/": %s'%(direc, www_index), False)
e_www_index = True
continue
# Add link to HTML structure
navbar_new = True
menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
'%s<a class="site_menu_link"\n'%(12 * ' ') + \
'%s'%title + \
'%shref="/%s/">%s</a>\n'%(
15 * ' ', direc, direc
) + \
'%s</li>'%(10 * ' ')
menu_html = '%s%s'%(menu_html, menu_item)
# Stop if index error in src dir
if e_src_index or e_www_index:
if not option == 'pub':
logs.out("1", '(index article)', True)
logs.out('28', '%s'%langs.log.sidebar, False)
return
# Nothing to do
if not navbar_new:
if not navbar_has:
logs.out('29', '(navbar): %s'%db.navbar_load, False)
return
else:
logs.out('28', '(navbar)', False)
return
else:
# Create HTML complete sidebar
sidebar_temp = sidebar_html%(sidebar_title, sidebar_list)
# Indent HTML code
sidebar_content = ''
for line in sidebar_temp.rsplit('\n'):
sidebar_content = sidebar_content + '%s%s\n'%(4 * ' ', line)
# Ask to replace only for www
if option == 'www':
form.asking('%s. %s(%s)%s '%(
langs.site.sidebar, langs.site.form_rep,
option, langs.site.q
), True)
tyto.set_file(target, True, sidebar_content)
logs.out("32", target, False)
# Ask to replace (except from 'publish template')
if not option == 'pub' and tyto.exists(target):
ask_html = ' ├ Replace %s ? '%target
res = ''
try:
res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']:
logs.out("255", '', True)
# Close HTML tags
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
tyto.set_file(target, 'New', menu_html)
logs.out("33", target, False)
#========================================================#
# Create metas.html from _configs/tyto.metas.html #
# Manage options Edit, New, Force, Create #
# Create DB file with hash from _configs/tyto.metas.html #
# To manage new creation if changes #
#--------------------------------------------------------#
def create_user_metas(option):
dom.valid()
if option == 'wip': target = dom.wip_metas_f
elif option == 'www': target = dom.www_metas_f
elif option == 'pub': target = dom.www_metas_f
# Create wip metas.html file according to option
#-----------------------------------------------
ask_html = ' ├ Replace %s ? '%target
user_metas = ''
metas_used = ('<meta ', '<link ')
res = ''
if not option == 'pub' and tyto.exists(target):
try:
res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']:
logs.out("255", '', True)
user_file = open(db.metas_load, 'r').read()
for line in user_file.rsplit('\n'):
if line.startswith(metas_used):
if user_metas: user_metas = "%s\n %s"%(user_metas, line)
else: user_metas = ' %s'%line
tyto.set_file(target, True, user_metas)
logs.out("33", target, False)
#=========================================#
# Create generic footer from domain datas #
#-----------------------------------------#
#===================================================#
# Create footer.html from _configs/tyto.footer.html #
# Opiton 'pub' force create (when publish) #
#---------------------------------------------------#
def create_user_footer(option):
dom.valid()
@ -578,22 +521,20 @@ def create_user_footer(option):
elif option == 'pub': target = dom.www_footer_f
if not option == 'pub' and tyto.exists(target):
ask = ''
try:
ask = input('%s. %s%s '%(tr.footer, tr.form_rep, tr.q))
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in form.answer_yes:
logs.out("255", '', True)
form.asking('%s. %s%s '%(
langs.site.footer, langs.site.form_rep, langs.site.q
), True)
try: footer_f = open(dom.footer_f, 'r').read()
except: logs.out("1", dom.footer_f, True)
footer = ''
footer_f = open(dom.footer_f, 'r').read()
tab = 4 * ' '
for line in footer_f.rsplit('\n'):
if not line or line.startswith('#'): continue
if footer: footer = "%s\n %s"%(footer, line)
else: footer = ' %s'%line
if footer: footer = "%s\n%s%s"%(footer, tab, line)
else: footer = '%s%s'%(tab, line)
tyto.set_file(target, 'New', footer)
logs.out("32", target, False)

View File

@ -1,47 +0,0 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Set logs lang
# Description: Set logs language according to user choice
# file: lang.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 locale, sys, os
import dom
# Import translation directory
trans_dir = '/var/lib/tyto/translations'
sys.path.insert(0, trans_dir)
# Get default system language
# or set "en" (english) if no translation file
try:
lang_logs = locale.getdefaultlocale()[0].split('_')[0]
os.path.exists('%s/logs_%s.py'%(trans_dir, lang_logs))
except:
lang_logs = 'en'
# Set language logs from configuration domain
# or set default english if not known
try:
dom.exists
lang_logs = dom.lang_logs
os.path.exists('%s/logs_%s.py'%(trans_dir, lang_logs))
exec(open('%s/logs_%s.py'%(trans_dir, lang.logs)).read())
except:
exec(open('%s/logs_%s.py'%(trans_dir, lang_logs)).read())

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 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: Load translations file for log
# File: /var/lib/tyto/program/log.py
#----------------------------------------------------------------------
#------------
# funny stats
#------------
# lines:
# functions:
# comments:
#----------------------------------------------------------------------
#**********************************************************************
import locale, sys, os, importlib
import dom
# Import translation directory
trans_dir = '/var/lib/tyto/translations'
sys.path.insert(0, trans_dir)
# Get default system language
# or set "en" (english) if no translation file
try:
lang_sys = locale.getdefaultlocale()[0].split('_')[0]
os.path.exists('%s/logs_%s.py'%(trans_dir, lang_sys))
except:
lang_sys = 'en'
# Set language logs from configuration domain
# or set default english if not known
try:
dom.exists
lang_logs = dom.lang_logs
os.path.exists('%s/logs_%s.py'%(trans_dir, lang_logs))
log = importlib.import_module('logs_%s'%lang_logse, package=None)
except:
log = importlib.import_module('logs_%s'%lang_sys, package=None)
'''
exec(open('%s/logs_%s.py'%(trans_dir, lang.logs)).read())
except:
exec(open('%s/logs_%s.py'%(trans_dir, lang_sys)).read())
'''
# Set language site/form from configuration domain
# or set default english if not known
try:
dom.exists
lang_site = dom.lang_site
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
site = importlib.import_module('site_%s'%lang_site, package=None)
except:
site = importlib.import_module('site_%s'%lang_sys, package=None)

View File

@ -18,7 +18,7 @@
#**********************************************************************
import os, sys
import lang
import langs
# Set colors
CS = '\033[0;0m'
@ -31,50 +31,49 @@ CG = '\033[1;32m'
#--------------------------------#
def out(nbr, value, out):
logs = {
'1' : '%s%s%s > %s'%(CR, lang.unused_r, CS, value),
'2' : '%s%s%s > %s'%(CR, lang.data_inc, CS, value),
'3' : '%s%s%s %s'%(CR, lang.data_inv, CS, value),
'1' : '%s%s%s > %s'%(CR, langs.log.unused_r, CS, value),
'2' : '%s%s%s > %s'%(CR, langs.log.data_inc, CS, value),
'3' : '%s%s%s %s'%(CR, langs.log.data_inv, CS, value),
'4' : '%sUnable to create file%s: %s'%(CR, CS, value),
'5' : '%s%s%s > "%s"'%(CR, lang.no_arg, CS, value),
'6' : '%s%s%s > %s'%(CR, lang.sep_inv, CS, value),
'7' : '%s%s%s > %s'%(CR, lang.post_inv, CS, value),
'8' : '%s%s%s %s'%(CR, lang.mark_np, CS, value),
'5' : '%s%s%s > "%s"'%(CR, langs.log.no_arg, CS, value),
'6' : '%s%s%s > %s'%(CR, langs.log.sep_inv, CS, value),
'7' : '%s%s%s > %s'%(CR, langs.log.post_inv, CS, value),
'8' : '%s%s%s %s'%(CR, langs.log.mark_np, CS, value),
'9' : ' ╞ Article %shas changed%s. Check it first'%(CR, CS),
'10' : '%s%s%s'%(CR, lang.dom_no, CS),
'11' : '%s%s%s > %s'%(CR, lang.err_arg, CS, value),
'12' : '%s%s%s > %s'%(CR, lang.post_inc, CS, value),
'13' : '%s%s%s'%(CR, lang.no_fidi, CS),
'10' : '%s%s%s'%(CR, langs.log.dom_no, CS),
'11' : '%s%s%s > %s'%(CR, langs.log.err_arg, CS, value),
'12' : '%s%s%s > %s'%(CR, langs.log.post_inc, CS, value),
'13' : '%s%s%s'%(CR, langs.log.no_fidi, CS),
'14' : '%sMismatch%s program start'%(CR, CS),
'15' : '%s%s%s %s'%(CR, lang.anch_nu, CS, value),
'16' : '%s%s%s "%s = ?"'%(CR, lang.unused_c, CS, value),
'17' : '%s%s%s "%s ?"'%(CR, lang.unused_v, CS, value),
'18' : '%s%s%s > %s'%(CR, lang.unused_p, CS, value),
'15' : '%s%s%s %s'%(CR, langs.log.anch_nu, CS, value),
'16' : '%s%s%s "%s = ?"'%(CR, langs.log.unused_c, CS, value),
'17' : '%s%s%s "%s ?"'%(CR, langs.log.unused_v, CS, value),
'18' : '%s%s%s > %s'%(CR, langs.log.unused_p, CS, value),
'19' : ' ╞ Article %swip%s on: %s'%(CG, CS, value),
'20' : '%s%s%s %s'%(CG, lang.check_on, CS, value),
'21' : '%s%s%s > %s'%(CG, lang.post_val, CS, value),
'22' : '%s%s%s %s'%(CY, lang.symb_np, CS, value),
'23' : '%s%s%s > %s'%(CY, lang.db_inv, CS, value),
'24' : '%s%s%s > %s'%(CY, lang.unused_r, CS, value),
'25' : 'Article %snot yet checked%s: %s'%(CY, CS, value),
'26' : '%sNo index%s article %s'%(CY, CS, value),
'27' : '%s%s%s %s'%(CY, lang.snpic_d, CS, value),
'28' : '%s (%s)'%(lang.ntd, value),
'20' : '%s%s%s %s'%(CG, langs.log.check_on, CS, value),
'21' : '%s%s%s > %s'%(CG, langs.log.post_val, CS, value),
'22' : '%s%s%s %s'%(CY, langs.log.symb_np, CS, value),
'23' : '%s%s%s > %s'%(CY, langs.log.db_inv, CS, value),
'24' : '%s%s%s > %s'%(CY, langs.log.unused_r, CS, value),
'25' : '%s%s%s > %s'%(CY, langs.log.nycheck, CS, value),
'26' : '%s%s%s %s'%(CY, langs.log.nyfile, CS, value),
'27' : '%s%s%s %s'%(CY, langs.log.snpic_d, CS, value),
'28' : '%s (%s)'%(langs.log.ntd, value),
'29' : '%sEmpty configuration%s %s'%(CY, CS, value),
'30' : ' ╞ Article %snot yet wip%s: %s'%(CY, CS, value),
'31' : ' ╞ Not included. %sMax items reached%s %s'%(CY, CS, value),
'32' : ' ╞══ %s%s%s > %s'%(CG, lang.file_c, CS, value),
'33' : ' ╞══ %s%s%s > %s'%(CG, lang.dir_c, CS, value),
'34' : ' ╞══ %s%s%s > %s'%(CG, lang.file_n, CS, value),
'35' : '%sAdd item%s %s'%(CG, CS, value),
'36' : '%s %s'%(lang.file_e, value),
'37' : '%s %s'%(lang.dir_e, value),
'40' : '%s%s%s > "%s"'%(CY, lang.dom_ina, CS, value),
'41' : '%s%s%s > "%s"'%(CR, lang.dom_inc, CS, value),
'42' : '%s%s%s > "%s"'%(CG, lang.dom_act, CS, value),
'43' : '%s%s%s'%(CY, lang.dom_no, CS),
'44' : '%s%s%s "tyto check %s"'%(CY, lang.check_m, CS, value),
'51' : '%s%s%s > %s'%(CY, lang.data_inc, CS, value),
'255' : '%s'%lang.laterout
'30' : '%s%s%s > %s'%(CY, langs.log.nywip, CS, value),
'32' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_c, CS, value),
'33' : ' ╞══ %s%s%s > %s'%(CG, langs.log.dir_c, CS, value),
'34' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_n, CS, value),
'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),
'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),
'43' : '%s%s%s'%(CY, langs.log.dom_no, CS),
'44' : '%s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value),
'51' : '%s%s%s > %s'%(CY, langs.log.data_inc, CS, value),
'255' : '%s'%langs.log.laterout
}
msg = logs[nbr]

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Tyto - Littérateur
#
# Copyright (C) 2023 Cyrille Louarn <echolib@dismail.de>
# 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
@ -34,35 +34,8 @@
#**********************************************************************
import os, sys, locale, importlib
import args, lang, logs, dom, db, form, tyto, check, stats
# load locale translation
trans_dir = '/var/lib/tyto/translations'
sys.path.insert(0, trans_dir)
# System language
try: lang_sys = locale.getdefaultlocale()[0].split('_')[0]
except: lang_sys = 'en'
# Get default system language
# or set "en" (english) if no translation file
try:
lang_site = lang_sys
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
except:
lang_site = 'en'
# Set language site/form from configuration domain
# or set default english if not known
try:
dom.exists
lang_site = dom.lang_site
os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
tr = importlib.import_module('site_%s'%lang_site, package=None)
except:
tr = importlib.import_module('site_%s'%lang_site, package=None)
import os, sys, importlib
import args, logs, dom, db, form, tyto, check, stats, langs
#========================#
# Read lines from a file #
@ -94,10 +67,8 @@ def read_lines(f, alone):
#======================#
# From command line: #
# - 'showdb' / 'show' #
# - 'editdb' / 'edit' #
# Show or edit files #
# final html, db, load #
# Show or edit file #
# final html, db, src #
#----------------------#
def manage(target):
if not dom.exists: logs.out("10", '', True)
@ -127,10 +98,6 @@ def manage(target):
if args.action == "show-about":
target = 'post'
# When edit article, get src hash
if args.action == "edit":
curr_hash = tyto.get_filesum(db.uri_file, True)
# Convert command action to do[]
# as edit* &nd show* [action] have same target file
@ -153,71 +120,71 @@ def manage(target):
# Set target file from "new" [action]
do = \
{
'src' : {
'domain' : dom.config,
'footer' : dom.footer_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_src
},
'db' : {
'domain' : dom.config,
'footer' : dom.footer_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_db
},
'about' : {
'domain' : dom.config,
'footer' : dom.footer_about_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_db
},
'wip' : {
'domain' : dom.config,
'footer' : dom.wip_footer_f,
'metas' : dom.wip_metas_f,
'navbar' : dom.wip_navbar_f,
'sidebar' : dom.wip_sidebar_f,
'post' : post_wip
},
'www' : {
'domain' : dom.config,
'footer' : dom.www_footer_f,
'metas' : dom.www_metas_f,
'navbar' : dom.www_navbar_f,
'sidebar' : dom.www_sidebar_f,
'post' : post_www
},
'src' : {
'domain' : dom.config,
'footer' : dom.footer_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_src
},
'db' : {
'domain' : dom.config,
'footer' : dom.footer_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_db
},
'about' : {
'domain' : dom.config,
'footer' : dom.footer_about_f,
'metas' : dom.metas_f,
'navbar' : dom.navbar_f,
'sidebar' : dom.sidebar_f,
'post' : post_db
},
'wip' : {
'domain' : dom.config,
'footer' : dom.wip_footer_f,
'metas' : dom.wip_metas_f,
'navbar' : dom.wip_navbar_f,
'sidebar' : dom.wip_sidebar_f,
'post' : post_wip
},
'www' : {
'domain' : dom.config,
'footer' : dom.www_footer_f,
'metas' : dom.www_metas_f,
'navbar' : dom.www_navbar_f,
'sidebar' : dom.www_sidebar_f,
'post' : post_www
},
}
# Read or edit file, according to legacy args.action
try:
file = do[action][target]
if args.action in actions_read:
read_lines(file, True)
elif args.action in actions_edit:
curr_hash = tyto.get_filesum(file, True)
tyto.edit_file(file)
except:
logs.out("28", '%s + %s'%(action, target), True)
# If edit article and hash changed, ask to check
if args.action == "edit" and post_src:
new_hash = tyto.get_filesum(post_src, True)
new_hash = tyto.get_filesum(file, True)
if curr_hash != new_hash:
ask = ''
try: ask = input('%s%s '%(tr.post_chg, tr.q))
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in form.answer_yes:
logs.out("255", '', True)
if file == post_src:
form.asking('%s%s '%(
langs.site.post_chg, langs.site.q
), True)
# Reload post DB (if edited article, and check it if ask "y")
importlib.reload(db)

View File

@ -516,7 +516,8 @@ def files_to_srv(server):
d_in = uri.split("/")[-1]
d_in = uri.rsplit(d_in)[0]
# Destination file to server
# Destination file and directories according to server
# (remove last / from domain directory value)
f_src = '%s%s'%(dom.articles_d[:-1], uri)
if server == 'wip':
f_dst = '%s%s'%(dom.srv_wip[:-1], uri)
@ -525,19 +526,22 @@ def files_to_srv(server):
f_dst = '%s%s'%(dom.srv_www[:-1], uri)
d_dst = '%s%s'%(dom.srv_www[:-1], d_in)
# Create folder and subfolders
# Create sub-directories in server
try:
os.makedirs(d_dst, exist_ok=True)
logs.out("33", d_dst, False)
except:
logs.out('4', d_dst, True)
# COpy files to server
try:
shutil.copy2(f_src, f_dst)
logs.out("32", f_dst, False)
except:
logs.out('4', f_dst, True)
# Copy source post file in server
# if article_code is True in domain DB
if dom.article_code:
if server == "wip": base_srv = dom.srv_wip
elif server == "www": base_srv = dom.srv_www

View File

@ -1,13 +1,13 @@
#!/usr/bin/env python3
# Tyto - Littérateur
#
# Copyright (C) 2023 Cyrille Louarn <echolib@dismail.de>
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
# Copyright (C) 2023 Adrien Bourmault <neox@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.
# 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
@ -39,7 +39,7 @@
import os, re, sys, locale, shutil, importlib, time
from pathlib import Path
import args, logs, lang, dom, db, tyto, html, form, stats
import args, logs, dom, db, tyto, html, form, stats
# load locale translation
trans_dir = '/var/lib/tyto/translations'
@ -112,15 +112,7 @@ def manage_wip(target):
# wip is up-to-date: ask to wip again
else:
logs.out("19", db.date_wip, False)
try:
res = input(' ├ [%s] %s%s '%(db.title, tr.wip_new, tr.q))
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in form.answer_yes:
logs.out("255", '', True)
form.asking(' ├ [%s] %s%s '%(db.title, tr.wip_new, tr.q), True)
wip_article(db.uri_file)
@ -308,34 +300,55 @@ def wip_words_tags():
)
#=======================#
# Convert links from DB #
# - link_%i #
# - file_%i #
#-----------------------#
def wip_links():
#========================#
# Convert links set inDB #
# - file_%i #
# - link_%i #
# from marker to HTML #
#------------------------#
def wip_link_convert(marker, html):
global post_bottom
post_bottom = post_bottom.replace(marker, html)
# Doing files, first, becase of similar marker
def wip_links():
if db.uniq_files == 0 and db.uniq_links == 0: return
link_tb = 'target="_blank"'
link_ts = 'target="_self"'
link_html = '<a class="%s" href="%s" title="%s" %s>%s</a>'
# ! Doing link files, first, becase of similar marker
#----------------------------------------------------
if db.uniq_files > 0:
for i in range(1, db.uniq_files + 1):
file = 'db.file_%s'%i
post_bottom = post_bottom.replace(eval(file)[0]+'+',
eval(file)[1]%('_blank')
)
post_bottom = post_bottom.replace(eval(file)[0],
eval(file)[1]%('_self')
)
link = 'db.file_%s'%i
link_css = "link_file"
link_name = eval(link)[0][2:]
link_anc = eval(link)[1]
link_title = eval(link)[2]
link_set = link_html%(
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)
# Convert simple links
#---------------------
if db.uniq_links > 0:
for i in range(1, db.uniq_links + 1):
link = 'db.link_%s'%i
post_bottom = post_bottom.replace(eval(link)[0]+'+',
eval(link)[1]%('_blank')
)
post_bottom = post_bottom.replace(eval(link)[0],
eval(link)[1]%('_self')
)
link = 'db.link_%s'%i
link_css = "link"
link_name = eval(link)[0][1:]
link_anc = eval(link)[1]
link_title = eval(link)[2]
link_set = link_html%(
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)
#===============#
@ -370,8 +383,8 @@ def wip_images():
if db.uniq_images == 0: return
global post_bottom
image_link = '<a class="%s" href="%s" title="%s">%s</a>'
image_show = '<img class="%s" src="%s" alt="%s"%s />'
image_link = '<a class="%s" href="%s">%s</a>'
image_show = '<img class="%s" src="%s" alt="%s" title="%s"%s />'
# Check each line
for ln, line in enumerate(post_bottom.rsplit('\n')):
@ -419,13 +432,15 @@ def wip_images():
image_target = eval(image)[1]
image_target = db.sub_uri + image_target[1:]
image_src = image_show%(
set_css, image_target, eval(image)[2], style
set_css, image_target,
eval(image)[2], eval(image)[2],
style
)
# Set link for image
if target:
image_tgt = image_link%(
set_css, image_target, eval(image)[2], '%s'
set_css, image_target, '%s'
)
else:
image_tgt = '%s'

View File

@ -11,6 +11,10 @@
#**********************************************************************
# Generic
sidebar = 'Sidebar'
navbar = 'Navbar'
metas = 'Metas Tags'
footer = 'Footer'
line = "Ligne"
ntd = "Nothing to do"
@ -44,5 +48,9 @@ mark_np = "Not paired marks"
symb_np = "Not paired symbols"
snpic_d = "Using default snpic. Not found"
anch_nu = "Anchor not uniq"
nyfile = "file not yet created"
nycheck = "Article not yet checked"
nywip = "Article not yet wip"
add = "Add:"
laterout = "Maybe later..."

View File

@ -11,7 +11,12 @@
#**********************************************************************
# Generique
linecol = "Line"
sidebar = 'Barre Latérale'
navbar = 'Barre de navigation'
metas = 'Balises Metas'
footer = "Pied de Page"
line = "Line"
ntd = "Rien à faire"
unused_r = "Ressource manquante"
@ -44,5 +49,10 @@ mark_np = "Marqueurs non jumelés"
symb_np = "Symboles non jumelés"
snpic_d = "snpic utilisé par défaut. Manquant"
anch_nu = "Ancre non unique"
nyfile = "Fichier pas encore créé"
nycheck = "Article pas encore 'check'"
nywip = "Article pas encore 'wip'"
add = "Ajout:"
laterout = "Pour plus tard..."

View File

@ -23,7 +23,7 @@ This is a python file, so... DO NOT REMOVE:
# Generic
sidebar = 'Sidebar'
navbar = 'Navbar'
metas = 'HTML Metas Tags'
metas = 'Metas Tags'
footer = 'Footer'
title = 'Title'
File = 'File'
@ -178,7 +178,7 @@ sidebar_doc = \
'# Order in sidebar position\n' + \
'# Max articles = %d\n' + \
'# Option Tp set sidebar title:\n' + \
' ": Sidebar Title"\n' + \
'# ": Sidebar Title"\n' + \
'\n# %s\n'%(20 * "-") + \
'# Examples :\n' + \
'# : My new articles list'

View File

@ -23,7 +23,7 @@ Ceci est un fichier python, donc... NE PAS ENLEVER :
# Generic
sidebar = 'Barre Latérale'
navbar = 'Barre de navigation'
metas = 'Balises Metas HTML'
metas = 'Balises Metas'
footer = "Pied de Page"
title = 'Titre'
File = 'Fichier'
@ -179,7 +179,7 @@ sidebar_doc = \
'# L\'ordre définit la position\n' + \
'# Articles max = %d\n' + \
'# Option Pour définir un titre à la barre latérale:\n' + \
' ": Titre de la sidebar"\n' + \
'# ": Titre de la sidebar"\n' + \
'\n# %s\n'%(20 * "-") + \
'# Exemples :\n' + \
'# : Ma liste des nouveaux articles\n' + \