Lots of changes. wip page file created with needed in-files article

This commit is contained in:
Cyrille L 2023-02-06 10:50:50 +01:00
parent a71e2e58e6
commit 8e74f8dece
11 changed files with 1252 additions and 712 deletions

View File

@ -26,8 +26,6 @@
import sys
sys.path.insert(0, '/var/lib/tyto/program')
import check, domain, wip, html
#====================#
# MAIN #
# Treat Arguments #
@ -36,6 +34,9 @@ if not __name__ == "__main__":
print(':< Mismatch program start')
sys.exit(1)
import args
import check, domain, wip, html
noarg = False
target = ''
option = ''
@ -51,38 +52,7 @@ actions = {
'footer' : html.manage_configs
}
# Dict for Options
options = {
'-a' : 'Add', 'add' : 'Add',
'-R' : "Remove", 'remove' : "Remove",
'-n' : "New", 'new' : "New",
'-e' : "Edit", 'edit' : "Edit",
'-F' : "Force", 'force' : "Force",
'-s' : "Show",
'-d' : 'DB',
'again': 'Again'
}
# Set Argument 2 or 3
#--------------------
for i in range(2,4):
try:
sys.argv[i]
try:
if not option: option = options[sys.argv[i]]
else: target: target = sys.argv[i]
except:
if not target: target = sys.argv[i]
else: option: option = options[sys.argv[i]]
except:
noarg = True
if noarg: continue
# Argument 1
#-----------
try:
actions[sys.argv[1]](target, option)
except KeyError:
print(':< Invalid action "%s": [check, wip...]'%sys.argv[1])
actions[sys.argv[1]](args.target, args.option)

View File

@ -0,0 +1,86 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Command arguments
# Description: Check arguments
# file: args.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 sys
# Arguments from command line
#----------------------------
# Dict for Actions
actions = (
'check',
'domain',
'footer',
'metas',
'navbar',
'wip',
'publish',
'sidebar'
)
# Dict for Options
options = {
'-a' : 'Add', 'add' : 'Add',
'-c' : 'Create', 'create' : 'Create',
'-d' : 'DB', 'db' : 'DB',
'-e' : "Edit", 'edit' : "Edit",
'-F' : "Force", 'force' : "Force",
'-n' : "New", 'new' : "New",
'-R' : "Remove", 'remove' : "Remove",
'-s' : "Show", 'show' : 'Show',
'again' : 'Again'
}
# Second argument in command
#---------------------------
arguments = (
'-a', 'add',
'-c', 'create',
'-d', 'db',
'-e', 'edit',
'-F', 'force',
'-n', 'new',
'-R', 'remove',
'-s', 'show',
'again'
)
option = ''
target = ''
try:
sys.argv[1]
except:
print(':< Needed [action] argument')
sys.exit(1)
if not sys.argv[1] in actions:
print(':< Unused [action] argument: "%s"'%sys.argv[1])
sys.exit(1)
# Check and set arguments from command line
#------------------------------------------
for i in range(2,4):
try:
sys.argv[i]
if sys.argv[i] in arguments:
option = options[sys.argv[i]]
else:
target = sys.argv[i]
except:
continue

View File

