html: in-dev of sidebar fonction
This commit is contained in:
parent
2ce6e0d4a5
commit
51389e2e3c
|
@ -34,7 +34,7 @@ Directories that must be writeable by Tyto
|
||||||
# Import needed libs and tyto's libs
|
# Import needed libs and tyto's libs
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, '/var/lib/tyto/program')
|
sys.path.insert(0, '/var/lib/tyto/program')
|
||||||
import check, wip, domain, log
|
import check, wip, domain, log, sidebar
|
||||||
|
|
||||||
#=======#
|
#=======#
|
||||||
# Tools #
|
# Tools #
|
||||||
|
@ -53,7 +53,8 @@ def tyto_args(ta):
|
||||||
Actions = { 'check' : check.manage_check,
|
Actions = { 'check' : check.manage_check,
|
||||||
'wip' : wip.manage_wip,
|
'wip' : wip.manage_wip,
|
||||||
'domain' : domain.manage_domain,
|
'domain' : domain.manage_domain,
|
||||||
'log' : log.manage_log
|
'log' : log.manage_log,
|
||||||
|
'sidebar' : sidebar.manage_sidebar
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dict for Options
|
# Dict for Options
|
||||||
|
@ -86,7 +87,7 @@ def tyto_args(ta):
|
||||||
try:
|
try:
|
||||||
Actions[sys.argv[1]](Target, Opt)
|
Actions[sys.argv[1]](Target, Opt)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(':( Invalid action "%s"'%sys.argv[1])
|
print(':< Invalid action "%s"'%sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -442,7 +442,7 @@ def check_date(date):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
msg_log = 'Line %s. Invalid date: %s'%(date[1],date[2])
|
msg_log = 'Line %s. Invalid date: %s'%(date[1],date[2])
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
|
|
||||||
# Create date_check (epoch) from article's Date + now TIME
|
# Create date_check (epoch) from article's Date + now TIME
|
||||||
if not Post_Err:
|
if not Post_Err:
|
||||||
|
@ -491,7 +491,7 @@ def if_option_marker(marker, m_in):
|
||||||
msg_log = 'Line %s. Unused Alt-Text for marker "%s"'%(
|
msg_log = 'Line %s. Unused Alt-Text for marker "%s"'%(
|
||||||
m_in[0]+1, marker
|
m_in[0]+1, marker
|
||||||
)
|
)
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
|
|
||||||
#=================================#
|
#=================================#
|
||||||
|
@ -512,7 +512,7 @@ def check_links(line, ln, stats_links_uniq):
|
||||||
|
|
||||||
if not link_name:
|
if not link_name:
|
||||||
msg_log = 'Line %s. Unused NAME for marker "link:"'%ln
|
msg_log = 'Line %s. Unused NAME for marker "link:"'%ln
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
return(1)
|
return(1)
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ def check_links(line, ln, stats_links_uniq):
|
||||||
link_page = '_%s'%link_name
|
link_page = '_%s'%link_name
|
||||||
if not link_page in article:
|
if not link_page in article:
|
||||||
msg_log = 'Unused "%s" for marker "link:" in article"'%link_page
|
msg_log = 'Unused "%s" for marker "link:" in article"'%link_page
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
|
|
||||||
if Post_Err: return
|
if Post_Err: return
|
||||||
|
@ -602,7 +602,7 @@ def check_files(line, ln, stats_files_uniq):
|
||||||
file_page = '__%s'%file_name
|
file_page = '__%s'%file_name
|
||||||
if not file_page in article:
|
if not file_page in article:
|
||||||
msg_log = 'Unused "%s" for marker "file:" in article"'%file_page
|
msg_log = 'Unused "%s" for marker "file:" in article"'%file_page
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
|
|
||||||
# Check URI value (exists and where)
|
# Check URI value (exists and where)
|
||||||
|
|
|
@ -51,7 +51,7 @@ if not os.path.exists(tyto_logs):
|
||||||
file.write('')
|
file.write('')
|
||||||
file.close()
|
file.close()
|
||||||
msg_log = 'Log > Create logs file for Tyto in %s\n'%tyto_logs
|
msg_log = 'Log > Create logs file for Tyto in %s\n'%tyto_logs
|
||||||
log.append_f(tyto_logs,msg_log,0)
|
log.append_f(tyto_logs, msg_log, 0)
|
||||||
|
|
||||||
# Get database domains
|
# Get database domains
|
||||||
# If not exists, create the file conf
|
# If not exists, create the file conf
|
||||||
|
@ -92,10 +92,10 @@ def append_f(f, line_val):
|
||||||
# for process form: "
|
# for process form: "
|
||||||
# - rename temp domain conf to legacy #
|
# - rename temp domain conf to legacy #
|
||||||
#--------------------------------------#
|
#--------------------------------------#
|
||||||
def exiting(process,out,msg):
|
def exiting(process, out, msg):
|
||||||
msgs = [
|
msgs = [
|
||||||
'\n:D All done !',
|
':D All done !',
|
||||||
'\n:/ Maybe next time...',
|
':/ Maybe next time...',
|
||||||
'%s'%msg
|
'%s'%msg
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ def manage_domain(Domain, Opt):
|
||||||
|
|
||||||
add_domain(set_domain)
|
add_domain(set_domain)
|
||||||
|
|
||||||
elif Opt == 'Edit' or '-E':
|
elif Opt == 'Edit':
|
||||||
if domain_conf:
|
if domain_conf:
|
||||||
print(':> Editing',domain_conf)
|
print(':> Editing',domain_conf)
|
||||||
old_conf_ID = check.get_filesum(domain_conf, True)
|
old_conf_ID = check.get_filesum(domain_conf, True)
|
||||||
|
@ -191,10 +191,8 @@ def add_domain(set_domain):
|
||||||
# Ask to confirm to write activation domain
|
# Ask to confirm to write activation domain
|
||||||
print(' ├─────────────────────────────')
|
print(' ├─────────────────────────────')
|
||||||
confirm = input(' └ Activate domain configuration ? ')
|
confirm = input(' └ Activate domain configuration ? ')
|
||||||
if confirm in ['y', 'Y']:
|
if confirm in ['y', 'Y']: create_domain()
|
||||||
create_domain()
|
else : exiting('form', 1, '')
|
||||||
else:
|
|
||||||
exiting('form', 1, '')
|
|
||||||
|
|
||||||
#==============#
|
#==============#
|
||||||
# Get protocol #
|
# Get protocol #
|
||||||
|
@ -347,10 +345,8 @@ def domain_form():
|
||||||
# Separator Pages Titles (default '-')
|
# Separator Pages Titles (default '-')
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
global sep_titles
|
global sep_titles
|
||||||
try:
|
try: sep_titles
|
||||||
sep_titles
|
except: sep_titles = '-'
|
||||||
except:
|
|
||||||
sep_titles = '-'
|
|
||||||
|
|
||||||
set_sep = input(' ├ Website pages separator (%s) ? '%sep_titles)
|
set_sep = input(' ├ Website pages separator (%s) ? '%sep_titles)
|
||||||
if set_sep:
|
if set_sep:
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import re, os
|
import re, os
|
||||||
import check, log, domain
|
import check, log, domain
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Name: Tyto - Littérateur
|
||||||
|
# Type: Global functions for HTML page
|
||||||
|
# Description: Create final HTML Page
|
||||||
|
# file: sidebar.py
|
||||||
|
# Folder: /var/lib/tyto/programs/
|
||||||
|
# By echolib (XMPP: im@echolib.re)
|
||||||
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||||
|
|
||||||
|
#------------
|
||||||
|
# funny stats
|
||||||
|
#------------
|
||||||
|
# lines:
|
||||||
|
# functions:
|
||||||
|
# comments:
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
#**********************************************************************
|
||||||
|
|
||||||
|
import re, os, sys, subprocess
|
||||||
|
import log, domain, check
|
||||||
|
|
||||||
|
#========================#
|
||||||
|
# Manage sidebar command #
|
||||||
|
#------------------------#
|
||||||
|
def manage_sidebar(article, Opt):
|
||||||
|
create = False
|
||||||
|
|
||||||
|
# Create tyto.sidebar
|
||||||
|
if not os.path.exists(domain.domain_sdb_load):
|
||||||
|
create_sdb_load()
|
||||||
|
create = True
|
||||||
|
|
||||||
|
# Wan to edit (in nano)
|
||||||
|
# Then, ask to make HTML sidebar (if file changed)
|
||||||
|
if Opt == "Edit":
|
||||||
|
old_sdb_ID = check.get_filesum(domain.domain_sdb_load, True)
|
||||||
|
edit_sdb = subprocess.run(['/usr/bin/nano',
|
||||||
|
'--linenumbers',
|
||||||
|
domain.domain_sdb_load])
|
||||||
|
new_sdb_ID = check.get_filesum(domain.domain_sdb_load, True)
|
||||||
|
if old_sdb_ID == new_sdb_ID:
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
ask_make_sdb = input('! Create new HTML sidebar ? ')
|
||||||
|
if not ask_make_sdb in ['y', 'Y']: domain.exiting('root', 1, '')
|
||||||
|
|
||||||
|
loop_sidebar(create)
|
||||||
|
|
||||||
|
#========================#
|
||||||
|
# Read tyto.sidebar file #
|
||||||
|
#------------------------#
|
||||||
|
def loop_sidebar(create):
|
||||||
|
Post_Err = False
|
||||||
|
sdb_posts = []
|
||||||
|
max_items = int(domain.domain_sdb_items) + 1
|
||||||
|
counter = 0 # TO not count more than set in config
|
||||||
|
sdb_loaded = (open(domain.domain_sdb_load)).read()
|
||||||
|
for line in sdb_loaded.rsplit('\n'):
|
||||||
|
if create : print(line)
|
||||||
|
elif line.startswith('#'): continue
|
||||||
|
elif len(line) == 0 : continue
|
||||||
|
else:
|
||||||
|
counter += 1
|
||||||
|
if counter == max_items: break
|
||||||
|
post_uri = '%s%s'%(domain.domain_articles, line)
|
||||||
|
if not os.path.exists(post_uri):
|
||||||
|
print(':< Unused file: %s'%post_uri)
|
||||||
|
Post_Err = True
|
||||||
|
else:
|
||||||
|
hash_post = check.get_filesum(post_uri, False)
|
||||||
|
sdb_posts = sdb_posts + [hash_post]
|
||||||
|
|
||||||
|
print(sdb_posts)
|
||||||
|
|
||||||
|
#=====================#
|
||||||
|
# Create sidebar file #
|
||||||
|
#---------------------#
|
||||||
|
def create_sdb_load():
|
||||||
|
sdb_file_fr = '# Nom: Tyto - Littérateur\n' + \
|
||||||
|
'# Type: fichier texte\n' + \
|
||||||
|
'# Description: Fichier appelé par : tyto sidebar\n' + \
|
||||||
|
'# fichier: tyto.sidebar\n' + \
|
||||||
|
'# Dossier: articles/sidebar/\n' + \
|
||||||
|
'# (depuis le dossier du domaine)\n' + \
|
||||||
|
'# Comment: 1 URI de l\'article par ligne\n' + \
|
||||||
|
'# L\'ordre définit la position\n' + \
|
||||||
|
'# exemples :\n' + \
|
||||||
|
'# index.tyto\n' + \
|
||||||
|
'# dir1/index.tyto\n'
|
||||||
|
|
||||||
|
sdb_file_en = '# Name: Tyto - Littérateur\n' + \
|
||||||
|
'# Type: Text file\n' + \
|
||||||
|
'# Description: file called with: tyto sidebar\n' + \
|
||||||
|
'# file: tyto.sidebar\n' + \
|
||||||
|
'# Folder: articles/sidebar/\n' + \
|
||||||
|
'# (from the domain folder)\n' + \
|
||||||
|
'# Comment: 1 article URI per line\n' + \
|
||||||
|
'# Order in sidebar position\n' + \
|
||||||
|
'# examples :\n' + \
|
||||||
|
'# index.tyto\n' + \
|
||||||
|
'# dir1/index.tyto\n'
|
||||||
|
|
||||||
|
if re.match('fr', domain.domain_lang, re.IGNORECASE):
|
||||||
|
sdb_file = sdb_file_fr
|
||||||
|
else:
|
||||||
|
sdb_file = sdb_file_en
|
||||||
|
|
||||||
|
file = open(domain.domain_sdb_load, "w")
|
||||||
|
file.write(sdb_file)
|
||||||
|
file.close()
|
||||||
|
msg_log = 'Sidebar > Create new sidebar file in %s'%(
|
||||||
|
domain.domain_sdb_load
|
||||||
|
)
|
||||||
|
log.append_f(domain.tyto_logs, msg_log, 0)
|
|
@ -77,10 +77,10 @@ def manage_wip(file_post, Force):
|
||||||
msg_log = 'Wip > Article: %s. logs: %s'%(
|
msg_log = 'Wip > Article: %s. logs: %s'%(
|
||||||
check.post_uri, check.post_logs
|
check.post_uri, check.post_logs
|
||||||
)
|
)
|
||||||
log.append_f(domain.tyto_logs,msg_log,0)
|
log.append_f(domain.tyto_logs, msg_log, 0)
|
||||||
|
|
||||||
# Set file_string from post_tmp
|
# Set file_string from post_tmp
|
||||||
file_string = open(check.post_tmp,'r').read()
|
file_string = open(check.post_tmp, 'r').read()
|
||||||
post_lines = file_string.rsplit('\n')
|
post_lines = file_string.rsplit('\n')
|
||||||
|
|
||||||
# Set wip_html string. Will be the HTML part <article>
|
# Set wip_html string. Will be the HTML part <article>
|
||||||
|
|
Loading…
Reference in New Issue