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 sys
|
||||
sys.path.insert(0, '/var/lib/tyto/program')
|
||||
import check, wip, domain, log
|
||||
import check, wip, domain, log, sidebar
|
||||
|
||||
#=======#
|
||||
# Tools #
|
||||
|
@ -53,7 +53,8 @@ def tyto_args(ta):
|
|||
Actions = { 'check' : check.manage_check,
|
||||
'wip' : wip.manage_wip,
|
||||
'domain' : domain.manage_domain,
|
||||
'log' : log.manage_log
|
||||
'log' : log.manage_log,
|
||||
'sidebar' : sidebar.manage_sidebar
|
||||
}
|
||||
|
||||
# Dict for Options
|
||||
|
@ -86,7 +87,7 @@ def tyto_args(ta):
|
|||
try:
|
||||
Actions[sys.argv[1]](Target, Opt)
|
||||
except KeyError:
|
||||
print(':( Invalid action "%s"'%sys.argv[1])
|
||||
print(':< Invalid action "%s"'%sys.argv[1])
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -441,8 +441,8 @@ def check_date(date):
|
|||
bool(datetime.strptime(date[2], fmt_article))
|
||||
except ValueError:
|
||||
Post_Err = True
|
||||
msg_log = 'Line %s. Invalid date: %s'%(date[1],date[2])
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
msg_log = 'Line %s. Invalid date: %s'%(date[1],date[2])
|
||||
log.append_f(post_logs, msg_log, 1)
|
||||
|
||||
# Create date_check (epoch) from article's Date + now TIME
|
||||
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"'%(
|
||||
m_in[0]+1, marker
|
||||
)
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
log.append_f(post_logs, msg_log, 1)
|
||||
Post_Err = True
|
||||
|
||||
#=================================#
|
||||
|
@ -512,7 +512,7 @@ def check_links(line, ln, stats_links_uniq):
|
|||
|
||||
if not link_name:
|
||||
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
|
||||
return(1)
|
||||
|
||||
|
@ -540,7 +540,7 @@ def check_links(line, ln, stats_links_uniq):
|
|||
link_page = '_%s'%link_name
|
||||
if not link_page in article:
|
||||
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
|
||||
|
||||
if Post_Err: return
|
||||
|
@ -602,7 +602,7 @@ def check_files(line, ln, stats_files_uniq):
|
|||
file_page = '__%s'%file_name
|
||||
if not file_page in article:
|
||||
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
|
||||
|
||||
# Check URI value (exists and where)
|
||||
|
|
|
@ -51,7 +51,7 @@ if not os.path.exists(tyto_logs):
|
|||
file.write('')
|
||||
file.close()
|
||||
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
|
||||
# If not exists, create the file conf
|
||||
|
@ -92,10 +92,10 @@ def append_f(f, line_val):
|
|||
# for process form: "
|
||||
# - rename temp domain conf to legacy #
|
||||
#--------------------------------------#
|
||||
def exiting(process,out,msg):
|
||||
def exiting(process, out, msg):
|
||||
msgs = [
|
||||
'\n:D All done !',
|
||||
'\n:/ Maybe next time...',
|
||||
':D All done !',
|
||||
':/ Maybe next time...',
|
||||
'%s'%msg
|
||||
]
|
||||
|
||||
|
@ -120,7 +120,7 @@ def manage_domain(Domain, Opt):
|
|||
|
||||
add_domain(set_domain)
|
||||
|
||||
elif Opt == 'Edit' or '-E':
|
||||
elif Opt == 'Edit':
|
||||
if domain_conf:
|
||||
print(':> Editing',domain_conf)
|
||||
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
|
||||
print(' ├─────────────────────────────')
|
||||
confirm = input(' └ Activate domain configuration ? ')
|
||||
if confirm in ['y', 'Y']:
|
||||
create_domain()
|
||||
else:
|
||||
exiting('form', 1, '')
|
||||
if confirm in ['y', 'Y']: create_domain()
|
||||
else : exiting('form', 1, '')
|
||||
|
||||
#==============#
|
||||
# Get protocol #
|
||||
|
@ -347,10 +345,8 @@ def domain_form():
|
|||
# Separator Pages Titles (default '-')
|
||||
# ------------------------------------
|
||||
global sep_titles
|
||||
try:
|
||||
sep_titles
|
||||
except:
|
||||
sep_titles = '-'
|
||||
try: sep_titles
|
||||
except: sep_titles = '-'
|
||||
|
||||
set_sep = input(' ├ Website pages separator (%s) ? '%sep_titles)
|
||||
if set_sep:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#----------------------------------------------------------------------
|
||||
|
||||
#**********************************************************************
|
||||
|
||||
import re, os
|
||||
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'%(
|
||||
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
|
||||
file_string = open(check.post_tmp,'r').read()
|
||||
file_string = open(check.post_tmp, 'r').read()
|
||||
post_lines = file_string.rsplit('\n')
|
||||
|
||||
# Set wip_html string. Will be the HTML part <article>
|
||||
|
|
Loading…
Reference in New Issue