@ -23,10 +23,7 @@ from datetime import datetime
from time import gmtime, strftime
import time
import tyto
# Load domain configuration if exists
if tyto.domain_exists: exec(open(tyto.domain_conf).read())
import logs, db, tyto
post_err = False
date_wip = hash_wip = date_www = hash_www = ''
@ -37,21 +34,22 @@ date_wip = hash_wip = date_www = hash_www = ''
# Start checking article #
#-------------------------#--------------------------------------------
def manage_check(target, option):
# target needed
if not target: logs.out("5", '', True)
global post_bottom, article_bottom
global post_words
# target needed
if not target: tyto.exiting("5", '', True)
# Article exists + has DB ?
db_exists = tyto.get_db_post(target)
# Manage option
if option == 'Edit':
tyto.edit_file(tyto.uri_root)
tyto.edit_file(tyto.uri_file)
return
elif option == 'Show':
article_raw = open(tyto.uri_root).read()
article_raw = open(tyto.uri_file).read()
for line in article_raw.rsplit('\n'):
print(line)
return
@ -66,21 +64,12 @@ def manage_check(target, option):
try:
exec(open(tyto.post_db).read(),globals())
try:
if hash_chk == tyto.hash_post and not option == 'Force':
tyto.exiting("20", date_chk, True)
except: pass
except: pass
# Get sub_uri for HTML
global sub_uri
sub_uri = tyto.uri_post.rsplit('articles/')[1]
sub_nbr = sub_uri.count('/')
if sub_nbr == 0 : sub_uri = './'
else: sub_uri = sub_nbr * '../'
logs.out("20", date_chk, True)
finally: pass
# Start processes
file_to_string(tyto.uri_root)
file_to_string(tyto.uri_file)
# Specific to inline-code: check markers on same line
check_icodes(article.rsplit('\n'))
@ -106,7 +95,7 @@ def manage_check(target, option):
check_headers(post_header)
# Exit if unused needed tags
if post_err: tyto.exiting("7", '', True)
if post_err: logs.out("7", '', True)
# No error
create_database()
@ -134,8 +123,7 @@ def file_to_string(post_file):
article = open(post_file, 'r').read()
# Check if separator or exit
if not '-----' in article:
tyto.exiting("6", '-----', True)
if not '-----' in article: logs.out("6", '-----', True)
# Set from separator, NOT splitted by new line
article_header = article.rsplit('-----')[0]
@ -146,9 +134,9 @@ def file_to_string(post_file):
post_bottom = article.rsplit('-----')[1].rsplit('\n')
#
# Check inline code, for markers on same line
#
#=============================================#
# Check inline code, for markers on same line #
#---------------------------------------------#
def check_icodes(article):
quote = bcode = False
@ -172,11 +160,12 @@ def check_icodes(article):
icode_m1 = line.count(tyto.words_tags[9][0])
icode_m2 = line.count(tyto.words_tags[9][1])
if icode_m1 != icode_m2:
tyto.exiting("8", 'inline-code: line %s. %s %s'%(ln,
logs.out("8", 'inline-code: line %s. %s %s'%(ln,
tyto.words_tags[9][0], tyto.words_tags[9][1]
), True
)
#==================================#
# Check tags from article's header #
#----------------------------------#
@ -186,6 +175,11 @@ def check_headers(post_header):
global stat_links, stat_images, stat_files, stat_raws, stat_abbrs
global post_tags
global snpic_url
global files_post
# Contains all files URIs needed for article
# Used with publish command to copy needed files
files_post = ('')
snshare = False
snpic_name = ''
@ -259,7 +253,7 @@ def check_headers(post_header):
# Check if set needed tags
for tag in need_headers:
if not need_headers[tag]:
tyto.exiting("6", tag, False)
logs_out("6", tag, False)
###
@ -282,20 +276,20 @@ def check_headers(post_header):
abbr_short = post_header[ln - 1].rsplit(tag)[1].lstrip()
if not abbr_short:
tyto.exiting("2", "Line %s (SHORT, %s)"%(ln, tag), False)
logs.out("2", "Line %s (SHORT, %s)"%(ln, tag), False)
post_err = True
if not abbr_short.isupper():
tyto.exiting("3", "Line %s (Upper SHORT, %s)"%(ln, tag), False)
logs.out("3", "Line %s (Upper SHORT, %s)"%(ln, tag), False)
post_err = True
continue
if not isin(r'!\b%s\b'%abbr_short, post_bottom):
tyto.exiting("6", '!%s'%abbr_short, False)
logs.out("6", '!%s'%abbr_short, False)
post_err = True
abbr_long = post_header[ln].lstrip()
if abbr_long.startswith(tyto.headers): abbr_long = ''
if not abbr_long:
tyto.exiting("2", "Line %s (Long, %s)"%(ln + 1, tag), False)
logs.out("2", "Line %s (Long, %s)"%(ln + 1, tag), False)
post_err = True
abbr_alt = post_header[ln + 1].lstrip()
@ -319,22 +313,22 @@ def check_headers(post_header):
link_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
if not link_name:
tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False)
logs.out("2", "Line %s (Name, %s)"%(ln, tag), False)
post_err = True
if not isin(r'\b_%s\b'%link_name, post_bottom):
tyto.exiting("6", "_%s"%link_name, False)
logs.out("6", "_%s"%link_name, False)
post_err = True
link_url = post_header[ln].lstrip()
if link_url.startswith(tyto.headers): link_url = ''
if not link_url:
tyto.exiting("2", "Line %s (URL, %s)"%(ln + 1, tag), False)
logs.out("2", "Line %s (URL, %s)"%(ln + 1, tag), False)
post_err = True
link_alt = post_header[ln + 1].lstrip()
if link_alt.startswith(tyto.headers): link_alt = ''
if not link_alt:
tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
post_err = True
if not post_err:
@ -356,24 +350,26 @@ def check_headers(post_header):
image_name = post_header[ln - 1]
image_name = image_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
if not image_name:
tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False)
logs.out("2", "Line %s (Name, %s)"%(ln, tag), False)
post_err = True
if not isin(r'\b_%s%s\b'%(tag, image_name), post_bottom):
tyto.exiting("6", "_%s%s"%(tag, image_name), False)
logs.out("6", "_%s%s"%(tag, image_name), False)
post_err = True
image_uri = post_header[ln].lstrip()
if image_uri.startswith(tyto.headers): image_uri = ''
if not image_uri:
tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
post_err = True
else:
check_file_uri('image', image_uri, ln + 1)
f_uri = web_uri[1:len(web_uri)]
files_post = (files_post + "'%s', "%f_uri)
image_alt = post_header[ln + 1].lstrip()
if image_alt.startswith(tyto.headers): image_alt = ''
if not image_alt:
tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
post_err = True
if not post_err:
@ -393,24 +389,26 @@ def check_headers(post_header):
raw_name = post_header[ln - 1]
raw_name = raw_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
if not raw_name:
tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False)
logs.out("2", "Line %s (Name, %s)"%(ln, tag), False)
post_err = True
if not isin(r'\b_%s%s\b'%(tag, raw_name), post_bottom):
tyto.exiting("6", "_%s%s"%(tag, raw_name), False)
logs.out("6", "_%s%s"%(tag, raw_name), False)
post_err = True
raw_uri = post_header[ln].lstrip()
if raw_uri.startswith(tyto.headers): raw_uri = ''
if not raw_uri:
tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
post_err = True
else:
check_file_uri('file', raw_uri, ln + 1)
f_uri = web_uri[1:len(web_uri)]
files_post = (files_post + "'%s', "%f_uri)
raw_alt = post_header[ln + 1].lstrip()
if raw_alt.startswith(tyto.headers): raw_alt = ''
if not raw_alt:
tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
post_err = True
if not post_err:
@ -429,24 +427,26 @@ def check_headers(post_header):
file_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
if not file_name:
tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False)
logs.out("2", "Line %s (Name, %s)"%(ln, tag), False)
post_err = True
if not isin(r'\b__%s\b'%file_name, post_bottom):
tyto.exiting("6", "__%s"%file_name, False)
logs.out("6", "__%s"%file_name, False)
post_err = True
file_uri = post_header[ln].lstrip()
if file_uri.startswith(tyto.headers): file_uri = ''
if not file_uri:
tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False)
post_err = True
else:
check_file_uri('file', file_uri, ln + 1)
f_uri = web_uri[1:len(web_uri)]
files_post = (files_post + "'%s', "%f_uri)
file_alt = post_header[ln + 1].lstrip()
if file_alt.startswith(tyto.headers): file_alt = ''
if not file_alt:
tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False)
post_err = True
if not post_err:
@ -461,6 +461,7 @@ def check_headers(post_header):
# snpic (set image to share to social networks)
#----------------------------------------------
if snpic_name: continue
snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo)
tag = tyto.headers[11] # snpic:
if line.startswith(tag):
snpic_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
@ -470,15 +471,14 @@ def check_headers(post_header):
image_uri = post_header[ln].lstrip()
check_file_uri('image', image_uri, ln + 1)
snshare = True
snpic_url = '%s%s'%(domain_url, web_uri)
snpic_url = '%s%s'%(db.domain_www_url, web_uri)
break
if not snshare:
tyto.exiting("10", '%s %s'%(tyto.headers[6], snpic_name), True)
logs.out("12", '%s %s'%(tyto.headers[6], snpic_name), True)
# Exit if error in optional tags
#-------------------------------
if post_err:
tyto.exiting("7", '', True)
if post_err: logs.out("7", '', True)
#================================#
@ -495,7 +495,7 @@ def check_date(date, ln):
bool(datetime.strptime(date, fmt_article))
except ValueError:
post_err = True
tyto.exiting("3", 'Line %s (date, %s)'%(ln, date), False)
logs.out("3", 'Line %s (date, %s)'%(ln, date), False)
# Create date_check (epoch) from article's Date + now TIME
if not post_err:
@ -516,9 +516,9 @@ def check_file_uri(filetype, filename, ln):
# (@ = images/, / = articles/, else = post_dir)
if filename.startswith('@'):
if filetype == 'image':
fileuri = domain_images + filename[1: len(filename)]
fileuri = db.domain_images + filename[1: len(filename)]
elif filetype == 'file':
fileuri = domain_files + filename[1: len(filename)]
fileuri = db.domain_files + filename[1: len(filename)]
elif filename.startswith('/'):
fileuri = tyto.post_dir + filename[1: len(filename)]
@ -528,11 +528,11 @@ def check_file_uri(filetype, filename, ln):
# Check if file exists
if not os.path.exists(fileuri):
tyto.exiting("1", "Line %s, %s"%(ln, fileuri), False)
logs.out("1", "Line %s, %s"%(ln, fileuri), False)
post_err = True
return
web_uri = '/' + fileuri.replace(domain_articles, "")
web_uri = '/' + fileuri.replace(db.domain_articles, "")
#===========================#
@ -560,7 +560,7 @@ def check_content(post_bottom):
if line.startswith(tag[1]): c_closed += 1
if c_opened != c_closed:
tyto.exiting("8", '%s: "%s", "%s"'%(tag[4], tag[0], tag[1]), False)
logs.out("8", '%s: "%s", "%s"'%(tag[4], tag[0], tag[1]), False)
post_err = True
return # Useless and could code errors to check nexts
else:
@ -581,7 +581,7 @@ def check_content(post_bottom):
css_anchor = anchor.rsplit(':')[0]
tag = '%s %s'%(tyto.single_tags[1][0], css_anchor)
if not tag in post_bottom:
tyto.exiting("6", 'anchor, %s'%tag, False)
logs.out("6", 'anchor, %s'%tag, False)
post_err = True
@ -598,9 +598,10 @@ def check_content(post_bottom):
if not inlist: continue
if not line[0] in tyto.markers_lists:
tyto.exiting("3", 'line %s must start with %s'%(
logs.out("3", 'line %s must start with %s'%(
ln, markers_lists
), False)
), False
)
post_err = True
@ -621,7 +622,7 @@ def check_content(post_bottom):
set_tags = (ptag_set)
if match: continue
else: tyto.exiting("10", "%s %s"%(htag, ptag_set), True)
else: logs.out("12", "%s %s"%(htag, ptag_set), True)
# Template Tags (warning for not paired symbols)
@ -631,7 +632,7 @@ def check_content(post_bottom):
tpl2 = article_bottom.count(tag[1])
if tpl1 != tpl2:
tyto.exiting("22", '"%s", "%s"'%(tag[0], tag[1]), False)
logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False)
@ -639,18 +640,17 @@ def check_content(post_bottom):
# Create new article's database at each check ! #
#-----------------------------------------------#
def create_database():
# No first / from dir post
web_uri = tyto.web_uri[1: len(tyto.web_uri)]
# No need index.html for web link
if tyto.web_uri.endswith('index.html'): tyto.web_uri = '/'
database = '# Post Configuration for Tyto\n' + \
'post_id = "%s"\n'%tyto.uri_id + \
'root_uri = "%s"\n'%tyto.uri_root + \
'wip_uri = "%s%s"\n'%(srv_wip, web_uri) + \
'www_uri = "%s%s"\n'%(srv_www, web_uri) + \
'http_uri = "%s"\n'%tyto.web_uri + \
'sub_uri = "%s"\n'%sub_uri + \
'post_src = "%s"\n'%tyto.uti_file + \
'post_wip = "%s"\n'%tyto.srv_post_wip_uri + \
'post_www = "%s"\n'%tyto.srv_post_www_uri + \
'\n' + \
'short_src = "%s"\n'%tyto.src_post_short_uri + \
'short_srv = "%s"\n'%tyto.srv_post_short_uri + \
'sub_uri = "%s"\n'%tyto.sub_uri + \
'http_wip = "%s"\n'%tyto.http_wip + \
'http_www = "%s"\n'%tyto.http_www + \
'\n' + \
'date_chk = "%s"\n'%tyto.nowdate() + \
'hash_chk = "%s"\n'%tyto.hash_post + \
@ -665,6 +665,8 @@ def create_database():
'tags = "%s"\n'%tags + \
'date = %s\n'%str(date) + \
'snpic = "%s"\n'%snpic_url + \
'\n# Used files\n' + \
'uris = (%s)\n'%files_post + \
'\n# Post configuration from optional tags'
if stat_abbrs > 0:
@ -698,31 +700,31 @@ def create_database():
)
db_stats = '\n# Statistics from optional tags\n' + \
'uniq_anchors = %s\n'%(int(stat_ancs)) + \
'uniq_abbrs = %s\n'%(int(stat_abbrs)) + \
'uniq_links = %s\n'%(int(stat_links)) + \
'uniq_images = %s\n'%(int(stat_images)) + \
'uniq_files = %s\n'%(int(stat_files)) + \
'uniq_raws = %s\n'%(int(stat_raws)) + \
'uniq_anchors = %d\n'%stat_ancs + \
'uniq_abbrs = %d\n'%stat_abbrs + \
'uniq_links = %d\n'%stat_links + \
'uniq_images = %d\n'%stat_images + \
'uniq_files = %d\n'%stat_files + \
'uniq_raws = %d\n'%stat_raws + \
'\n# Statistics from post content\n' + \
'stat_tags = %s\n'%(int(post_tags)) + \
'stat_words = %s\n'%(int(post_words)) + \
'stat_titles = %s\n'%(int(tyto.nbr_titles)) + \
'stat_paragraphs = %s\n'%(int(post_paragraphs)) + \
'stat_anchors = %s\n'%(int(post_anchors)) + \
'stat_strongs = %s\n'%(int(post_strongs)) + \
'stat_bolds = %s\n'%(int(post_bolds)) + \
'stat_emphasis = %s\n'%(int(post_emphasis)) + \
'stat_italics = %s\n'%(int(post_italics)) + \
'stat_dels = %s\n'%(int(post_dels)) + \
'stat_underlines = %s\n'%(int(post_underlines)) + \
'stat_cites = %s\n'%(int(post_cites)) + \
'stat_customs = %s\n'%(int(post_customs)) + \
'stat_icodes = %s\n'%(int(tyto.nbr_icodes)) + \
'stat_bcodes = %s\n'%(int(tyto.nbr_bcodes)) + \
'stat_quotes = %s\n'%(int(tyto.nbr_quotes)) + \
'stat_lists = %s\n'%(int(post_lists))
'stat_tags = %d\n'%post_tags + \
'stat_words = %d\n'%post_words + \
'stat_titles = %d\n'%tyto.nbr_titles + \
'stat_paragraphs = %d\n'%post_paragraphs + \
'stat_anchors = %d\n'%post_anchors + \
'stat_strongs = %d\n'%post_strongs + \
'stat_bolds = %d\n'%post_bolds + \
'stat_emphasis = %d\n'%post_emphasis + \
'stat_italics = %d\n'%post_italics + \
'stat_dels = %d\n'%post_dels + \
'stat_underlines = %d\n'%post_underlines + \
'stat_cites = %d\n'%post_cites + \
'stat_customs = %d\n'%post_customs + \
'stat_icodes = %d\n'%tyto.nbr_icodes + \
'stat_bcodes = %d\n'%tyto.nbr_bcodes + \
'stat_quotes = %d\n'%tyto.nbr_quotes + \
'stat_lists = %d\n'%post_lists
database = '%s\n%s'%(database, db_stats)
tyto.set_file(tyto.post_db, 'new', database)
tyto.exiting("21", '', True)
logs.out("21", '', True)

View File

