Some cleaning. wip_links Ok. New processes
This commit is contained in:
parent
d08b96cf37
commit
e43f2eaaa4
|
@ -5,8 +5,8 @@
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License
|
# 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
|
# as published by the Free Software Foundation, either version 3 of the
|
||||||
# of the License, or (at your option) any later version.
|
# License, or of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# 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 datetime import datetime
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
|
|
||||||
import args, dom, logs, status, db, form, tyto
|
import args, dom, logs, status, db, form, tyto, 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'
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
post_err = False
|
post_err = False
|
||||||
|
|
||||||
|
@ -86,14 +60,10 @@ def manage(target):
|
||||||
and db.exists \
|
and db.exists \
|
||||||
and not db.old_chk:
|
and not db.old_chk:
|
||||||
logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False)
|
logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False)
|
||||||
ask = ''
|
answer = form.asking(' ├ %s%s '%(
|
||||||
try:
|
langs.site.check_a, langs.site.q
|
||||||
ask = input(' ├ %s%s '%(tr.check_a, tr.q))
|
), True)
|
||||||
except KeyboardInterrupt:
|
|
||||||
print('')
|
|
||||||
logs.out("255", '', True)
|
|
||||||
if not ask in form.answer_yes:
|
|
||||||
return
|
|
||||||
check_process(target)
|
check_process(target)
|
||||||
|
|
||||||
# All
|
# All
|
||||||
|
@ -416,7 +386,7 @@ def check_date(date):
|
||||||
date_check = time.mktime(time.strptime(date_check, fmt_check))
|
date_check = time.mktime(time.strptime(date_check, fmt_check))
|
||||||
|
|
||||||
# Set franch format in post DB
|
# Set franch format in post DB
|
||||||
if lang_site == 'fr':
|
if dom.lang_site == 'fr':
|
||||||
date = date.rsplit('-')
|
date = date.rsplit('-')
|
||||||
date = date[2] + '/' + date[1] + '/' + date[0]
|
date = date[2] + '/' + date[1] + '/' + date[0]
|
||||||
|
|
||||||
|
@ -486,7 +456,7 @@ def check_3lines(tag, ln, line):
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
logs.out("2", 'L=%s. "%s: %s" > %s'%(
|
logs.out("2", 'L=%s. "%s: %s" > %s'%(
|
||||||
ln, tag, tr.name, db.uri_file
|
ln, tag, langs.site.name, db.uri_file
|
||||||
), False)
|
), False)
|
||||||
post_err = True
|
post_err = True
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,11 @@
|
||||||
# Tyto - Littérateur
|
# 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
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License
|
# 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
|
# as published by the Free Software Foundation, either version 3 of the
|
||||||
# of the License, or (at your option) any later version.
|
# License, or of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ -34,31 +34,13 @@
|
||||||
|
|
||||||
import os, sys, importlib
|
import os, sys, importlib
|
||||||
|
|
||||||
import logs, db, dom, tyto, form
|
import logs, db, dom, tyto, form, langs
|
||||||
|
|
||||||
# load locale translation
|
# Publish option can be
|
||||||
trans_dir = '/var/lib/tyto/translations'
|
pub_opts = ('www', 'pub')
|
||||||
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)
|
|
||||||
|
|
||||||
|
# Not a line if it starts with...(for sidebar, navbar)
|
||||||
|
nolines = ('#', '/')
|
||||||
|
|
||||||
#==========================#
|
#==========================#
|
||||||
# Load article DB #
|
# 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 #
|
# Create HTML sidebar from file tyto.sidebar #
|
||||||
#--------------------------------------------#
|
#--------------------------------------------#
|
||||||
def create_sidebar(option):
|
def create_sidebar(option):
|
||||||
dom.valid()
|
dom.valid()
|
||||||
|
|
||||||
try:
|
|
||||||
if not tyto.exists(dom.sidebar_f):
|
if not tyto.exists(dom.sidebar_f):
|
||||||
logs.out("1", dom.sidebar_f, True)
|
logs.out("1", dom.sidebar_f, True)
|
||||||
except:
|
|
||||||
logs.out("1", 'Sidebar ?', True)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if int(dom.sidebar_items) > 16: db.sidebar_items = 6
|
if int(dom.sidebar_items) > 16: db.sidebar_items = 6
|
||||||
except:
|
|
||||||
db.sidebar_items = 6
|
|
||||||
|
|
||||||
|
|
||||||
pub_opts = ('www', 'pub')
|
|
||||||
if option == 'wip': target = dom.wip_sidebar_f
|
if option == 'wip': target = dom.wip_sidebar_f
|
||||||
elif option == 'www': target = dom.www_sidebar_f
|
elif option in pub_opts: target = dom.www_sidebar_f
|
||||||
elif option == 'pub': target = dom.www_sidebar_f
|
|
||||||
|
|
||||||
# If content in sidebar, go True
|
sidebar_items = False
|
||||||
sidebar_new = False
|
|
||||||
sidebar_has = False
|
|
||||||
|
|
||||||
# Set HTML sidebar
|
# Set HTML sidebar
|
||||||
sidebar_list = ''
|
sidebar_list = ''
|
||||||
sidebar_html = '<aside>\n' + \
|
sidebar_html = \
|
||||||
|
'<aside>\n' + \
|
||||||
' <h1 id="sidebar_title">%s</h1>\n' + \
|
' <h1 id="sidebar_title">%s</h1>\n' + \
|
||||||
' <ul id="sidebar_list">\n' + \
|
' <ul id="sidebar_list">\n' + \
|
||||||
'%s' + \
|
'%s' + \
|
||||||
' </ul>\n' + \
|
' </ul>\n' + \
|
||||||
'</aside>'
|
'</aside>'
|
||||||
|
|
||||||
counter = 0
|
|
||||||
nolines = ('#', '/')
|
|
||||||
|
|
||||||
sidebar_title = dom.sidebar_title
|
sidebar_title = dom.sidebar_title
|
||||||
sidebar_lines = open(dom.sidebar_f, 'r').read()
|
sidebar_lines = open(dom.sidebar_f, 'r').read()
|
||||||
|
|
||||||
|
counter = 0
|
||||||
for line in sidebar_lines.rsplit('\n'):
|
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(':'):
|
if line.startswith(':'):
|
||||||
sidebar_title = line.rsplit(':')[1].lstrip()
|
sidebar_title = line.rsplit(':')[1].lstrip()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get full article URI and check if exists
|
|
||||||
sidebar_has = True
|
|
||||||
f_uri = '%s%s'%(dom.articles_d, line)
|
f_uri = '%s%s'%(dom.articles_d, line)
|
||||||
if not tyto.exists(f_uri):
|
if not tyto.exists(f_uri):
|
||||||
logs.out("24", f_uri, False)
|
logs.out("24", f_uri, False)
|
||||||
|
@ -321,62 +437,59 @@ def create_sidebar(option):
|
||||||
logs.out('25', line, False)
|
logs.out('25', line, False)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# Load article"s database
|
# Load article"s database
|
||||||
exec(open(db_uri).read(),globals())
|
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 option == 'wip':
|
||||||
if not hash_wip == hash_chk:
|
if hash_wip != hash_chk:
|
||||||
logs.out("30", '%s "%s"'%(line, title), False)
|
logs.out("30", line, False)
|
||||||
continue
|
continue
|
||||||
if not tyto.exists(post_wip):
|
if not tyto.exists(post_wip):
|
||||||
logs.out("24", 'in wip: %s'%post_wip, False)
|
logs.out("24", post_wip, False)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif option in pub_opts:
|
elif option in pub_opts:
|
||||||
if not hash_www == hash_chk:
|
if hash_www != hash_chk:
|
||||||
logs.out("30", '%s "%s"'%(line, title), False)
|
logs.out("30", line, False)
|
||||||
continue
|
continue
|
||||||
if not tyto.exists(post_www):
|
if not tyto.exists(post_www):
|
||||||
logs.out("24", 'in www: %s'%post_www, False)
|
logs.out("24", post_www, False)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Valid article
|
# Add item if not max
|
||||||
sidebar_new = True
|
sidebar_items = True
|
||||||
|
|
||||||
# Count: no more than max configured items
|
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter > dom.sidebar_items:
|
if counter > dom.sidebar_items: break
|
||||||
logs.out("31", '(%s): %s "%s"'%(
|
|
||||||
dom.sidebar_items, line, title),
|
|
||||||
False
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Show item to add
|
# 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
|
# Create HTML list for this article
|
||||||
link_title = '%s [%s]'%(about, author)
|
link_title = '%s [%s]'%(title, author)
|
||||||
sidebar_list = sidebar_list + \
|
sidebar_list = sidebar_list + \
|
||||||
' <li class="sidebar_item">\n' + \
|
' <li class="sidebar_item">\n' + \
|
||||||
' <a class="sidebar_item_link"\n' + \
|
' <a class="sidebar_item_link"\n' + \
|
||||||
' href="/%s"\n'%short_srv + \
|
' href="/%s">\n'%short_srv + \
|
||||||
' title="%s">\n'%link_title + \
|
|
||||||
' <h2 class="sidebar_item_title">%s</h2>\n'%title + \
|
' <h2 class="sidebar_item_title">%s</h2>\n'%title + \
|
||||||
' <p class="sidebar_item_about">%s [%s] - %s</p>\n'%(
|
' <p class="sidebar_item_about"\n' + \
|
||||||
date[0], author, about) + \
|
' title="%s">\n'%link_title + \
|
||||||
|
' %s [%s] - %s\n'%(date, author, about) + \
|
||||||
|
' </p>\n' + \
|
||||||
' </a>\n' + \
|
' </a>\n' + \
|
||||||
' </li>\n'
|
' </li>\n'
|
||||||
|
|
||||||
if not sidebar_new:
|
# Nothing to do
|
||||||
# Empty file
|
if not sidebar_items:
|
||||||
if not sidebar_has:
|
if not tyto.exists(target):
|
||||||
logs.out('29', '(sidebar): %s'%db.sidebar_load, False)
|
tyto.set_file(target, 'New', '')
|
||||||
|
logs.out("32", target, False)
|
||||||
return
|
return
|
||||||
else: # Some items, but no one is valid
|
logs.out('28', '%s'%langs.log.sidebar, False)
|
||||||
logs.out('28', '(sidebar)', False)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
# Create HTML complete sidebar
|
# Create HTML complete sidebar
|
||||||
sidebar_temp = sidebar_html%(sidebar_title, sidebar_list)
|
sidebar_temp = sidebar_html%(sidebar_title, sidebar_list)
|
||||||
|
|
||||||
|
@ -385,191 +498,21 @@ def create_sidebar(option):
|
||||||
for line in sidebar_temp.rsplit('\n'):
|
for line in sidebar_temp.rsplit('\n'):
|
||||||
sidebar_content = sidebar_content + '%s%s\n'%(4 * ' ', line)
|
sidebar_content = sidebar_content + '%s%s\n'%(4 * ' ', line)
|
||||||
|
|
||||||
# Create file if sidebar has content
|
# Ask to replace only for www
|
||||||
if sidebar_new:
|
if option == 'www':
|
||||||
ask_html = ' ├ Replace %s ? '%target
|
form.asking(' ├ %s. %s(%s)%s '%(
|
||||||
res = ''
|
langs.site.sidebar, langs.site.form_rep,
|
||||||
|
option, langs.site.q
|
||||||
if not option == 'pub' and tyto.exists(target):
|
), True)
|
||||||
res = input(ask_html)
|
|
||||||
if not res in ['y', 'Y']:
|
|
||||||
logs.out("255", '', True)
|
|
||||||
|
|
||||||
tyto.set_file(target, True, sidebar_content)
|
tyto.set_file(target, True, sidebar_content)
|
||||||
logs.out("33", target, False)
|
logs.out("32", target, False)
|
||||||
|
|
||||||
|
|
||||||
#==================================#
|
#===================================================#
|
||||||
# Create HTML navbar from config #
|
# Create footer.html from _configs/tyto.footer.html #
|
||||||
# If no index in src: STOP #
|
# Opiton 'pub' force create (when publish) #
|
||||||
# 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)
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# 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 #
|
|
||||||
#-----------------------------------------#
|
|
||||||
def create_user_footer(option):
|
def create_user_footer(option):
|
||||||
dom.valid()
|
dom.valid()
|
||||||
|
|
||||||
|
@ -578,22 +521,20 @@ def create_user_footer(option):
|
||||||
elif option == 'pub': target = dom.www_footer_f
|
elif option == 'pub': target = dom.www_footer_f
|
||||||
|
|
||||||
if not option == 'pub' and tyto.exists(target):
|
if not option == 'pub' and tyto.exists(target):
|
||||||
ask = ''
|
form.asking(' ├ %s. %s%s '%(
|
||||||
try:
|
langs.site.footer, langs.site.form_rep, langs.site.q
|
||||||
ask = input(' ├ %s. %s%s '%(tr.footer, tr.form_rep, tr.q))
|
), True)
|
||||||
except KeyboardInterrupt:
|
|
||||||
print('')
|
try: footer_f = open(dom.footer_f, 'r').read()
|
||||||
logs.out("255", '', True)
|
except: logs.out("1", dom.footer_f, True)
|
||||||
if not ask in form.answer_yes:
|
|
||||||
logs.out("255", '', True)
|
|
||||||
|
|
||||||
footer = ''
|
footer = ''
|
||||||
footer_f = open(dom.footer_f, 'r').read()
|
tab = 4 * ' '
|
||||||
for line in footer_f.rsplit('\n'):
|
for line in footer_f.rsplit('\n'):
|
||||||
if not line or line.startswith('#'): continue
|
if not line or line.startswith('#'): continue
|
||||||
|
|
||||||
if footer: footer = "%s\n %s"%(footer, line)
|
if footer: footer = "%s\n%s%s"%(footer, tab, line)
|
||||||
else: footer = ' %s'%line
|
else: footer = '%s%s'%(tab, line)
|
||||||
|
|
||||||
tyto.set_file(target, 'New', footer)
|
tyto.set_file(target, 'New', footer)
|
||||||
logs.out("32", target, False)
|
logs.out("32", target, False)
|
||||||
|
|
|
@ -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())
|
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
@ -18,7 +18,7 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
import lang
|
import langs
|
||||||
|
|
||||||
# Set colors
|
# Set colors
|
||||||
CS = '\033[0;0m'
|
CS = '\033[0;0m'
|
||||||
|
@ -31,50 +31,49 @@ CG = '\033[1;32m'
|
||||||
#--------------------------------#
|
#--------------------------------#
|
||||||
def out(nbr, value, out):
|
def out(nbr, value, out):
|
||||||
logs = {
|
logs = {
|
||||||
'1' : ' ╞ %s%s%s > %s'%(CR, lang.unused_r, CS, value),
|
'1' : ' ╞ %s%s%s > %s'%(CR, langs.log.unused_r, CS, value),
|
||||||
'2' : ' ╞ %s%s%s > %s'%(CR, lang.data_inc, CS, value),
|
'2' : ' ╞ %s%s%s > %s'%(CR, langs.log.data_inc, CS, value),
|
||||||
'3' : ' ╞ %s%s%s %s'%(CR, lang.data_inv, CS, value),
|
'3' : ' ╞ %s%s%s %s'%(CR, langs.log.data_inv, CS, value),
|
||||||
'4' : ' ╘ %sUnable to create file%s: %s'%(CR, CS, value),
|
'4' : ' ╘ %sUnable to create file%s: %s'%(CR, CS, value),
|
||||||
'5' : ' ╘ %s%s%s > "%s"'%(CR, lang.no_arg, CS, value),
|
'5' : ' ╘ %s%s%s > "%s"'%(CR, langs.log.no_arg, CS, value),
|
||||||
'6' : ' ╞ %s%s%s > %s'%(CR, lang.sep_inv, CS, value),
|
'6' : ' ╞ %s%s%s > %s'%(CR, langs.log.sep_inv, CS, value),
|
||||||
'7' : ' ╘ %s%s%s > %s'%(CR, lang.post_inv, CS, value),
|
'7' : ' ╘ %s%s%s > %s'%(CR, langs.log.post_inv, CS, value),
|
||||||
'8' : ' ╞ %s%s%s %s'%(CR, lang.mark_np, CS, value),
|
'8' : ' ╞ %s%s%s %s'%(CR, langs.log.mark_np, CS, value),
|
||||||
'9' : ' ╞ Article %shas changed%s. Check it first'%(CR, CS),
|
'9' : ' ╞ Article %shas changed%s. Check it first'%(CR, CS),
|
||||||
'10' : ' ╘ %s%s%s'%(CR, lang.dom_no, CS),
|
'10' : ' ╘ %s%s%s'%(CR, langs.log.dom_no, CS),
|
||||||
'11' : ' ╘ %s%s%s > %s'%(CR, lang.err_arg, CS, value),
|
'11' : ' ╘ %s%s%s > %s'%(CR, langs.log.err_arg, CS, value),
|
||||||
'12' : ' ╞ %s%s%s > %s'%(CR, lang.post_inc, CS, value),
|
'12' : ' ╞ %s%s%s > %s'%(CR, langs.log.post_inc, CS, value),
|
||||||
'13' : ' ╞ %s%s%s'%(CR, lang.no_fidi, CS),
|
'13' : ' ╞ %s%s%s'%(CR, langs.log.no_fidi, CS),
|
||||||
'14' : ' ╞ %sMismatch%s program start'%(CR, CS),
|
'14' : ' ╞ %sMismatch%s program start'%(CR, CS),
|
||||||
'15' : ' ╞ %s%s%s %s'%(CR, lang.anch_nu, CS, value),
|
'15' : ' ╞ %s%s%s %s'%(CR, langs.log.anch_nu, CS, value),
|
||||||
'16' : ' ╞ %s%s%s "%s = ?"'%(CR, lang.unused_c, CS, value),
|
'16' : ' ╞ %s%s%s "%s = ?"'%(CR, langs.log.unused_c, CS, value),
|
||||||
'17' : ' ╞ %s%s%s "%s ?"'%(CR, lang.unused_v, CS, value),
|
'17' : ' ╞ %s%s%s "%s ?"'%(CR, langs.log.unused_v, CS, value),
|
||||||
'18' : ' ╘ %s%s%s > %s'%(CR, lang.unused_p, CS, value),
|
'18' : ' ╘ %s%s%s > %s'%(CR, langs.log.unused_p, CS, value),
|
||||||
'19' : ' ╞ Article %swip%s on: %s'%(CG, CS, value),
|
'19' : ' ╞ Article %swip%s on: %s'%(CG, CS, value),
|
||||||
'20' : ' ╞ %s%s%s %s'%(CG, lang.check_on, CS, value),
|
'20' : ' ╞ %s%s%s %s'%(CG, langs.log.check_on, CS, value),
|
||||||
'21' : ' ╘ %s%s%s > %s'%(CG, lang.post_val, CS, value),
|
'21' : ' ╘ %s%s%s > %s'%(CG, langs.log.post_val, CS, value),
|
||||||
'22' : ' ╞ %s%s%s %s'%(CY, lang.symb_np, CS, value),
|
'22' : ' ╞ %s%s%s %s'%(CY, langs.log.symb_np, CS, value),
|
||||||
'23' : ' ╞ %s%s%s > %s'%(CY, lang.db_inv, CS, value),
|
'23' : ' ╞ %s%s%s > %s'%(CY, langs.log.db_inv, CS, value),
|
||||||
'24' : ' ╞ %s%s%s > %s'%(CY, lang.unused_r, CS, value),
|
'24' : ' ╞ %s%s%s > %s'%(CY, langs.log.unused_r, CS, value),
|
||||||
'25' : ' ╞ Article %snot yet checked%s: %s'%(CY, CS, value),
|
'25' : ' ╞ %s%s%s > %s'%(CY, langs.log.nycheck, CS, value),
|
||||||
'26' : ' ╞ %sNo index%s article %s'%(CY, CS, value),
|
'26' : ' ╞ %s%s%s %s'%(CY, langs.log.nyfile, CS, value),
|
||||||
'27' : ' ╞ %s%s%s %s'%(CY, lang.snpic_d, CS, value),
|
'27' : ' ╞ %s%s%s %s'%(CY, langs.log.snpic_d, CS, value),
|
||||||
'28' : ' ╘ %s (%s)'%(lang.ntd, value),
|
'28' : ' ╘ %s (%s)'%(langs.log.ntd, value),
|
||||||
'29' : ' ╞ %sEmpty configuration%s %s'%(CY, CS, value),
|
'29' : ' ╞ %sEmpty configuration%s %s'%(CY, CS, value),
|
||||||
'30' : ' ╞ Article %snot yet wip%s: %s'%(CY, CS, value),
|
'30' : ' ╞ %s%s%s > %s'%(CY, langs.log.nywip, CS, value),
|
||||||
'31' : ' ╞ Not included. %sMax items reached%s %s'%(CY, CS, value),
|
'32' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_c, CS, value),
|
||||||
'32' : ' ╞══ %s%s%s > %s'%(CG, lang.file_c, CS, value),
|
'33' : ' ╞══ %s%s%s > %s'%(CG, langs.log.dir_c, CS, value),
|
||||||
'33' : ' ╞══ %s%s%s > %s'%(CG, lang.dir_c, CS, value),
|
'34' : ' ╞══ %s%s%s > %s'%(CG, langs.log.file_n, CS, value),
|
||||||
'34' : ' ╞══ %s%s%s > %s'%(CG, lang.file_n, CS, value),
|
'35' : ' ╞═ %s%s%s %s'%(CG, langs.log.add, CS, value),
|
||||||
'35' : ' ╞ %sAdd item%s %s'%(CG, CS, value),
|
'36' : ' ╡ %s %s'%(langs.log.file_e, value),
|
||||||
'36' : ' ╡ %s %s'%(lang.file_e, value),
|
'37' : ' ╡ %s %s'%(langs.log.dir_e, value),
|
||||||
'37' : ' ╡ %s %s'%(lang.dir_e, value),
|
'40' : ' ╒ %s%s%s > "%s"'%(CY, langs.log.dom_ina, CS, value),
|
||||||
'40' : ' ╒ %s%s%s > "%s"'%(CY, lang.dom_ina, CS, value),
|
'41' : ' ╒ %s%s%s > "%s"'%(CR, langs.log.dom_inc, CS, value),
|
||||||
'41' : ' ╒ %s%s%s > "%s"'%(CR, lang.dom_inc, CS, value),
|
'42' : ' ╒ %s%s%s > "%s"'%(CG, langs.log.dom_act, CS, value),
|
||||||
'42' : ' ╒ %s%s%s > "%s"'%(CG, lang.dom_act, CS, value),
|
'43' : ' ╒ %s%s%s'%(CY, langs.log.dom_no, CS),
|
||||||
'43' : ' ╒ %s%s%s'%(CY, lang.dom_no, CS),
|
'44' : ' ╞ %s%s%s "tyto check %s"'%(CY, langs.log.check_m, CS, value),
|
||||||
'44' : ' ╞ %s%s%s "tyto check %s"'%(CY, lang.check_m, CS, value),
|
'51' : ' ╞ %s%s%s > %s'%(CY, langs.log.data_inc, CS, value),
|
||||||
'51' : ' ╞ %s%s%s > %s'%(CY, lang.data_inc, CS, value),
|
'255' : ' ╘ %s'%langs.log.laterout
|
||||||
'255' : ' ╘ %s'%lang.laterout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = logs[nbr]
|
msg = logs[nbr]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Tyto - Littérateur
|
# 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
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License
|
# it under the terms of the GNU Affero General Public License
|
||||||
|
@ -34,35 +34,8 @@
|
||||||
|
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, sys, locale, importlib
|
import os, sys, importlib
|
||||||
import args, lang, logs, dom, db, form, tyto, check, stats
|
import args, logs, dom, db, form, tyto, check, stats, langs
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
|
|
||||||
#========================#
|
#========================#
|
||||||
# Read lines from a file #
|
# Read lines from a file #
|
||||||
|
@ -94,10 +67,8 @@ def read_lines(f, alone):
|
||||||
|
|
||||||
#======================#
|
#======================#
|
||||||
# From command line: #
|
# From command line: #
|
||||||
# - 'showdb' / 'show' #
|
# Show or edit file #
|
||||||
# - 'editdb' / 'edit' #
|
# final html, db, src #
|
||||||
# Show or edit files #
|
|
||||||
# final html, db, load #
|
|
||||||
#----------------------#
|
#----------------------#
|
||||||
def manage(target):
|
def manage(target):
|
||||||
if not dom.exists: logs.out("10", '', True)
|
if not dom.exists: logs.out("10", '', True)
|
||||||
|
@ -127,10 +98,6 @@ def manage(target):
|
||||||
if args.action == "show-about":
|
if args.action == "show-about":
|
||||||
target = 'post'
|
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[]
|
# Convert command action to do[]
|
||||||
# as edit* &nd show* [action] have same target file
|
# as edit* &nd show* [action] have same target file
|
||||||
|
@ -198,26 +165,26 @@ def manage(target):
|
||||||
# Read or edit file, according to legacy args.action
|
# Read or edit file, according to legacy args.action
|
||||||
try:
|
try:
|
||||||
file = do[action][target]
|
file = do[action][target]
|
||||||
|
|
||||||
if args.action in actions_read:
|
if args.action in actions_read:
|
||||||
read_lines(file, True)
|
read_lines(file, True)
|
||||||
|
|
||||||
elif args.action in actions_edit:
|
elif args.action in actions_edit:
|
||||||
|
curr_hash = tyto.get_filesum(file, True)
|
||||||
tyto.edit_file(file)
|
tyto.edit_file(file)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logs.out("28", '%s + %s'%(action, target), True)
|
logs.out("28", '%s + %s'%(action, target), True)
|
||||||
|
|
||||||
|
|
||||||
# If edit article and hash changed, ask to check
|
# If edit article and hash changed, ask to check
|
||||||
if args.action == "edit" and post_src:
|
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:
|
if curr_hash != new_hash:
|
||||||
ask = ''
|
if file == post_src:
|
||||||
try: ask = input(' ├ %s%s '%(tr.post_chg, tr.q))
|
form.asking(' ├ %s%s '%(
|
||||||
except KeyboardInterrupt:
|
langs.site.post_chg, langs.site.q
|
||||||
print('')
|
), True)
|
||||||
logs.out("255", '', True)
|
|
||||||
|
|
||||||
if not ask in form.answer_yes:
|
|
||||||
logs.out("255", '', True)
|
|
||||||
|
|
||||||
# Reload post DB (if edited article, and check it if ask "y")
|
# Reload post DB (if edited article, and check it if ask "y")
|
||||||
importlib.reload(db)
|
importlib.reload(db)
|
||||||
|
|
|
@ -516,7 +516,8 @@ def files_to_srv(server):
|
||||||
d_in = uri.split("/")[-1]
|
d_in = uri.split("/")[-1]
|
||||||
d_in = uri.rsplit(d_in)[0]
|
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)
|
f_src = '%s%s'%(dom.articles_d[:-1], uri)
|
||||||
if server == 'wip':
|
if server == 'wip':
|
||||||
f_dst = '%s%s'%(dom.srv_wip[:-1], uri)
|
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)
|
f_dst = '%s%s'%(dom.srv_www[:-1], uri)
|
||||||
d_dst = '%s%s'%(dom.srv_www[:-1], d_in)
|
d_dst = '%s%s'%(dom.srv_www[:-1], d_in)
|
||||||
|
|
||||||
# Create folder and subfolders
|
# Create sub-directories in server
|
||||||
try:
|
try:
|
||||||
os.makedirs(d_dst, exist_ok=True)
|
os.makedirs(d_dst, exist_ok=True)
|
||||||
logs.out("33", d_dst, False)
|
logs.out("33", d_dst, False)
|
||||||
except:
|
except:
|
||||||
logs.out('4', d_dst, True)
|
logs.out('4', d_dst, True)
|
||||||
|
|
||||||
|
# COpy files to server
|
||||||
try:
|
try:
|
||||||
shutil.copy2(f_src, f_dst)
|
shutil.copy2(f_src, f_dst)
|
||||||
logs.out("32", f_dst, False)
|
logs.out("32", f_dst, False)
|
||||||
except:
|
except:
|
||||||
logs.out('4', f_dst, True)
|
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 dom.article_code:
|
||||||
if server == "wip": base_srv = dom.srv_wip
|
if server == "wip": base_srv = dom.srv_wip
|
||||||
elif server == "www": base_srv = dom.srv_www
|
elif server == "www": base_srv = dom.srv_www
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Tyto - Littérateur
|
# 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>
|
# Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License
|
# 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
|
# as published by the Free Software Foundation, either version 3 of the
|
||||||
# of the License, or (at your option) any later version.
|
# License, or of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
import os, re, sys, locale, shutil, importlib, time
|
import os, re, sys, locale, shutil, importlib, time
|
||||||
from pathlib import Path
|
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
|
# load locale translation
|
||||||
trans_dir = '/var/lib/tyto/translations'
|
trans_dir = '/var/lib/tyto/translations'
|
||||||
|
@ -112,15 +112,7 @@ def manage_wip(target):
|
||||||
# wip is up-to-date: ask to wip again
|
# wip is up-to-date: ask to wip again
|
||||||
else:
|
else:
|
||||||
logs.out("19", db.date_wip, False)
|
logs.out("19", db.date_wip, False)
|
||||||
try:
|
form.asking(' ├ [%s] %s%s '%(db.title, tr.wip_new, tr.q), True)
|
||||||
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)
|
|
||||||
|
|
||||||
wip_article(db.uri_file)
|
wip_article(db.uri_file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,35 +300,56 @@ def wip_words_tags():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#=======================#
|
#========================#
|
||||||
# Convert links from DB #
|
# Convert links set inDB #
|
||||||
# - link_%i #
|
|
||||||
# - file_%i #
|
# - file_%i #
|
||||||
#-----------------------#
|
# - link_%i #
|
||||||
def wip_links():
|
# from marker to HTML #
|
||||||
|
#------------------------#
|
||||||
|
def wip_link_convert(marker, html):
|
||||||
global post_bottom
|
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:
|
if db.uniq_files > 0:
|
||||||
for i in range(1, db.uniq_files + 1):
|
for i in range(1, db.uniq_files + 1):
|
||||||
file = 'db.file_%s'%i
|
link = 'db.file_%s'%i
|
||||||
post_bottom = post_bottom.replace(eval(file)[0]+'+',
|
link_css = "link_file"
|
||||||
eval(file)[1]%('_blank')
|
link_name = eval(link)[0][2:]
|
||||||
)
|
link_anc = eval(link)[1]
|
||||||
post_bottom = post_bottom.replace(eval(file)[0],
|
link_title = eval(link)[2]
|
||||||
eval(file)[1]%('_self')
|
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:
|
if db.uniq_links > 0:
|
||||||
for i in range(1, db.uniq_links + 1):
|
for i in range(1, db.uniq_links + 1):
|
||||||
link = 'db.link_%s'%i
|
link = 'db.link_%s'%i
|
||||||
post_bottom = post_bottom.replace(eval(link)[0]+'+',
|
link_css = "link"
|
||||||
eval(link)[1]%('_blank')
|
link_name = eval(link)[0][1:]
|
||||||
)
|
link_anc = eval(link)[1]
|
||||||
post_bottom = post_bottom.replace(eval(link)[0],
|
link_title = eval(link)[2]
|
||||||
eval(link)[1]%('_self')
|
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 Abbrs #
|
# Convert Abbrs #
|
||||||
|
@ -370,8 +383,8 @@ def wip_images():
|
||||||
if db.uniq_images == 0: return
|
if db.uniq_images == 0: return
|
||||||
|
|
||||||
global post_bottom
|
global post_bottom
|
||||||
image_link = '<a class="%s" href="%s" title="%s">%s</a>'
|
image_link = '<a class="%s" href="%s">%s</a>'
|
||||||
image_show = '<img class="%s" src="%s" alt="%s"%s />'
|
image_show = '<img class="%s" src="%s" alt="%s" title="%s"%s />'
|
||||||
|
|
||||||
# Check each line
|
# Check each line
|
||||||
for ln, line in enumerate(post_bottom.rsplit('\n')):
|
for ln, line in enumerate(post_bottom.rsplit('\n')):
|
||||||
|
@ -419,13 +432,15 @@ def wip_images():
|
||||||
image_target = eval(image)[1]
|
image_target = eval(image)[1]
|
||||||
image_target = db.sub_uri + image_target[1:]
|
image_target = db.sub_uri + image_target[1:]
|
||||||
image_src = image_show%(
|
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
|
# Set link for image
|
||||||
if target:
|
if target:
|
||||||
image_tgt = image_link%(
|
image_tgt = image_link%(
|
||||||
set_css, image_target, eval(image)[2], '%s'
|
set_css, image_target, '%s'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
image_tgt = '%s'
|
image_tgt = '%s'
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
# Generic
|
# Generic
|
||||||
|
sidebar = 'Sidebar'
|
||||||
|
navbar = 'Navbar'
|
||||||
|
metas = 'Metas Tags'
|
||||||
|
footer = 'Footer'
|
||||||
line = "Ligne"
|
line = "Ligne"
|
||||||
|
|
||||||
ntd = "Nothing to do"
|
ntd = "Nothing to do"
|
||||||
|
@ -44,5 +48,9 @@ mark_np = "Not paired marks"
|
||||||
symb_np = "Not paired symbols"
|
symb_np = "Not paired symbols"
|
||||||
snpic_d = "Using default snpic. Not found"
|
snpic_d = "Using default snpic. Not found"
|
||||||
anch_nu = "Anchor not uniq"
|
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..."
|
laterout = "Maybe later..."
|
||||||
|
|
|
@ -11,7 +11,12 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
# Generique
|
# Generique
|
||||||
linecol = "Line"
|
sidebar = 'Barre Latérale'
|
||||||
|
navbar = 'Barre de navigation'
|
||||||
|
metas = 'Balises Metas'
|
||||||
|
footer = "Pied de Page"
|
||||||
|
|
||||||
|
line = "Line"
|
||||||
|
|
||||||
ntd = "Rien à faire"
|
ntd = "Rien à faire"
|
||||||
unused_r = "Ressource manquante"
|
unused_r = "Ressource manquante"
|
||||||
|
@ -44,5 +49,10 @@ mark_np = "Marqueurs non jumelés"
|
||||||
symb_np = "Symboles non jumelés"
|
symb_np = "Symboles non jumelés"
|
||||||
snpic_d = "snpic utilisé par défaut. Manquant"
|
snpic_d = "snpic utilisé par défaut. Manquant"
|
||||||
anch_nu = "Ancre non unique"
|
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..."
|
laterout = "Pour plus tard..."
|
||||||
|
|
|
@ -23,7 +23,7 @@ This is a python file, so... DO NOT REMOVE:
|
||||||
# Generic
|
# Generic
|
||||||
sidebar = 'Sidebar'
|
sidebar = 'Sidebar'
|
||||||
navbar = 'Navbar'
|
navbar = 'Navbar'
|
||||||
metas = 'HTML Metas Tags'
|
metas = 'Metas Tags'
|
||||||
footer = 'Footer'
|
footer = 'Footer'
|
||||||
title = 'Title'
|
title = 'Title'
|
||||||
File = 'File'
|
File = 'File'
|
||||||
|
@ -178,7 +178,7 @@ sidebar_doc = \
|
||||||
'# Order in sidebar position\n' + \
|
'# Order in sidebar position\n' + \
|
||||||
'# Max articles = %d\n' + \
|
'# Max articles = %d\n' + \
|
||||||
'# Option Tp set sidebar title:\n' + \
|
'# Option Tp set sidebar title:\n' + \
|
||||||
' ": Sidebar Title"\n' + \
|
'# ": Sidebar Title"\n' + \
|
||||||
'\n# %s\n'%(20 * "-") + \
|
'\n# %s\n'%(20 * "-") + \
|
||||||
'# Examples :\n' + \
|
'# Examples :\n' + \
|
||||||
'# : My new articles list'
|
'# : My new articles list'
|
||||||
|
|
|
@ -23,7 +23,7 @@ Ceci est un fichier python, donc... NE PAS ENLEVER :
|
||||||
# Generic
|
# Generic
|
||||||
sidebar = 'Barre Latérale'
|
sidebar = 'Barre Latérale'
|
||||||
navbar = 'Barre de navigation'
|
navbar = 'Barre de navigation'
|
||||||
metas = 'Balises Metas HTML'
|
metas = 'Balises Metas'
|
||||||
footer = "Pied de Page"
|
footer = "Pied de Page"
|
||||||
title = 'Titre'
|
title = 'Titre'
|
||||||
File = 'Fichier'
|
File = 'Fichier'
|
||||||
|
@ -179,7 +179,7 @@ sidebar_doc = \
|
||||||
'# L\'ordre définit la position\n' + \
|
'# L\'ordre définit la position\n' + \
|
||||||
'# Articles max = %d\n' + \
|
'# Articles max = %d\n' + \
|
||||||
'# Option Pour définir un titre à la barre latérale:\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 * "-") + \
|
'\n# %s\n'%(20 * "-") + \
|
||||||
'# Exemples :\n' + \
|
'# Exemples :\n' + \
|
||||||
'# : Ma liste des nouveaux articles\n' + \
|
'# : Ma liste des nouveaux articles\n' + \
|
||||||
|
|
Loading…
Reference in New Issue