@ -0,0 +1,139 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: DBs tools
# Description: Search DBs and exec
# file: db.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 os, sys
import args, logs
# Settings
#---------
domain_active = False
home_dir = os.path.expanduser('~')
try:
in_dir = os.getcwd()
except:
logs.out("13", '', False)
domain_conf = in_dir
incomplete_domain = False
# Settings for domain, check if db is not corrupted
domain_values = (
'domain_dir',
'domain_conf',
'domain_articles',
'domain_files',
'domain_images',
'domain_db',
'html_db',
'navbars_dir',
'navbar_load',
'navbar_load_db',
'sidebar_load',
'sidebar_load_db',
'metas_load',
'metas_load_db',
'footer_load',
'footer_load_db',
'domain_short',
'domain_www_url',
'domain_wip_url',
'domain_title',
'domain_about',
'domain_lang',
'domain_mail',
'domain_tags',
'domain_logo',
'domain_license',
'domain_licurl',
'domain_css',
'domain_sep',
'domain_relme',
'sidebar_title',
'sidebar_items',
'srv_root',
'srv_domain',
'srv_wip',
'srv_wip_tpl',
'srv_wip_images',
'srv_wip_files',
'srv_www',
'srv_www_tpl',
'srv_www_images',
'srv_www_files',
'wip_navbar',
'wip_sidebar',
'wip_metas',
'wip_footer',
'www_navbar',
'www_sidebar',
'www_metas',
'www_footer',
'domain_active',
)
# If error in DB, continue process for these options
domain_pass_args = ('New', 'Edit', 'Show', '')
# Search and set domain conf file
# from current directory or from argument
#----------------------------------------
if '/articles' in in_dir:
domain_conf = in_dir.rsplit('/articles')[0]
else:
try:
args.target
if 'articles/' in args.arguments:
domain_conf = in_dir.rsplit('articles/')[0]
except:
domain_conf = in_dir
conf_dir = domain_conf + "/"
domain_conf = '%s/tyto_domain.conf'%domain_conf
if os.path.exists(domain_conf): domain_exists = True
else: domain_exists = False
# Check if domain is set
#-----------------------
stdout = '%s %s domain "%s" in %s' # Show domain status
if domain_exists:
exec(open(domain_conf).read())
for conf in domain_values:
try:
eval(str(conf))
except:
incomplete_domain = True
logs.out('10', conf, False)
# Stop process if error, continue if '-n'
if not args.option in domain_pass_args:
if incomplete_domain:
sys.exit(1)
try: domain_active
except: domain_active = False
if incomplete_domain: logs.out("41", domain_short, False)
elif domain_active: logs.out("42", domain_short, False)
else: logs.out("40", domain_short, False)
else:
logs.out("43", domain_conf, False)

View File

@ -17,33 +17,38 @@
#**********************************************************************
import os, locale
import tyto, html
import os, sys, locale
import logs, db, tyto, html
#==========================#
# Manage Argument 'domain' #
#--------------------------#
def manage_domain(target, option):
if option == 'Edit':
if tyto.domain_exists:
print(":D Edit domain configuration file:", tyto.domain_conf)
tyto.edit_file(tyto.domain_conf)
if db.domain_exists:
print(":D Edit domain configuration file:", db.domain_conf)
tyto.edit_file(db.domain_conf)
else:
sys.exit(1)
elif option == 'New':
if not tyto.domain_exists:
if not db.domain_exists:
create_domain(target, option)
else:
print(':) A domain exists in this directory')
ask = input('-> Edit it with the form ? ')
if not db.incomplete_domain:
ask = input(' ├ Edit the domain configuration with the form ? ')
if ask in ['y', 'Y']: create_domain(target, option)
else: tyto.exiting("255", '', True)
else: logs.out("255", '', True)
else:
create_domain(target, option)
elif option == 'DB' or option == 'Show':
if tyto.domain_exists:
domain_db = open(tyto.domain_conf).read()
elif option == 'Show':
if db.domain_exists:
domain_db = open(db.domain_conf).read()
for line in domain_db.rsplit('\n'):
print(line)
else:
sys.exit(1)
#=====================#
@ -51,10 +56,9 @@ def manage_domain(target, option):
#---------------------#
def isurl(target):
global url
if target.startswith('http'):
url = target
else:
tyto.exiting("2", target, True)
if target.startswith('http'): url = target
else: logs.out("2", target, True)
#=====================#
# Create a new domain #
@ -75,322 +79,330 @@ def create_domain(target, option):
# Get complete URL from target or ask
#------------------------------------
try: domain_url = tyto.domain_url
except: domain_url = ''
try:
domain_www_url = db.domain_www_url
except:
if target: domain_www_url = target
else: domain_www_url = ''
valid_url = ('http://', 'https://')
ask = ''
ask = input(' ├ [HTTP...] URL to website ? ("%s") '%domain_url)
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url)
if ask:
if not ask.startswith(valid_url):
logs.out("2", 'http(s)://...', True)
isurl(ask)
domain_url = url
elif not domain_url:
tyto.exiting("255", '', True)
domain_www_url = url
elif not domain_www_url:
logs.out("255", '', True)
domain_short = domain_www_url.rsplit('://')[1]
domain_short = domain_url.rsplit('://')[1]
# Prefix wip
#-----------
try:
try_wipurl = target.rsplit('.')
try_wipurl = 'https://www-wip.%s.%s'%(try_wipurl[1], try_wipurl[2])
try_wip_url = target.rsplit('.')
try_wip_url = 'https://www-wip.%s.%s'%(
try_wip_url[1], try_wip_url[2]
)
except:
try_wipurl = 'https://www-wip.%s'%target
try_wip_url = 'https://www-wip.%s'%domain_short
try: domain_wipurl = tyto.domain_wipurl
except: domain_wipurl = try_wipurl
try: domain_wip_url = db.domain_wip_url
except: domain_wip_url = try_wip_url
ask = ''
ask = input(' ├ URL to wip ? ("%s") '%domain_wipurl)
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url)
if ask:
isurl(ask)
domain_wipurl = ask
domain_wip_url = ask
db_dir = '%s/.local/tyto/%s/'%(tyto.home_dir, domain_short)
navbars_conf= '%sarticles/_configs/'%tyto.conf_dir
conf_domain = 'domain_dir = "%s"\n'%tyto.conf_dir + \
'domain_conf = "%s"\n'%tyto.domain_conf + \
'domain_articles = "%sarticles/"\n'%tyto.conf_dir + \
'domain_files = "%sarticles/files/"\n'%tyto.conf_dir + \
'domain_images = "%sarticles/images/"\n'%tyto.conf_dir + \
'domain_db = "%sarticles/"\n'%(db_dir) + \
'html_db = "%shtml/"\n'%(db_dir) + \
global navbars_conf
db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short)
db_dir_html = '%shtml/'%db_dir
navbars_conf = '%sarticles/_configs/'%db.conf_dir
conf_domain = \
'domain_dir = "%s"\n'%db.conf_dir + \
'domain_conf = "%s"\n'%db.domain_conf + \
'domain_articles = "%sarticles/"\n'%db.conf_dir + \
'domain_files = "%sarticles/files/"\n'%db.conf_dir + \
'domain_images = "%sarticles/images/"\n'%db.conf_dir + \
'domain_db = "%sarticles/"\n'%db_dir + \
'html_db = "%s"\n'%db_dir_html + \
'navbars_dir = "%s"\n'%navbars_conf + \
'navbar_load = "%styto.navbar"\n'%navbars_conf + \
'navbar_load_db = "%snavbar_load.conf"\n'%db_dir_html + \
'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \
'sidebar_load_db = "%ssidebar_load.conf"\n'%db_dir_html + \
'metas_load = "%styto.metas.html"\n'%navbars_conf + \
'metas_load_db = "%smetas_load.conf"\n'%db_dir_html + \
'footer_load = "%styto.footer.html"\n'%navbars_conf + \
'footer_load_db = "%sfooter_load.conf"\n'%db_dir_html + \
'\ndomain_short = "%s"\n'%domain_short + \
'domain_url = "%s"\n'%domain_url + \
'domain_wipurl = "%s"\n'%domain_wipurl
'domain_www_url = "%s"\n'%domain_www_url + \
'domain_wip_url = "%s"\n'%domain_wip_url
tyto.set_file(tyto.domain_conf, True, conf_domain)
tyto.set_file(db.domain_conf, True, conf_domain)
# Get srv root
#-------------
try: domain_srv = db.domain_srv
except: domain_srv = '/var/www'
ask = ''
ask = input(' ├ System server ? ("%s") '%domain_srv)
if ask:
if not os.path.exists(srv): logs.out("1", ask, True)
elif not domain_srv: logs.out("255", '', True)
root_srv_dom = '%s/%s'%(domain_srv, domain_short)
srv_wip_tpl = "%s/wip/template/"%root_srv_dom
srv_www_tpl = "%s/www/template/"%root_srv_dom
srvs = '# Servers directories\n' + \
'srv_root = "%s/"\n'%domain_srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \
'srv_wip_tpl = "%s"\n'%srv_wip_tpl + \
'srv_wip_images = "%s/wip/images/"\n'%root_srv_dom + \
'srv_wip_files = "%s/wip/files/"\n'%root_srv_dom + \
'srv_www = "%s/www/"\n'%root_srv_dom + \
'srv_www_tpl = "%s"\n'%srv_www_tpl + \
'srv_www_images = "%s/www/images/"\n'%root_srv_dom + \
'srv_www_files = "%s/www/files/"\n'%root_srv_dom + \
'\n' + \
'# Servers files\n' + \
'wip_navbar = "%snavbar.html"\n'%srv_wip_tpl + \
'wip_sidebar = "%ssidebar.html"\n'%srv_wip_tpl + \
'wip_metas = "%smetas.html"\n'%srv_wip_tpl + \
'wip_footer = "%sfooter.html"\n'%srv_wip_tpl + \
'www_navbar = "%snavbar.html"\n'%srv_www_tpl + \
'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas = "%smetas.html"\n'%srv_www_tpl + \
'www_footer = "%sfooter.html"\n'%srv_www_tpl
tyto.set_file(db.domain_conf, False, srvs)
# Get title domain
#-----------------
try: domain_title = tyto.domain_title
try: domain_title = db.domain_title
except: domain_title = ''
ask = ''
ask = input(' ├ Domain title ? ("%s") '%domain_title)
if ask: domain_title = ask
elif not domain_title: tyto.exit("255")
elif not domain_title: logs.out("255", '', True)
if '"' in domain_title:
domain_title = domain_title.replace('"', '')
tyto.set_file(tyto.domain_conf, False,
'domain_title = "%s"'%domain_title)
tyto.set_file(db.domain_conf, False,
'# Domain user\'s settings\n' + \
'domain_title = "%s"'%domain_title
)
# Get Description domain
#-----------------------
try: domain_about = tyto.domain_about
try: domain_about = db.domain_about
except: domain_about = ''
ask = ''
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
if ask: domain_about = ask
elif not domain_about: tyto.exit("255")
elif not domain_about: logs.out("255", '', True)
if '"' in domain_about:
domain_about = domain_about.replace('"', '')
tyto.set_file(tyto.domain_conf, False,
'domain_about = "%s"'%domain_about)
tyto.set_file(db.domain_conf, False,
'domain_about = "%s"'%domain_about
)
# Get Lang domain
#----------------
try: domain_lang = tyto.domain_lang
try: domain_lang = db.domain_lang
except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
ask = ''
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
if ask:
if len(ask) == 2: domain_lang = ask
else: tyto.exiting("3", ask, True)
elif not domain_lang: tyto.exiting("255", '', True)
else: logs.out("3", ask, True)
elif not domain_lang: logs.out("255", '', True)
tyto.set_file(tyto.domain_conf, False,
'domain_lang = "%s"'%domain_lang)
tyto.set_file(db.domain_conf, False,
'domain_lang = "%s"'%domain_lang
)
# Get mail domain
#----------------
try: domain_mail = tyto.domain_mail
try: domain_mail = db.domain_mail
except: domain_mail = ''
ask = ''
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
if ask:
if not "@" in ask and not "." in ask: tyto.exiting("3", ask, True)
if not "@" in ask and not "." in ask: logs.out("3", ask, True)
domain_mail = ask
elif not domain_mail: tyto.exiting("255", '', True)
elif not domain_mail: logs.out("255", '', True)
tyto.set_file(tyto.domain_conf, False,
'domain_mail = "%s"'%domain_mail)
tyto.set_file(db.domain_conf, False,
'domain_mail = "%s"'%domain_mail
)
# Get Tags domain
#----------------
try: domain_tags = tyto.domain_tags
try: domain_tags = db.domain_tags
except: domain_tags = ''
ask = ''
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
if ask: domain_tags = ask
elif not domain_tags: tyto.exiting("255", '', True)
elif not domain_tags: logs.out("255", '', True)
tyto.set_file(tyto.domain_conf, False,
'domain_tags = "%s"'%domain_tags)
tyto.set_file(db.domain_conf, False,
'domain_tags = "%s"'%domain_tags
)
# Get logo's website
#-------------------
try: domain_logo = tyto.domain_logo
try: domain_logo = db.domain_logo
except: domain_logo = 'logo.png'
ask = ''
ask = input(' ├ logo filename ? ("%s") '%domain_logo)
tyto.set_file(tyto.domain_conf, False,
'domain_logo = "%s"'%domain_logo)
if ask: domain_logo = ask
tyto.set_file(db.domain_conf, False,
'domain_logo = "%s"\n'%domain_logo + \
'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \
'www_logo = "%s%s"\n'%(srv_www_tpl, domain_logo)
)
# Get License domain
#-------------------
try: domain_license = tyto.domain_license
try: domain_license = db.domain_license
except: domain_license = 'CC BY-NC-SA'
ask = ''
ask = input(' ├ Domain License ? ("%s") '%domain_license)
if ask: domain_license = ask
elif not domain_license: tyto.exiting("255", '', True)
elif not domain_license: logs.out("255", '', True)
if '"' in domain_license:
domain_license = domain_license.replace('"', '')
tyto.set_file(tyto.domain_conf, False,
'domain_license = "%s"'%domain_license)
tyto.set_file(db.domain_conf, False,
'domain_license = "%s"'%domain_license
)
# Get License URL (optionnal)
#----------------------------
try: domain_licurl = tyto.domain_licurl
try: domain_licurl = db.domain_licurl
except: domain_licurl = ''
ask = ''
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
if ask:
if not ask.startswith('http'): tyto.exiting("3", ask, True)
if not ask.startswith('http'): logs.out("3", ask, True)
domain_licurl = ask
tyto.set_file(tyto.domain_conf, False,
'domain_licurl = "%s"'%domain_licurl)
tyto.set_file(db.domain_conf, False,
'domain_licurl = "%s"'%domain_licurl
)
# CSS Prefix
#-----------
try: domain_css = tyto.domain_css
try: domain_css = db.domain_css
except: domain_css = 'tyto'
ask = ''
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
if ask:
if not ask.isalnum(): tyto.exiting("3", ask, True)
if not ask.isalnum(): logs.out("3", ask, True)
domain_css = ask.lower()
tyto.set_file(tyto.domain_conf, False,
'domain_css = "%s"'%domain_css)
tyto.set_file(db.domain_conf, False,
'domain_css = "%s"'%domain_css
)
# Titles webpage separator
#-------------------------
try: domain_sep = tyto.domain_sep
try: domain_sep = db.domain_sep
except: domain_sep = "-"
ask = ''
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
if ask:
if not len(ask) == 1: tyto.exiting("3", ask, True)
if not len(ask) == 1: logs.out("3", ask, True)
domain_sep = ask
tyto.set_file(tyto.domain_conf, False,
'domain_sep = "%s"'%domain_sep)
tyto.set_file(db.domain_conf, False,
'domain_sep = "%s"'%domain_sep
)
# Profile for rel="me" (optionnal)
#---------------------------------
try: domain_relme = tyto.domain_relme
try: domain_relme = db.domain_relme
except: domain_relme = ''
ask = ''
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
if ask:
if not ask.startswith('http'): tyto.exiting("3", ask, True)
if not ask.startswith('http'): logs.out("3", ask, True)
domain_relme = ask
tyto.set_file(tyto.domain_conf, False,
'domain_relme = "%s"'%domain_relme)
# Activate menu bar from tyto.navbar ?
#-------------------------------------
try: domain_menubar = tyto.domain_menubar
except: domain_menubar = 'False'
ask = ''
ask = input(' ├ Create menu bar from tyto.navbar file ? (%s) '%(
domain_menubar
tyto.set_file(db.domain_conf, False,
'domain_relme = "%s"'%domain_relme
)
)
if ask in ['y', 'Y']: domain_menubar = 'True'
else: domain_menubar = domain_menubar
tyto.set_file(tyto.domain_conf, False,
'domain_menubar = %s'%(domain_menubar))
# Activate side bar from tyto.sidebar ?
#--------------------------------------
try: domain_sidebar = tyto.domain_sidebar
except: domain_sidebar = 'False'
ask = ''
ask = input(' ├ Create article\'s list from tyto.sidebar file ? (%s) '%(
domain_sidebar
)
)
if ask in ['y', 'Y']: domain_sidebar = 'True'
else: domain_sidebar = domain_sidebar
tyto.set_file(tyto.domain_conf, False,
'domain_sidebar = %s'%(domain_sidebar))
# Sidebar Title
#--------------
try: sidebar_title = tyto.sidebar_title
try: sidebar_title = db.sidebar_title
except: sidebar_title = tyto.trans[0][tyto.n]
if domain_sidebar:
ask = ''
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
if ask: sidebar_title = ask
if '"' in sidebar_title:
sidebar_title = sidebar_title.replace('"', '')
tyto.set_file(tyto.domain_conf, False,
'sidebar_title = "%s"'%(sidebar_title))
tyto.set_file(db.domain_conf, False,
'sidebar_title = "%s"'%(sidebar_title)
)
# Sidebar Items
#--------------
try: sidebar_items = tyto.sidebar_items
try: sidebar_items = db.sidebar_items
except: sidebar_items = "6"
if domain_sidebar:
ask = ''
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items)
if ask:
if not ask.isdigit(): tyto.exiting("3", ask, True)
if not ask.isdigit(): logs.out("3", ask, True)
elif int(ask) in range(1,17): sidebar_items = int(ask)
tyto.set_file(tyto.domain_conf, False,
'sidebar_items = %s'%(sidebar_items))
# Get srv root
#-------------
try: domain_srv = tyto.domain_srv
except: domain_srv = '/var/www'
ask = ''
ask = input(' ├ System server ? ("%s") '%domain_srv)
if ask:
if not os.path.exists(srv): tyto.exiting("1", ask, True)
elif not domain_srv: tyto.exiting("255", '', True)
root_srv_dom = '%s/%s'%(domain_srv, domain_short)
srvs = '\nsrv_root = "%s/"\n'%domain_srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \
'srv_wip_tpl = "%s/wip/template/"\n'%root_srv_dom + \
'srv_wip_images = "%s/wip/images/"\n'%root_srv_dom + \
'srv_wip_files = "%s/wip/files/"\n'%root_srv_dom + \
'srv_www = "%s/www/"\n'%root_srv_dom + \
'srv_www_tpl = "%s/www/template/"\n'%root_srv_dom + \
'srv_www_images = "%s/www/images/"\n'%root_srv_dom + \
'srv_www_files = "%s/www/files/"'%root_srv_dom
tyto.set_file(tyto.domain_conf, False, srvs)
tyto.set_file(db.domain_conf, False,
'sidebar_items = %s'%(sidebar_items)
)
# Activate Domain after Resumed configuration ?
#----------------------------------------------
try: domain_active = tyto.domain_active
try: domain_active = db.domain_active
except: domain_active = False
file = open(tyto.domain_conf, 'r').read()
file = open(db.domain_conf, 'r').read()
resume = '\n' + \
' ├──────────────────────────────────────┐\n' + \
' │ Please, READ the configuration datas │\n' + \
@ -403,16 +415,15 @@ def create_domain(target, option):
ask = input(' ├ Activate and prepare domain ? ')
if not ask in ['y', 'Y']:
tyto.set_file(tyto.domain_conf, False,
'\ndomain_active = False')
tyto.exiting("255", '', True)
tyto.set_file(db.domain_conf, False, '\ndomain_active = False')
logs.out("255", '', True)
# Activate Domain
#----------------
tyto.set_file(tyto.domain_conf, False, '\ndomain_active = True')
tyto.set_file(db.domain_conf, False, '\ndomain_active = True')
# Load config
exec(open(tyto.domain_conf).read(),globals())
exec(open(db.domain_conf).read(),globals())
# Create folders from configuration file
folders = (
@ -448,12 +459,45 @@ def create_domain(target, option):
# sidebar load file translated #
#------------------------------#
def create_sidebar(option):
sidebar_load = tyto.sidebar_load
if not db.domain_active: return
# Create an empty html file if not exists
if not os.path.exists(db.wip_sidebar):
tyto.set_file(db.wip_sidebar, 'new', '')
print(' ├ Create file: %s'%db.wip_sidebar)
create_load = False # file in _configs
create_html = False # file in template/
# Get metas_load hash or create metas db file if not exists
#----------------------------------------------------------
if os.path.exists(db.sidebar_load):
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
# Manage option
#--------------
if not os.path.exists(db.sidebar_load):
create_load = True
elif option == 'New':
create_load = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.sidebar_load, True)
tyto.edit_file(db.sidebar_load)
hash_load_new = tyto.get_filesum(db.sidebar_load, True)
if not hash_load_old == hash_load_new:
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
create_html = True
elif option == 'Force':
create_load = True
# French sidebar_load content
sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \
'# Type : fichier texte\n' + \
'# Description : Fichier appelé par "tyto sidebar"\n' + \
'# (Liste d\'articles)\n' + \
'# Fichier : %s\n'%sidebar_load + \
'# Fichier : %s\n'%db.sidebar_load + \
'# Comment : 1 URI de l\'article par ligne\n' + \
'# (depuis articles/)\n' + \
'# Ne commence pas par "/"\n' + \
@ -464,11 +508,12 @@ def create_sidebar(option):
'# dir1/index.tyto\n' + \
'# %s\n\n'%(15 * "-")
# English sidebar_load content
sdb_load_en = '# For: Tyto - Littérateur\n' + \
'# Type: Text file\n' + \
'# Description: file called with "tyto sidebar"\n' + \
'# (articles\'s list)\n' + \
'# File: %s\n'%sidebar_load + \
'# File: %s\n'%db.sidebar_load + \
'# Comment: 1 article URI per line\n' + \
'# (from articles/)\n' + \
'# not begining with "/"\n' + \
@ -479,31 +524,71 @@ def create_sidebar(option):
'# dir1/index.tyto\n' + \
'# %s\n\n'%(15 * "-")
# Set language file
if tyto.n == 0: sdb_load = sdb_load_fr
elif tyto.n == 1: sdb_load = sdb_load_en
# Create sidebar_load
if create_load:
# Create new file, or ask if exists
ask = ' ├ Use default (empty) _configs/tyto.sidebar file ? '
log = ' ├ Create file: %s'%sidebar_load
if os.path.exists(sidebar_load):
ask = ' ├ Use default (empty) sidebar configuration ? '
log = ' ├ Create file: %s'%db.sidebar_load
res = ''
if os.path.exists(db.sidebar_load):
res = input(ask)
if not res in ['y', 'Y']: return
tyto.set_file(sidebar_load, 'new', sdb_load)
tyto.set_file(db.sidebar_load, 'new', sdb_load)
print(log)
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
# Create wip/template/sidebar.html
if create_html:
html.create_sidebar(db.wip_sidebar)
#=============================#
# navbar load file translated #
#-----------------------------#
def create_navbar(option):
navbar_load = tyto.navbar_load
if not db.domain_active: return
# Create an empty html file if not exists
if not os.path.exists(db.wip_navbar):
tyto.set_file(db.wip_navbar, 'new', '')
print(' ├ Create file: %s'%db.wip_navbar)
create_load = False # file in _configs
create_html = False # file in template/
# Get metas_load hash or create metas db file if not exists
#----------------------------------------------------------
if os.path.exists(db.navbar_load):
html.create_db_load(db.navbar_load, db.navbar_load_db)
# Manage option
#--------------
if not os.path.exists(db.navbar_load):
create_load = True
elif option == 'New':
create_load = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.navbar_load, True)
tyto.edit_file(db.navbar_load)
hash_load_new = tyto.get_filesum(db.navbar_load, True)
if not hash_load_old == hash_load_new:
html.create_db_load(db.navbar_load, db.navbar_load_db)
create_html = True
elif option == 'Force':
create_load = True
nav_load_fr = '# Pour : Tyto - Littérateur\n' + \
'# Type : fichier texte\n' + \
'# Description : Fichier utilisé par "tyto wip"\n' + \
'# (Liste des catégories)\n' + \
'# Fichier : %s\n'%navbar_load + \
'# Fichier : %s\n'%db.navbar_load + \
'# Comment : 1 nom de dossier par ligne *1\n' + \
'# (depuis articles/)\n' + \
'# Ne commence pas par "/"\n' + \
@ -524,7 +609,7 @@ def create_navbar(option):
'# Type: Text file\n' + \
'# Description: file used with "tyto wip"\n' + \
'# (categories\'s list)\n' + \
'# File : %s\n'%navbar_load + \
'# File : %s\n'%db.navbar_load + \
'# Comment: 1 folder name per line *1\n' + \
'# (from articles/)\n' + \
'# not begining with "/"\n' + \
@ -541,16 +626,24 @@ def create_navbar(option):
'# about # infos about this website\n' + \
'# %s\n\n'%(15 * "-")
if tyto.n == 0: nav_load = nav_load_fr
elif tyto.n == 1: nav_load = nav_load_en
# Set language file
if tyto.n == 0: nvb_load = nav_load_fr
elif tyto.n == 1: nvb_load = nav_load_en
# Create sidebar_load
if create_load:
# Create new file, or ask if exists
ask = ' ├ Use default (empty) _configs/tyto.navbar file ? '
log = ' ├ Create file: %s'%navbar_load
if os.path.exists(navbar_load):
ask = ' ├ Use default (empty) navbar configuration ? '
log = ' ├ Create file: %s'%db.navbar_load
res = ''
if os.path.exists(db.navbar_load):
res = input(ask)
if not res in ['y', 'Y']: return
tyto.set_file(navbar_load, 'new', nav_load)
tyto.set_file(db.navbar_load, 'new', nvb_load)
print(log)
html.create_db_load(db.navbar_load, db.navbar_load_db)
# Create wip/template/sidebar.html
if create_html:
html.create_navbar(db.wip_navbar)

View File

@ -16,23 +16,9 @@
#----------------------------------------------------------------------
#**********************************************************************
import os, sys
import tyto, domain
# Load domain configuration DB
exec(open(tyto.domain_conf).read())
Tyto = 'Tyto - Littérateur'
Tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur'
Tytogti = 'Dépôt officiel du code source de Tyto - Littérateur'
Tytoweb = 'https://tyto.echolib.re'
Tytowti = 'Site web officiel du logiciel Tyto - Littérateur'
Tytosrc = '(<a href="%s" '%Tytogit + \
'title="%s" '%Tytogti + \
'id="footer_item_link">Code source</a>)'
navbar_file = '%snavbar.html'%srv_wip_tpl
import logs, db, tyto, domain
#==================================#
@ -40,16 +26,17 @@ navbar_file = '%snavbar.html'%srv_wip_tpl
# (sidebar, metas, footer, navbar) #
#----------------------------------#
def manage_configs(target, option):
# Arguments
args1 = ('metas', 'sidebar', 'footer', 'navbar')
args2 = ('-n', '-e', '-F', )
opts = ('New', 'Edit', 'Force')
args2 = ('-n', '-e', '-F', '-c')
opts = ('New', 'Edit', 'Force', 'Create')
# Check arguments (from form domain)
if target in args1: sys.argv[1] = target
elif target and not option: option = target
if not sys.argv[1] in args1: tyto.exiting('11', '%s'%str(args1), True)
if not sys.argv[1] in args1: logs.out('11', '%s'%str(args1), True)
if not option in opts and not option == '-i' and not option in args2:
tyto.exiting('11', '%s'%str(args2), True)
logs.out('11', '%s'%str(args2), True)
actions = {
'sidebar' : domain.create_sidebar,
@ -69,7 +56,7 @@ def set_page(post_db, target, article_bottom):
exec(open(post_db).read(),globals())
create_metas_page() # Include metas tags
create_main_page(target, article_bottom) # At last, create main page
create_main_page(target, article_bottom) # Create main page
#============================================#
@ -82,22 +69,24 @@ def create_metas_page():
#-------------------
metas_page = ''
scale = 'width=device-width, initial-scale=1.0'
all_tags = domain_tags + ',' + tags
post_url = domain_url + http_uri
all_tags = db.domain_tags + ',' + tags
css_file = 'template/style.css'
css_ref = 'media="screen" href="%s%s" />'%(sub_uri, css_file)
css_ref = 'media="screen" href="%s%s"'%(sub_uri, css_file)
rss_file = 'rss.xml'
rss_ref = 'type="application/rss+xml" ' + \
'href="%s%s" title="RSS 2.0. %s %s %s'%(
sub_uri, rss_file, domain_title, domain_sep, domain_short
sub_uri, rss_file,
db.domain_title, db.domain_sep, db.domain_short
)
icon_file = 'favicon.png'
icon_ref = 'type="image/png" href="%stemplate/%s"'%(sub_uri, icon_file)
icon_ref = 'type="image/png" href="%stemplate/%s"'%(
sub_uri, icon_file
)
en_date = tyto.set_en_date(date[0])
relme = '' # External URL in metas (if exists in config domain)
if domain_relme:
if db.domain_relme:
relme = '\n <link rel="me" type="text/html" href="%s">'%(
domain_relme
db.domain_relme
)
# Set all raw HTML metas
@ -106,29 +95,29 @@ def create_metas_page():
metas = \
' <meta charset="UTF-8" />\n' + \
' <meta name="viewport" content="%s" />\n'%scale + \
' <meta name=”url” content=”%s” />\n'%domain_url + \
' <meta name="language" content="%s" />\n'%domain_lang + \
' <meta name="reply-to" content="%s" />\n'%domain_mail + \
' <meta name="copyright" content="%s" />\n'%domain_license + \
' <meta name="generator" content="%s" />\n'%Tyto + \
' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \
' <meta name="language" content="%s" />\n'%db.domain_lang + \
' <meta name="reply-to" content="%s" />\n'%db.domain_mail + \
' <meta name="copyright" content="%s" />\n'%db.domain_license + \
' <meta name="generator" content="%s" />\n'%tyto.Tyto + \
' <meta name="title" content="%s" />\n'%title + \
' <meta name="author" content="%s" />\n'%author + \
' <meta name="description" content="%s" />\n'%about + \
' <meta name="keywords" content="%s" />\n'%all_tags + \
' <meta name="search_date" content="%s" />\n'%en_date + \
' <link rel="canonical" href="%s" />\n'%post_url + \
' <link rel="canonical" href="%s" />\n'%http_www + \
' <link rel="alternate" %s />\n'%(rss_ref) + \
' <link rel="stylesheet" %s /\n'%css_ref + \
' <link rel="shortcut icon" %s />'%icon_ref + \
' <link rel="stylesheet" %s />\n'%css_ref + \
' <link rel="shortcut icon" %s />\n'%icon_ref + \
' <!-- Open Graph data -->\n' + \
' <meta property="og:site_name" content="%s" />\n'%domain_title + \
' <meta property="og:site_name" content="%s" />\n'%db.domain_title + \
' <meta property="og:title" content="%s" />\n'%title + \
' <meta property="og:type" content="article" />\n' + \
' <meta property="og:url" content="%s" />\n'%post_url + \
' <meta property="og:url" content="%s" />\n'%http_www + \
' <meta property="og:description" content="%s" />\n'%about + \
' <meta property="og:image" content="%s" />\n'%snpic + \
'%s'%relme + \
'\n<!--# include virtual="/template/metas.html"-->\n' + \
'<!--# include virtual="/template/metas.html"-->\n' + \
' <title>%s</title>'%title
@ -138,38 +127,33 @@ def create_metas_page():
def create_main_page(target, article_bottom):
global main_page
# Check needed footer.html
footer_file = '%sfooter.html'%srv_wip_tpl
if not os.path.exists(footer_file):
tyto.exiting("1", footer_file, True)
if not os.path.exists(db.wip_footer):
logs.out("1", db.wip_footer, True)
# Check optional metas.html
metas_file = '%smetas.html'%srv_wip_tpl
if not os.path.exists(metas_file):
tyto.exiting("24", '(user metas tags): '%metas_file, True)
# Check for menu bar
create_navbar('-n', navbars_dir)
if not os.path.exists(db.wip_metas):
logs.out("24", '(HTML metas): %s'%db.wip_metas, False)
# Create link for website's logo
#-------------------------------
logo_html = '<a href="/"\n' + \
'%stitle="%s %s logo: %s"\n'%(11 * " ",
tyto.trans[1][tyto.n], domain_sep, domain_title
tyto.trans[1][tyto.n], db.domain_sep, db.domain_title
) + \
'%sid="site_logo_link">\n'%(11 * " ") + \
'%s<img src=""\n'%(10 * " ") + \
'%salt="logo: %s">\n'%(15 * " ", domain_title) + \
'%sid="site_logo_image">\n'%(15 * " ") + \
'%s<img src="%stemplate/%s"\n'%(10 * " ", sub_uri, db.domain_logo) + \
'%salt="logo: %s"\n'%(15 * " ", db.domain_title) + \
'%sid="site_logo_image" />\n'%(15 * " ") + \
'%s</a>'%(8 * " ")
# Create author and date publish section infos
create_html_infos_section('wip')
#-----------------------#
# Create main HTML Page #
#-----------------------#
main_page = \
'<!Doctype html>\n' + \
'<html lang="%s">\n'%domain_lang + \
'<html lang="%s">\n'%db.domain_lang + \
' <head>\n' + \
'%s\n'%metas + \
' </head>\n\n' + \
@ -183,48 +167,215 @@ def create_main_page(target, article_bottom):
' <a href="/"\n' + \
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
' id="site_link">\n' + \
' <h1 id="site_title">%s</h1>\n'%domain_title + \
' <h1 id="site_title">%s</h1>\n'%db.domain_title + \
' </a>\n' + \
' <p id="site_about">%s</p>\n'%domain_about + \
' <p id="site_about">%s</p>\n'%db.domain_about + \
' </div>\n' + \
'<!--# include virtual="/template/navbar.html"-->\n' + \
' </header>\n' + \
'\n' + \
' <article id="article_main">\n' + \
' <section id="article_infos">\n' + \
'%s\n'%html_infos + \
' </section>\n' + \
'%s\n'%article_bottom + \
' </article>\n' + \
'\n' + \
'<!--# include virtual="/template/sidebar.html"-->\n' + \
'<!--# include virtual="/template/footer.html"-->\n' + \
' </body>\n' + \
'</html>'
#============================================#
# Create HTML line for article infos section #
# when wip, and publish #
#--------------------------------------------#
def create_html_infos_section(process):
global html_infos
if process == 'wip':
date_raw = date_wip # <time datetime=
date_pub = date_wip.rsplit(' ')[0]
time_pub = date_wip.rsplit(' ')[1]
elif process == 'publish':
date_raw = date_www # <time datetime=
date_pub = date_www.rsplit(' ')[0]
time_pub = date_www.rsplit(' ')[1]
if tyto.n == 0: # fr
date_new = date_pub.rsplit('-')
date_pub = date_new[2] + '/' + date_new[1] + '/' + date_new[0]
html_infos = '%s<p>'%(8 * ' ') + \
'<span id="article_title" title="%s">Article</span> '%(
title
) + \
'<span title="%s %s">%s</span> '%(
tyto.trans[10][tyto.n], date[0], tyto.trans[7][tyto.n]
) + \
'<span id="article_author">%s</span>. %s '%(
author, tyto.trans[8][tyto.n]
) + \
'<time datetime="%s">'%date_raw + \
'<span id="article_date">%s</span> %s '%(
date_pub, tyto.trans[9][tyto.n]
) + \
'<span id="article_time">%s</span>'%time_pub + \
'</time>' + \
'</p>'
#========================================================#
# Create DB file with hash from [type]_load file content #
#--------------------------------------------------------#
def create_db_load(file_load, file_db):
hash_load = tyto.get_filesum(file_load, True)
if not os.path.exists(file_db):
tyto.set_file(file_db,
'New',
'file_load_hash = "%s"'%hash_load
)
return
global file_load_hash
file_load_hash = ''
exec(open(file_db, 'r').read(), globals())
if not file_load_hash == hash_load:
tyto.set_file(file_db,
'New',
'file_load_hash = "%s"'%hash_load
)
#============================================#
# Create HTML sidebar from file tyto.sidebar #
#--------------------------------------------#
def create_sidebar(target):
if not db.domain_exists: return
# If content in sidebar, go True
sidebar_new = False
sidebar_has = 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_lines = open(db.sidebar_load, 'r').read()
for line in sidebar_lines.rsplit('\n'):
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'%(db.domain_articles, line)
if not os.path.exists(f_uri):
logs.out("24", f_uri, False)
continue
# Get Hash from uri to get db file
hash_uri = tyto.get_filesum(f_uri, False)
db_uri = '%s%s.conf'%(db.domain_db, hash_uri)
if not os.path.exists(db_uri):
logs.out('25', 'No Database', False)
continue
# Load article"s database
exec(open(db_uri).read(),globals())
# Check wip status and if wip article exists
if not hash_wip == hash_chk:
logs.out("30", '%s "%s"'%(line, title), False)
continue
if not os.path.exists(post_wip):
logs.out("24", 'in wip: %s'%post_wip, False)
continue
# Valid article
sidebar_new = True
# Count: no more than max configured items
counter += 1
if counter > db.sidebar_items:
logs.out("31", '(%s): %s "%s"'%(
db.sidebar_items, line, title),
False
)
continue
# Create HTML list for this article
link_title = '%s [@%s]'%(about, author)
sidebar_list = sidebar_list + \
' <li class="sidebar_item">\n' + \
' <a class="sidebar_item_link"\n' + \
' href="%s">\n' + \
' title="%s">\n'%(link_title) + \
' <h2 class="sidebar_item_title">%s</h2>\n'%title + \
' <p class="sidebar_item_about">%s [%s] - %s</p>\n'%(
date[0], author, about) + \
' </a>\n' + \
' </li>\n'
if not sidebar_new:
# Empty file
if not sidebar_has:
logs.out('29', '(sidebar): %s'%db.sidebar_load, True)
# Some items, but no one is valid
else:
logs.out('28', '(sidebar)', True)
# 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 ? '%db.wip_sidebar
res = ''
if os.path.exists(db.wip_sidebar):
res = input(ask_html)
if not res in ['y', 'Y']: return
tyto.set_file(target, "w", sidebar_content)
logs.out("33", target, False)
#====================================#
# Create HTML menu from root folders #
#------------------------------------#
def create_navbar(option, target):
# Conditions to create navbar
if not domain_menubar:
tyto.exiting("26", 'domain_menubar', False)
if os.path.exists(navbar_file) and os.stat(navbar_file).st_size > 1:
tyto.set_file(navbar_file, 'new', '')
tyto.exiting('27', 'contents (navbar): %s'%navbar_file, False)
return
def create_navbar(target):
if not db.domain_exists: return
# True in config
# Create folder links (from navbars/tyto.navbar)
try: nav_file = open(navbar_load, 'r').read()
except: tyto.exiting("1", '(navbar) %s'%navbar_load, True)
# If content in sidebar, go True
navbar_new = False
navbar_has = False
# Open HTML tags
empty = True
menu_html = '%s<nav id="site_menu">\n'%(6 * ' ') + \
'%s<ul id="site_menu_items">'%(8 * ' ')
nolines = ('#', '/')
for line in nav_file.rsplit('\n'):
navbar_lines = open(db.navbar_load, 'r').read()
for line in navbar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue
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())
@ -232,13 +383,32 @@ def create_navbar(option, target):
direc = line
title = ''
dir_uri = os.path.join(domain_articles, direc)
# Check if dir exists in articles/
dir_uri = os.path.join(db.domain_articles, direc)
if not os.path.isdir(dir_uri):
tyto.exiting("28", dir_uri, False)
logs.out("24", '%s/'%dir_uri, False)
continue
# Check if an index.[ext] and index.html exist and log
index_src = False
index_wip = False
for f in os.listdir(dir_uri):
if f.startswith("index."):
index_src = True
wip_index = '%s%s/index.html'%(db.srv_wip, direc)
if not os.path.exists(wip_index):
logs.out('26', 'in "%s": %s'%(direc, wip_index), False)
else:
index_wip = True
break
if not index_src:
logs.out("26", 'in "%s": %s'%(direc, dir_uri), False)
continue
if not index_wip:
continue
# Add link to HTML structure
empty = False
navbar_new = True
menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
'%s<a class="site_menu_link"\n'%(12 * ' ') + \
'%s'%title + \
@ -251,18 +421,63 @@ def create_navbar(option, target):
# Close HTML tags
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
if empty:
tyto.exiting("29", '(navbar): %s'%navbar_load, False)
tyto.set_file(navbar_file, 'new', '')
if not navbar_new:
if not navbar_has:
logs.out('29', '(navbar): %s'%db.navbar_load, True)
else:
tyto.set_file(navbar_file, 'new', menu_html)
log_html = ' ├ Create file: %s'%navbar_file
print(log_html)
logs.out('28', '(navbar)', True)
#========================================#
# Create metas.html from tyto.metas.html #
#----------------------------------------#
# Create file if sidebar has content
if navbar_new:
ask_html = ' ├ Replace %s ? '%db.wip_navbar
res = ''
if os.path.exists(db.wip_navbar):
res = input(ask_html)
if not res in ['y', 'Y']: return
tyto.set_file(navbar_file, 'new', menu_html)
print(' ├ Create file: %s'%navbar_file)
#========================================================#
# 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):
if not db.domain_exists: return
create_load = False # file in _configs
create_html = False # file in template/
# Get metas_load hash or create metas db file if not exists
#----------------------------------------------------------
if os.path.exists(db.metas_load):
create_db_load(db.metas_load, db.metas_load_db)
# Manage option
#--------------
if not os.path.exists(db.metas_load):
create_load = True
elif option == 'New':
create_load = True
create_html = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.metas_load, True)
tyto.edit_file(db.metas_load)
hash_load_new = tyto.get_filesum(db.metas_load, True)
if not hash_load_old == hash_load_new:
create_db_load(db.metas_load, db.metas_load_db)
create_html = True
elif option == 'Force':
create_load = True
create_html = True
# Set metas_load default content
#-------------------------------
metas_tags = \
'<!-- Custom HTML metas for all pages\n' + \
'# You can add/edit HTML tags\n' + \
@ -300,52 +515,43 @@ def create_user_metas(option):
'<meta name="medium" content="website">\n' + \
'<meta name="revisit-after" content="3 days">'
# Create new file, or ask if exists
ask_load = ' ├ Use default _configs/tyto.metas.html ? '
log_load = ' ├ Create file: %s'%metas_load
create_load = True
# Create metas_load file according to option
#-------------------------------------------
if create_load:
ask_load = ' ├ Use default HTML metas configuration ? '
log_load = ' ├ Create file: %s'%db.metas_load
res = ''
if os.path.exists(db.metas_load):
res = input(ask_load)
if not res in ['y', 'Y']: return
metas_html = '%smetas.html'%srv_wip_tpl
ask_html = ' ├ Replace template/metas.html ' + \
'from _configs/tyto.metas.html ? '
log_html = ' ├ Create file: %s'%metas_html
tyto.set_file(db.metas_load, 'new', metas_tags)
create_html = True
create_db_load(db.metas_load, db.metas_load_db)
print(log_load)
# Create wip metas.html file according to option
#-----------------------------------------------
if create_html:
ask_html = ' ├ Replace %s ? '%db.wip_metas
log_html = ' ├ Create file: %s'%db.wip_metas
user_metas = ''
metas_used = ('<meta ', '<link ')
# Auto create if not tyto.metas.html in _configs
# Pass if exists, user not wants, option is 'New' (only footer.html)
res = ''
if os.path.exists(metas_load):
if option == 'New':
create_load = False
else:
res = input(ask_load)
if not res in ['y', 'Y']: create_load = False
if create_load:
tyto.set_file(metas_load, 'new', metas_tags)
print(log_load)
# Auto create if not metas.html in template/
# Create if option is 'New'
res = ''
if os.path.exists(metas_html):
if option == 'New':
create_html = True
else:
if os.path.exists(db.wip_metas):
res = input(ask_html)
if not res in ['y', 'Y']: create_html = False
if not res in ['y', 'Y']: return
if create_html:
user_file = open(metas_load, 'r').read()
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(metas_html, 'new', user_metas)
tyto.set_file(db.wip_metas, 'new', user_metas)
print(log_html)
@ -353,93 +559,106 @@ def create_user_metas(option):
# Create generic footer from domain datas #
#-----------------------------------------#
def create_user_footer(option):
try:
tyto.domain_licurl
domain_licurl = tyto.domain_licurl
except:
domain_licurl = "/"
if not db.domain_exists: return
create_load = False # file in _configs
create_html = False # file in template/
# Get sidebar_load hash or create sidebar db file if not exists
#--------------------------------------------------------------
if os.path.exists(db.footer_load):
create_db_load(db.footer_load, db.footer_load_db)
# Manage option
#--------------
if not os.path.exists(db.footer_load):
create_load = True
elif option == 'Force':
create_load = True
create_html = True
elif option == 'Create':
create_html = True
elif option == 'Edit':
hash_load_old = tyto.get_filesum(db.footer_load, True)
tyto.edit_file(db.footer_load)
hash_load_new = tyto.get_filesum(db.footer_load, True)
if not hash_load_old == hash_load_new:
create_db_load(db.footer_load, db.footer_load_db)
create_html = True
# Default footer contents
Tytosrc = '(<a href="%s" '%tyto.Tytogit + \
'title="%s" '%tyto.trans[4][tyto.n] + \
'id="footer_item_link">%s</a>)'%tyto.trans[3][tyto.n]
footer = \
'<!-- Default <footer> generated by %s -->\n'%Tyto + \
'<!-- Default <footer> generated by %s -->\n'%tyto.Tyto + \
'<footer id="footer_page">\n' + \
' <div id="footer_infos">\n' + \
' <a href="/"\n' + \
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
' id="footer_title_link">\n' + \
' <h1 id="footer_site_title">%s</h1>\n'%(domain_title) + \
' <h1 id="footer_site_title">%s</h1>\n'%(db.domain_title) + \
' </a>\n' + \
' <p id="footer_site_about">%s</p>\n'%(domain_about) + \
' <p id="footer_site_about">%s</p>\n'%(db.domain_about) + \
' </div>\n' + \
'\n' + \
' <div id="footer_references">\n' + \
' <ul> id="footer_items"\n' + \
' <li id="fotter_item">\n' + \
' <a href="%s"\n'%domain_licurl + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%db.domain_licurl + \
' title="%s %s %s"\n'%(
tyto.trans[2][tyto.n],
domain_sep, domain_title) + \
db.domain_sep, db.domain_title) + \
' id="footer_item_link">%s</a>\n'%(
domain_license) + \
db.domain_license) + \
' </li>\n' + \
' <li id="fotter_item">\n' + \
' <a href="%s"\n'%Tytoweb + \
' title="%s"\n'%Tytowti + \
' id="footer_item_link">%s</a> %s\n'%(Tyto, Tytosrc) + \
' <li id="footer_item">\n' + \
' <a href="%s"\n'%tyto.Tytoweb + \
' title="%s"\n'%tyto.trans[5][tyto.n] + \
' id="footer_item_link">%s</a> %s\n'%(tyto.Tyto, Tytosrc) + \
' </li>\n' + \
' </ul>\n' + \
' </div>\n' + \
'</footer>'
# Create new file, or ask if exists
ask_load = ' ├ Use default _configs/tyto.footer.html ? '
log_load = ' ├ Create file: %s'%footer_load
create_load = True
footer_html = '%sfooter.html'%srv_wip_tpl
ask_html = ' ├ Replace template/footer.html ' + \
'from _configs/tyto.footer.html ? '
log_html = ' ├ Create file: %s'%footer_html
create_html = True
user_footer = ''
# Auto create if not tyto.footer.html in _configs
# Pass if exists, user not wants, option is 'New' (only footer.html)
res = ''
if os.path.exists(footer_load):
if option == 'New':
create_load = False
else:
res = input(ask_load)
if not res in ['y', 'Y']: create_load = False
# Create new default footer_load, or ask if exists
#-------------------------------------------------
if create_load:
tyto.set_file(footer_load, 'new', footer)
ask_load = ' ├ Replace default footer configuration ? '
log_load = ' ├ Create file: %s'%db.footer_load
res = ''
if os.path.exists(db.footer_load):
res = input(ask_load)
if not res in ['y', 'Y']: return
create_html = True
tyto.set_file(db.footer_load, 'new', footer)
create_db_load(db.footer_load, db.footer_load_db)
print(log_load)
# Auto create if not footer.html in template/
# Create if option is 'New'
res = ''
if os.path.exists(footer_html):
if option == 'New':
create_html = True
else:
res = input(ask_html)
if not res in ['y', 'Y']: create_html = False
if create_html:
user_file = open(footer_load, 'r').read()
ask_load = ' ├ Replace HTML footer: %s ? '%db.wip_footer
log_load = ' ├ Create file: %s'%db.wip_footer
res = ''
if os.path.exists(db.wip_footer):
res = input(ask_load)
if not res in ['y', 'Y']: return
user_footer = ''
user_file = open(db.footer_load, 'r').read()
for line in user_file.rsplit('\n'):
if not line: continue
if user_footer: user_footer = "%s\n %s"%(user_footer, line)
else: user_footer = ' %s'%line
tyto.set_file(footer_html, 'new', user_footer)
print(log_html)
tyto.set_file(db.wip_footer, 'new', user_footer)
print(log_load)

View File

@ -0,0 +1,69 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: logs tools
# Description: Show logs and statuses, exit if needed
# file: logs.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 sys
# Colors
CS = '\033[0;0m'
CR = '\033[1;31m'
CY = '\033[1;33m'
CG = '\033[1;32m'
# Exit from program with message #
#--------------------------------#
def out(nbr, value, out):
logs = {
'1' : ':< %sUnused resource%s: %s'%(CR, CS, value),
'2' : ':< %sIncomplete data%s: "%s"'%(CR, CS, value),
'3' : ':< %sInvalid data%s: "%s"'%(CR, CS, value),
'5' : ':< %sUnused argument%s: [file]'%(CR, CS),
'6' : ':< %sUnused "%s"%s in article'%(CR, CS, value),
'7' : ':< Article is %snot valid yet%s'%(CR, CS),
'8' : ':< %sNot paired%s: %s'%(CR, CS, value),
'9' : ':< Article %shas changed%s. Check it first'%(CR, CS),
'10' : ':< %sUnused domain configuration%s: %s'%(CR, CS, value),
'11' : ':< %sUnused argument%s: %s'%(CR, CS, value),
'12' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, CS),
'13' : ':< %sNo file or directory%s here (deleted ?)'%(CR, CS),
'19' : ':D Article %swip%s on: %s'%(CG, CS, value),
'20' : ':D Article %scheck%s on: %s'%(CG, CS, value),
'21' : ':D %sValid%s article. Ready to wip'%(CG, CS),
'22' : ':? %sNot paired%s symbols: %s'%(CY, CS, value),
'23' : ':? %sCorrupted database%s: %s'%(CY, CS, value),
'24' : ':? %sUnused resource%s %s'%(CY, CS, value),
'25' : ':? Article %snot yet checked%s: %s'%(CY, CS, value),
'26' : ':? %sNo index%s article %s'%(CY, CS, value),
'28' : ':? Nothing to do %s'%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),
'33' : ':D %sCreated file%s: %s'%(CG, CS, value),
'40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value),
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),
'42' : ':D %sActive%s domain "%s"'%(CG, CS, value),
'43' : ':? %sNo domain%s configured here: %s'%(CY, CS, value),
'255' : ';) Maybe later...'
}
msg = logs[nbr]
print(msg)
if int(nbr) >= 20: nbr = 0
if out: sys.exit(int(nbr))

View File

@ -1,52 +0,0 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Global functions to manage sidebar
# Description: Create domain
# file: sidebar.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 sys
import tyto, html
# Load domain configuration if exists
if tyto.domain_exists: exec(open(tyto.domain_conf).read())
#==============================#
# Manage arguments for sidebar #
#------------------------------#
def manage_navbars(target, option):
import domain
actions = {
'sidebar' : domain.create_sidebar,
'navbar' : domain.create_navbar
}
if sys.argv[1] == "sidebar": file = sidebar_load
elif sys.argv[1] == 'navbar': file = navbar_load
# Initialize new file
if not target:
if option == "Remove":
actions[sys.argv[1]](option, navbars_dir)
elif option == 'Edit':
print(":D Edit %s configuration file:"%sys.argv[1], file)
tyto.edit_file(file)
elif option == 'New':
html.create_navbar()
else:
db_exists = tyto.get_db_post(target) # Article exists + has DB ?
if not db_exists: tyto.exiting("4", '') # Needs database

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Create HTML files in www/
# Description: Copy files and replace publish line in article
# file: publish.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:
#----------------------------------------------------------------------
#**********************************************************************
def replace_line_pub():
# Testing html publis
print('> Testing html publish')
wip_html_post = open(post_wip, 'r').read()
for line in wip_html_post.rsplit('\n'):
if line.startswith('%s<p><span id="article_title"'%(8 * ' ')): print(line)

View File

@ -20,79 +20,41 @@
import os, sys, subprocess, locale, base64, datetime
from hashlib import blake2b
# Second argument in command
#---------------------------
arguments = (
'-a', 'add',
'-R', 'remove',
'-e', 'edit',
'-n', 'new',
'-F', 'force',
'-d',
'again'
)
# Settings
#---------
import db, logs
domain_active = False
home_dir = os.path.expanduser('~')
in_dir = os.getcwd()
domain_conf = in_dir
if '/articles' in in_dir:
domain_conf = in_dir.rsplit('/articles')[0]
else:
try:
sys.argv[2]
if not sys.argv[2] in arguments:
if 'articles/' in sys.argv[2]:
domain_conf = in_dir.rsplit('articles/')[0]
except:
domain_conf = in_dir
conf_dir = domain_conf + "/"
domain_conf = '%s/tyto_domain.conf'%domain_conf
if db.domain_exists:
db_dir = db.domain_db
# Check if domain config file
#----------------------------
stdout = '%s %s domain "%s" in %s' # Message to show domain status
if os.path.exists(domain_conf):
exec(open(domain_conf).read())
datas_domain = open(domain_conf, "r").read()
domain_exists = True
if domain_active:
smiley = ':D'; status = 'Active'
domain_active = True
else:
smiley = ':|'; status = 'Inactive'
domain_active = False
print(stdout%(
smiley, status, domain_short, domain_conf
)
)
else:
print(':? No domain configured in this directory: %s'%domain_conf)
domain_exists = domain_active = False
if domain_exists:
db_dir = domain_db
# Basic translations: french, english
#------------------------------------
# Set translations: french, english
#----------------------------------
try: lang = domain_lang
except: lang = locale.getdefaultlocale()[0].split('_')[0]
if lang.lower() == 'fr': n = 0
else: n = 1
# :D
Tyto = 'Tyto - Littérateur'
Tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur'
Tytoweb = 'https://tyto.echolib.re'
# Translations French/English
trans = [
('À l\'affiche !', 'Featured !'), #0
('Accueil', 'Home'), #1
('Licence', 'License') #2
('Licence', 'License'), #2
('Code source', 'Source code'),
('Dépôt officiel du code source de %s'%Tyto , '%s\'s official source code repository'%Tyto),
('Site web officiel du logiciel libre %s'%Tyto, '%s\'s official website'),
('L\'article', 'The article'),
('écrit par', 'written by'),
('Publié le', 'Published the'), #8 date for section HTML (article_infos)
('à', 'at'), #9 time format
('rédigé le', 'created the')
]
@ -113,13 +75,6 @@ headers = (
)
# Colors
CS = '\033[0;0m'
CR = '\033[1;31m'
CY = '\033[1;33m'
CG = '\033[1;32m'
# Words and template Tags (paragraphs, lists, bold, strong...)
# Used to check, and replace (wip) tags
# As base64 is used, do NOT set marker: =_ _=
@ -144,8 +99,8 @@ words_tags = [
]
# warning Tags (Check paired symbols)
#--------------------------------------
# warning symbols (Check if paired)
#----------------------------------
tpl_tags = [
('(', ')'),
('[', ']'),
@ -181,6 +136,7 @@ quote_tags = [
# Tags to check in header in content _TAG
head_tags = ("image:", "raw:")
#=======#
# TOOLS #
#=======#--------------------------------------------------------------
@ -209,7 +165,7 @@ def nowdate():
# Convert date DD/MM/YYYY to YYYY-MM-DD #
#---------------------------------------#
def set_en_date(date):
if domain_lang.lower() == 'fr':
if db.domain_lang.lower() == 'fr':
udate = date.rsplit('/')
return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
@ -220,44 +176,59 @@ def set_en_date(date):
#-----------------------#
def get_db_post(target):
# Check if target file exists
global uri_post
uri_post = '%s/%s'%(in_dir, target)
if not os.path.exists(uri_post):
exiting("1", uri_post, True)
global uri_file
uri_file = '%s/%s'%(in_dir, target)
if not os.path.exists(uri_file):
logs.out("1", uri_file, True)
global uri_root
uri_root = uri_post
# Get extension from target, set short uris
ext_src = os.path.splitext(target)
global uri_src
uri_src = '/' + uri_post.rsplit(domain_articles)[1]
# Get uri after articles/ (no /...)
src_noslah_uri = uri_file.rsplit(db.domain_articles)[1]
global src_post_short_uri, srv_post_short_uri
src_post_short_uri = '/' + uri_file.rsplit(db.domain_articles)[1]
srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html')
global srv_post_wip_uri, srv_post_www_uri
srv_post_wip_uri = db.srv_wip + src_noslah_uri.replace(ext_src[1], '.html')
srv_post_www_uri = db.srv_www + src_noslah_uri.replace(ext_src[1], '.html')
# Hash from content file
global hash_post
hash_post = get_filesum(uri_post, True) # From content file
global web_uri
ext = os.path.splitext(uri_post)
new_ext = '.html'
uri_post = uri_post.replace(ext[1], new_ext)
web_uri = '/' + uri_post.rsplit(domain_articles)[1]
global post_filename, post_dir
post_filename = os.path.basename(uri_post)
post_dir = uri_post.replace(post_filename, '')
hash_post = get_filesum(uri_file, True)
# Hash from URI file
global uri_id
uri_id = get_filesum(uri_post, False) # From URI file
uri_id = get_filesum(uri_file, False) # From URI file
# Set DB file for this post
global post_db
post_db = '%s/%s.conf'%(db_dir, uri_id)
if os.path.exists(post_db): db_exists = True
else : db_exists = False
# Get sub_uri for HTML
global sub_uri
sub_uri = uri_file.rsplit('articles/')[1]
sub_nbr = sub_uri.count('/')
if sub_nbr == 0 : sub_uri = './'
else: sub_uri = sub_nbr * '../'
# Set HTTP link for wip and www
global http_www, http_wip
if srv_post_short_uri.endswith('index.html'):
http_www = "%s/"%db.domain_www_url
http_wip = '%s/'%db.domain_wip_url
else:
http_www = "%s%s"%(db.domain_www_url, srv_post_short_uri)
http_wip = '%s%s'%(db.domain_wip_url, srv_post_short_uri)
# Check if null byte
if db_exists and os.stat(post_db).st_size < 1000:
os.remove(post_db)
exiting('23', post_db, False)
logs.out('23', post_db, False)
db_exists = False
return(db_exists)
@ -267,6 +238,9 @@ def get_db_post(target):
# Open and edit a file #
#----------------------#
def edit_file(edit_file):
if not os.path.exists(edit_file):
logs.out("1", edit_file, True)
file_edit = subprocess.run(
[
'/usr/bin/nano',
@ -513,6 +487,10 @@ def exiting(nbr, value, out):
'27' : ':? %sDeleted%s %s'%(CY, CS, value),
'28' : ':? %sUnused directory%s: %s'%(CY, CS, value),
'29' : ':? %sEmpty configuration%s %s'%(CY, CS, value),
'30' : ':? %sArticle is not wip%s: %s'%(CY, CS, value),
'31' : ':? %sMax items reached%s %s'%(CY, CS, value),
'32' : ':? %sNo changes%s in: %s'%(CY, CS, value),
'33' : ':D %sCreated file%s: %s'%(CG, CS, value),
'255' : ':| Maybe later...'
}

View File

@ -16,13 +16,15 @@
#----------------------------------------------------------------------
#**********************************************************************
import os, re
import tyto, html
import os, re, shutil
import logs, db, tyto, html
def manage_wip(target, option):
global post_db, hash_post
if not db.domain_exists: return
#-----------------------------------------
# Option 'Again' to wip again, based on DB
#-----------------------------------------
@ -33,30 +35,26 @@ def manage_wip(target, option):
return
# Load domain configuration DB
exec(open(tyto.domain_conf).read(),globals())
for post_db in os.listdir(domain_db):
for post_db in os.listdir(db.domain_db):
if post_db.endswith('.conf'):
# Load DB
post_db = '%s%s'%(domain_db, post_db)
post_db = '%s%s'%(db.domain_db, post_db)
exec(open(post_db).read(),globals())
if not hash_wip: continue
print("->", root_uri)
hash_post = tyto.get_filesum(root_uri, True) # From content file
wip_article(root_uri)
print("->", post_src)
hash_post = tyto.get_filesum(post_src, True) # From content file
wip_article(post_src)
return
#------------------------
# Per article with target
#------------------------
# target needed
if not target: tyto.exiting("5", '', True)
# Article exists + has DB ?
db_exists = tyto.get_db_post(target)
target = tyto.uri_root
target = tyto.uri_file # tyto.uri_root
if not db_exists:
tyto.exiting("4", '', True)
logs.out("25", target, True)
# Load DB
post_db = tyto.post_db
@ -64,7 +62,7 @@ def manage_wip(target, option):
exec(open(post_db).read(),globals())
# Exit if article has changed
if hash_chk != hash_post: tyto.exiting("9", '', True)
if hash_chk != hash_post: logs.out("9", target, True)
# In any case, if Force
if option == 'Force':
@ -75,11 +73,11 @@ def manage_wip(target, option):
if hash_wip != hash_chk:
wip_article(target)
else:
if not os.path.exists(wip_uri):
tyto.exiting("24", '(wip article): %s'%wip_uri, False)
if not os.path.exists(post_wip):
logs.out("24", '(wip article): %s'%post_wip, False)
wip_article(target)
else:
tyto.exiting("20", date_wip, True)
logs.out("19", date_wip, True)
#===================#
@ -121,7 +119,18 @@ def wip_article(target):
# Get article DB in html.py
html.set_page(post_db, target, article_bottom)
print(html.main_page)
#print(html.main_page)
# Create wip file
tyto.set_file(post_wip, 'New', html.main_page)
logs.out("33", post_wip, False)
# Copy needed file to wip
for uri in uris:
f_src = '%s%s'%(db.domain_articles, uri)
f_wip = '%s%s'%(db.srv_wip, uri)
shutil.copy2(f_src, f_wip)
logs.out("33", f_wip, False)
# Replace in DB hash_wip and date_wip
tyto.replace_in_db(post_db, 'wip', hash_post)
@ -278,7 +287,7 @@ def wip_images():
for i in range(1, uniq_images + 1):
image = 'image_%s'%i
target = width = height = False
set_css = tyto.domain_css + '_image'
set_css = db.domain_css + '_image'
imag_html = ''
if eval(image)[0] == values[0]:
@ -607,15 +616,17 @@ def wip_raws(target):
raw = 'raw_%s'%i
raw_file = open(
'%s%s'%(
tyto.domain_articles, eval(raw)[1]
db.domain_articles, eval(raw)[1]
)
).read()
raw_html = '<pre class="%s" title="%s">\n'%(
tyto.domain_css, eval(raw)[2]
db.domain_css, eval(raw)[2]
) + \
' <code class="bcode">'
for line in raw_file.rsplit('\n'):
raw_html = '%s\n <span class="bcode">%s</span>'%(raw_html, line)
raw_html = '%s\n <span class="bcode">%s</span>'%(
raw_html, line
)
raw_html = '%s\n </code>\n</pre>'%(raw_html)
article_bottom = article_bottom.replace(