Lots of changes. wip page file created with needed in-files article
This commit is contained in:
parent
a71e2e58e6
commit
8e74f8dece
|
@ -26,8 +26,6 @@
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, '/var/lib/tyto/program')
|
sys.path.insert(0, '/var/lib/tyto/program')
|
||||||
|
|
||||||
import check, domain, wip, html
|
|
||||||
|
|
||||||
#====================#
|
#====================#
|
||||||
# MAIN #
|
# MAIN #
|
||||||
# Treat Arguments #
|
# Treat Arguments #
|
||||||
|
@ -36,6 +34,9 @@ if not __name__ == "__main__":
|
||||||
print(':< Mismatch program start')
|
print(':< Mismatch program start')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
import args
|
||||||
|
import check, domain, wip, html
|
||||||
|
|
||||||
noarg = False
|
noarg = False
|
||||||
target = ''
|
target = ''
|
||||||
option = ''
|
option = ''
|
||||||
|
@ -51,38 +52,7 @@ actions = {
|
||||||
'footer' : html.manage_configs
|
'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
|
# Argument 1
|
||||||
#-----------
|
#-----------
|
||||||
try:
|
actions[sys.argv[1]](args.target, args.option)
|
||||||
actions[sys.argv[1]](target, option)
|
|
||||||
except KeyError:
|
|
||||||
print(':< Invalid action "%s": [check, wip...]'%sys.argv[1])
|
|
||||||
|
|
|
@ -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
|
|
@ -23,10 +23,7 @@ from datetime import datetime
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import tyto
|
import logs, db, tyto
|
||||||
|
|
||||||
# Load domain configuration if exists
|
|
||||||
if tyto.domain_exists: exec(open(tyto.domain_conf).read())
|
|
||||||
|
|
||||||
post_err = False
|
post_err = False
|
||||||
date_wip = hash_wip = date_www = hash_www = ''
|
date_wip = hash_wip = date_www = hash_www = ''
|
||||||
|
@ -37,21 +34,22 @@ date_wip = hash_wip = date_www = hash_www = ''
|
||||||
# Start checking article #
|
# Start checking article #
|
||||||
#-------------------------#--------------------------------------------
|
#-------------------------#--------------------------------------------
|
||||||
def manage_check(target, option):
|
def manage_check(target, option):
|
||||||
|
# target needed
|
||||||
|
if not target: logs.out("5", '', True)
|
||||||
|
|
||||||
|
|
||||||
global post_bottom, article_bottom
|
global post_bottom, article_bottom
|
||||||
global post_words
|
global post_words
|
||||||
|
|
||||||
# target needed
|
|
||||||
if not target: tyto.exiting("5", '', True)
|
|
||||||
|
|
||||||
# Article exists + has DB ?
|
# Article exists + has DB ?
|
||||||
db_exists = tyto.get_db_post(target)
|
db_exists = tyto.get_db_post(target)
|
||||||
|
|
||||||
# Manage option
|
# Manage option
|
||||||
if option == 'Edit':
|
if option == 'Edit':
|
||||||
tyto.edit_file(tyto.uri_root)
|
tyto.edit_file(tyto.uri_file)
|
||||||
return
|
return
|
||||||
elif option == 'Show':
|
elif option == 'Show':
|
||||||
article_raw = open(tyto.uri_root).read()
|
article_raw = open(tyto.uri_file).read()
|
||||||
for line in article_raw.rsplit('\n'):
|
for line in article_raw.rsplit('\n'):
|
||||||
print(line)
|
print(line)
|
||||||
return
|
return
|
||||||
|
@ -66,21 +64,12 @@ def manage_check(target, option):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exec(open(tyto.post_db).read(),globals())
|
exec(open(tyto.post_db).read(),globals())
|
||||||
try:
|
if hash_chk == tyto.hash_post and not option == 'Force':
|
||||||
if hash_chk == tyto.hash_post and not option == 'Force':
|
logs.out("20", date_chk, True)
|
||||||
tyto.exiting("20", date_chk, True)
|
finally: pass
|
||||||
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 * '../'
|
|
||||||
|
|
||||||
# Start processes
|
# Start processes
|
||||||
file_to_string(tyto.uri_root)
|
file_to_string(tyto.uri_file)
|
||||||
|
|
||||||
# Specific to inline-code: check markers on same line
|
# Specific to inline-code: check markers on same line
|
||||||
check_icodes(article.rsplit('\n'))
|
check_icodes(article.rsplit('\n'))
|
||||||
|
@ -106,7 +95,7 @@ def manage_check(target, option):
|
||||||
check_headers(post_header)
|
check_headers(post_header)
|
||||||
|
|
||||||
# Exit if unused needed tags
|
# Exit if unused needed tags
|
||||||
if post_err: tyto.exiting("7", '', True)
|
if post_err: logs.out("7", '', True)
|
||||||
|
|
||||||
# No error
|
# No error
|
||||||
create_database()
|
create_database()
|
||||||
|
@ -134,8 +123,7 @@ def file_to_string(post_file):
|
||||||
article = open(post_file, 'r').read()
|
article = open(post_file, 'r').read()
|
||||||
|
|
||||||
# Check if separator or exit
|
# Check if separator or exit
|
||||||
if not '-----' in article:
|
if not '-----' in article: logs.out("6", '-----', True)
|
||||||
tyto.exiting("6", '-----', True)
|
|
||||||
|
|
||||||
# Set from separator, NOT splitted by new line
|
# Set from separator, NOT splitted by new line
|
||||||
article_header = article.rsplit('-----')[0]
|
article_header = article.rsplit('-----')[0]
|
||||||
|
@ -146,9 +134,9 @@ def file_to_string(post_file):
|
||||||
post_bottom = article.rsplit('-----')[1].rsplit('\n')
|
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):
|
def check_icodes(article):
|
||||||
quote = bcode = False
|
quote = bcode = False
|
||||||
|
|
||||||
|
@ -172,10 +160,11 @@ def check_icodes(article):
|
||||||
icode_m1 = line.count(tyto.words_tags[9][0])
|
icode_m1 = line.count(tyto.words_tags[9][0])
|
||||||
icode_m2 = line.count(tyto.words_tags[9][1])
|
icode_m2 = line.count(tyto.words_tags[9][1])
|
||||||
if icode_m1 != icode_m2:
|
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]
|
tyto.words_tags[9][0], tyto.words_tags[9][1]
|
||||||
), True
|
), True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#==================================#
|
#==================================#
|
||||||
# Check tags from article's header #
|
# 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 stat_links, stat_images, stat_files, stat_raws, stat_abbrs
|
||||||
global post_tags
|
global post_tags
|
||||||
global snpic_url
|
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
|
snshare = False
|
||||||
snpic_name = ''
|
snpic_name = ''
|
||||||
|
@ -259,7 +253,7 @@ def check_headers(post_header):
|
||||||
# Check if set needed tags
|
# Check if set needed tags
|
||||||
for tag in need_headers:
|
for tag in need_headers:
|
||||||
if not need_headers[tag]:
|
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()
|
abbr_short = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
||||||
if not abbr_short:
|
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
|
post_err = True
|
||||||
if not abbr_short.isupper():
|
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
|
post_err = True
|
||||||
continue
|
continue
|
||||||
if not isin(r'!\b%s\b'%abbr_short, post_bottom):
|
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
|
post_err = True
|
||||||
|
|
||||||
abbr_long = post_header[ln].lstrip()
|
abbr_long = post_header[ln].lstrip()
|
||||||
if abbr_long.startswith(tyto.headers): abbr_long = ''
|
if abbr_long.startswith(tyto.headers): abbr_long = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
abbr_alt = post_header[ln + 1].lstrip()
|
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()
|
link_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
||||||
if not link_name:
|
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
|
post_err = True
|
||||||
if not isin(r'\b_%s\b'%link_name, post_bottom):
|
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
|
post_err = True
|
||||||
|
|
||||||
link_url = post_header[ln].lstrip()
|
link_url = post_header[ln].lstrip()
|
||||||
if link_url.startswith(tyto.headers): link_url = ''
|
if link_url.startswith(tyto.headers): link_url = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
link_alt = post_header[ln + 1].lstrip()
|
link_alt = post_header[ln + 1].lstrip()
|
||||||
if link_alt.startswith(tyto.headers): link_alt = ''
|
if link_alt.startswith(tyto.headers): link_alt = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
if not post_err:
|
if not post_err:
|
||||||
|
@ -356,24 +350,26 @@ def check_headers(post_header):
|
||||||
image_name = post_header[ln - 1]
|
image_name = post_header[ln - 1]
|
||||||
image_name = image_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
|
image_name = image_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
|
||||||
if not image_name:
|
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
|
post_err = True
|
||||||
if not isin(r'\b_%s%s\b'%(tag, image_name), post_bottom):
|
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
|
post_err = True
|
||||||
|
|
||||||
image_uri = post_header[ln].lstrip()
|
image_uri = post_header[ln].lstrip()
|
||||||
if image_uri.startswith(tyto.headers): image_uri = ''
|
if image_uri.startswith(tyto.headers): image_uri = ''
|
||||||
if not 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
|
post_err = True
|
||||||
else:
|
else:
|
||||||
check_file_uri('image', image_uri, ln + 1)
|
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()
|
image_alt = post_header[ln + 1].lstrip()
|
||||||
if image_alt.startswith(tyto.headers): image_alt = ''
|
if image_alt.startswith(tyto.headers): image_alt = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
if not post_err:
|
if not post_err:
|
||||||
|
@ -393,24 +389,26 @@ def check_headers(post_header):
|
||||||
raw_name = post_header[ln - 1]
|
raw_name = post_header[ln - 1]
|
||||||
raw_name = raw_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
|
raw_name = raw_name.rsplit(tag)[1].lstrip().rsplit(' ')[0]
|
||||||
if not raw_name:
|
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
|
post_err = True
|
||||||
if not isin(r'\b_%s%s\b'%(tag, raw_name), post_bottom):
|
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
|
post_err = True
|
||||||
|
|
||||||
raw_uri = post_header[ln].lstrip()
|
raw_uri = post_header[ln].lstrip()
|
||||||
if raw_uri.startswith(tyto.headers): raw_uri = ''
|
if raw_uri.startswith(tyto.headers): raw_uri = ''
|
||||||
if not 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
|
post_err = True
|
||||||
else:
|
else:
|
||||||
check_file_uri('file', raw_uri, ln + 1)
|
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()
|
raw_alt = post_header[ln + 1].lstrip()
|
||||||
if raw_alt.startswith(tyto.headers): raw_alt = ''
|
if raw_alt.startswith(tyto.headers): raw_alt = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
if not post_err:
|
if not post_err:
|
||||||
|
@ -429,24 +427,26 @@ def check_headers(post_header):
|
||||||
|
|
||||||
file_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
file_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
||||||
if not file_name:
|
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
|
post_err = True
|
||||||
if not isin(r'\b__%s\b'%file_name, post_bottom):
|
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
|
post_err = True
|
||||||
|
|
||||||
file_uri = post_header[ln].lstrip()
|
file_uri = post_header[ln].lstrip()
|
||||||
if file_uri.startswith(tyto.headers): file_uri = ''
|
if file_uri.startswith(tyto.headers): file_uri = ''
|
||||||
if not 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
|
post_err = True
|
||||||
else:
|
else:
|
||||||
check_file_uri('file', file_uri, ln + 1)
|
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()
|
file_alt = post_header[ln + 1].lstrip()
|
||||||
if file_alt.startswith(tyto.headers): file_alt = ''
|
if file_alt.startswith(tyto.headers): file_alt = ''
|
||||||
if not 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
|
post_err = True
|
||||||
|
|
||||||
if not post_err:
|
if not post_err:
|
||||||
|
@ -461,24 +461,24 @@ def check_headers(post_header):
|
||||||
# snpic (set image to share to social networks)
|
# snpic (set image to share to social networks)
|
||||||
#----------------------------------------------
|
#----------------------------------------------
|
||||||
if snpic_name: continue
|
if snpic_name: continue
|
||||||
|
snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo)
|
||||||
tag = tyto.headers[11] # snpic:
|
tag = tyto.headers[11] # snpic:
|
||||||
if line.startswith(tag):
|
if line.startswith(tag):
|
||||||
snpic_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
snpic_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
|
||||||
|
|
||||||
for ln, line in enumerate(post_header, 1):
|
for ln, line in enumerate(post_header, 1):
|
||||||
if re.search(r"^image:\s+%s$"%snpic_name, line):
|
if re.search(r"^image:\s+%s$"%snpic_name, line):
|
||||||
image_uri = post_header[ln].lstrip()
|
image_uri = post_header[ln].lstrip()
|
||||||
check_file_uri('image', image_uri, ln + 1)
|
check_file_uri('image', image_uri, ln + 1)
|
||||||
snshare = True
|
snshare = True
|
||||||
snpic_url = '%s%s'%(domain_url, web_uri)
|
snpic_url = '%s%s'%(db.domain_www_url, web_uri)
|
||||||
break
|
break
|
||||||
if not snshare:
|
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
|
# Exit if error in optional tags
|
||||||
#-------------------------------
|
#-------------------------------
|
||||||
if post_err:
|
if post_err: logs.out("7", '', True)
|
||||||
tyto.exiting("7", '', True)
|
|
||||||
|
|
||||||
|
|
||||||
#================================#
|
#================================#
|
||||||
|
@ -495,7 +495,7 @@ def check_date(date, ln):
|
||||||
bool(datetime.strptime(date, fmt_article))
|
bool(datetime.strptime(date, fmt_article))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
post_err = True
|
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
|
# Create date_check (epoch) from article's Date + now TIME
|
||||||
if not post_err:
|
if not post_err:
|
||||||
|
@ -516,9 +516,9 @@ def check_file_uri(filetype, filename, ln):
|
||||||
# (@ = images/, / = articles/, else = post_dir)
|
# (@ = images/, / = articles/, else = post_dir)
|
||||||
if filename.startswith('@'):
|
if filename.startswith('@'):
|
||||||
if filetype == 'image':
|
if filetype == 'image':
|
||||||
fileuri = domain_images + filename[1: len(filename)]
|
fileuri = db.domain_images + filename[1: len(filename)]
|
||||||
elif filetype == 'file':
|
elif filetype == 'file':
|
||||||
fileuri = domain_files + filename[1: len(filename)]
|
fileuri = db.domain_files + filename[1: len(filename)]
|
||||||
|
|
||||||
elif filename.startswith('/'):
|
elif filename.startswith('/'):
|
||||||
fileuri = tyto.post_dir + filename[1: len(filename)]
|
fileuri = tyto.post_dir + filename[1: len(filename)]
|
||||||
|
@ -528,11 +528,11 @@ def check_file_uri(filetype, filename, ln):
|
||||||
|
|
||||||
# Check if file exists
|
# Check if file exists
|
||||||
if not os.path.exists(fileuri):
|
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
|
post_err = True
|
||||||
return
|
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 line.startswith(tag[1]): c_closed += 1
|
||||||
|
|
||||||
if c_opened != c_closed:
|
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
|
post_err = True
|
||||||
return # Useless and could code errors to check nexts
|
return # Useless and could code errors to check nexts
|
||||||
else:
|
else:
|
||||||
|
@ -581,7 +581,7 @@ def check_content(post_bottom):
|
||||||
css_anchor = anchor.rsplit(':')[0]
|
css_anchor = anchor.rsplit(':')[0]
|
||||||
tag = '%s %s'%(tyto.single_tags[1][0], css_anchor)
|
tag = '%s %s'%(tyto.single_tags[1][0], css_anchor)
|
||||||
if not tag in post_bottom:
|
if not tag in post_bottom:
|
||||||
tyto.exiting("6", 'anchor, %s'%tag, False)
|
logs.out("6", 'anchor, %s'%tag, False)
|
||||||
post_err = True
|
post_err = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -598,9 +598,10 @@ def check_content(post_bottom):
|
||||||
if not inlist: continue
|
if not inlist: continue
|
||||||
|
|
||||||
if not line[0] in tyto.markers_lists:
|
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
|
ln, markers_lists
|
||||||
), False)
|
), False
|
||||||
|
)
|
||||||
post_err = True
|
post_err = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -621,7 +622,7 @@ def check_content(post_bottom):
|
||||||
set_tags = (ptag_set)
|
set_tags = (ptag_set)
|
||||||
|
|
||||||
if match: continue
|
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)
|
# Template Tags (warning for not paired symbols)
|
||||||
|
@ -631,7 +632,7 @@ def check_content(post_bottom):
|
||||||
tpl2 = article_bottom.count(tag[1])
|
tpl2 = article_bottom.count(tag[1])
|
||||||
|
|
||||||
if tpl1 != tpl2:
|
if tpl1 != tpl2:
|
||||||
tyto.exiting("22", '"%s", "%s"'%(tag[0], tag[1]), False)
|
logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -639,25 +640,24 @@ def check_content(post_bottom):
|
||||||
# Create new article's database at each check ! #
|
# Create new article's database at each check ! #
|
||||||
#-----------------------------------------------#
|
#-----------------------------------------------#
|
||||||
def create_database():
|
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' + \
|
database = '# Post Configuration for Tyto\n' + \
|
||||||
'post_id = "%s"\n'%tyto.uri_id + \
|
'post_id = "%s"\n'%tyto.uri_id + \
|
||||||
'root_uri = "%s"\n'%tyto.uri_root + \
|
'post_src = "%s"\n'%tyto.uti_file + \
|
||||||
'wip_uri = "%s%s"\n'%(srv_wip, web_uri) + \
|
'post_wip = "%s"\n'%tyto.srv_post_wip_uri + \
|
||||||
'www_uri = "%s%s"\n'%(srv_www, web_uri) + \
|
'post_www = "%s"\n'%tyto.srv_post_www_uri + \
|
||||||
'http_uri = "%s"\n'%tyto.web_uri + \
|
|
||||||
'sub_uri = "%s"\n'%sub_uri + \
|
|
||||||
'\n' + \
|
'\n' + \
|
||||||
'date_chk = "%s"\n'%tyto.nowdate() + \
|
'short_src = "%s"\n'%tyto.src_post_short_uri + \
|
||||||
'hash_chk = "%s"\n'%tyto.hash_post + \
|
'short_srv = "%s"\n'%tyto.srv_post_short_uri + \
|
||||||
'date_wip = "%s"\n'%date_wip + \
|
'sub_uri = "%s"\n'%tyto.sub_uri + \
|
||||||
'hash_wip = "%s"\n'%hash_wip + \
|
'http_wip = "%s"\n'%tyto.http_wip + \
|
||||||
'date_www = "%s"\n'%date_www + \
|
'http_www = "%s"\n'%tyto.http_www + \
|
||||||
'hash_www = "%s"\n'%hash_www + \
|
'\n' + \
|
||||||
|
'date_chk = "%s"\n'%tyto.nowdate() + \
|
||||||
|
'hash_chk = "%s"\n'%tyto.hash_post + \
|
||||||
|
'date_wip = "%s"\n'%date_wip + \
|
||||||
|
'hash_wip = "%s"\n'%hash_wip + \
|
||||||
|
'date_www = "%s"\n'%date_www + \
|
||||||
|
'hash_www = "%s"\n'%hash_www + \
|
||||||
'\n# Post configuration from needed tags\n' + \
|
'\n# Post configuration from needed tags\n' + \
|
||||||
'title = "%s"\n'%title + \
|
'title = "%s"\n'%title + \
|
||||||
'about = "%s"\n'%about + \
|
'about = "%s"\n'%about + \
|
||||||
|
@ -665,6 +665,8 @@ def create_database():
|
||||||
'tags = "%s"\n'%tags + \
|
'tags = "%s"\n'%tags + \
|
||||||
'date = %s\n'%str(date) + \
|
'date = %s\n'%str(date) + \
|
||||||
'snpic = "%s"\n'%snpic_url + \
|
'snpic = "%s"\n'%snpic_url + \
|
||||||
|
'\n# Used files\n' + \
|
||||||
|
'uris = (%s)\n'%files_post + \
|
||||||
'\n# Post configuration from optional tags'
|
'\n# Post configuration from optional tags'
|
||||||
|
|
||||||
if stat_abbrs > 0:
|
if stat_abbrs > 0:
|
||||||
|
@ -698,31 +700,31 @@ def create_database():
|
||||||
)
|
)
|
||||||
|
|
||||||
db_stats = '\n# Statistics from optional tags\n' + \
|
db_stats = '\n# Statistics from optional tags\n' + \
|
||||||
'uniq_anchors = %s\n'%(int(stat_ancs)) + \
|
'uniq_anchors = %d\n'%stat_ancs + \
|
||||||
'uniq_abbrs = %s\n'%(int(stat_abbrs)) + \
|
'uniq_abbrs = %d\n'%stat_abbrs + \
|
||||||
'uniq_links = %s\n'%(int(stat_links)) + \
|
'uniq_links = %d\n'%stat_links + \
|
||||||
'uniq_images = %s\n'%(int(stat_images)) + \
|
'uniq_images = %d\n'%stat_images + \
|
||||||
'uniq_files = %s\n'%(int(stat_files)) + \
|
'uniq_files = %d\n'%stat_files + \
|
||||||
'uniq_raws = %s\n'%(int(stat_raws)) + \
|
'uniq_raws = %d\n'%stat_raws + \
|
||||||
'\n# Statistics from post content\n' + \
|
'\n# Statistics from post content\n' + \
|
||||||
'stat_tags = %s\n'%(int(post_tags)) + \
|
'stat_tags = %d\n'%post_tags + \
|
||||||
'stat_words = %s\n'%(int(post_words)) + \
|
'stat_words = %d\n'%post_words + \
|
||||||
'stat_titles = %s\n'%(int(tyto.nbr_titles)) + \
|
'stat_titles = %d\n'%tyto.nbr_titles + \
|
||||||
'stat_paragraphs = %s\n'%(int(post_paragraphs)) + \
|
'stat_paragraphs = %d\n'%post_paragraphs + \
|
||||||
'stat_anchors = %s\n'%(int(post_anchors)) + \
|
'stat_anchors = %d\n'%post_anchors + \
|
||||||
'stat_strongs = %s\n'%(int(post_strongs)) + \
|
'stat_strongs = %d\n'%post_strongs + \
|
||||||
'stat_bolds = %s\n'%(int(post_bolds)) + \
|
'stat_bolds = %d\n'%post_bolds + \
|
||||||
'stat_emphasis = %s\n'%(int(post_emphasis)) + \
|
'stat_emphasis = %d\n'%post_emphasis + \
|
||||||
'stat_italics = %s\n'%(int(post_italics)) + \
|
'stat_italics = %d\n'%post_italics + \
|
||||||
'stat_dels = %s\n'%(int(post_dels)) + \
|
'stat_dels = %d\n'%post_dels + \
|
||||||
'stat_underlines = %s\n'%(int(post_underlines)) + \
|
'stat_underlines = %d\n'%post_underlines + \
|
||||||
'stat_cites = %s\n'%(int(post_cites)) + \
|
'stat_cites = %d\n'%post_cites + \
|
||||||
'stat_customs = %s\n'%(int(post_customs)) + \
|
'stat_customs = %d\n'%post_customs + \
|
||||||
'stat_icodes = %s\n'%(int(tyto.nbr_icodes)) + \
|
'stat_icodes = %d\n'%tyto.nbr_icodes + \
|
||||||
'stat_bcodes = %s\n'%(int(tyto.nbr_bcodes)) + \
|
'stat_bcodes = %d\n'%tyto.nbr_bcodes + \
|
||||||
'stat_quotes = %s\n'%(int(tyto.nbr_quotes)) + \
|
'stat_quotes = %d\n'%tyto.nbr_quotes + \
|
||||||
'stat_lists = %s\n'%(int(post_lists))
|
'stat_lists = %d\n'%post_lists
|
||||||
|
|
||||||
database = '%s\n%s'%(database, db_stats)
|
database = '%s\n%s'%(database, db_stats)
|
||||||
tyto.set_file(tyto.post_db, 'new', database)
|
tyto.set_file(tyto.post_db, 'new', database)
|
||||||
tyto.exiting("21", '', True)
|
logs.out("21", '', True)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -17,33 +17,38 @@
|
||||||
|
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, locale
|
import os, sys, locale
|
||||||
|
import logs, db, tyto, html
|
||||||
import tyto, html
|
|
||||||
|
|
||||||
#==========================#
|
#==========================#
|
||||||
# Manage Argument 'domain' #
|
# Manage Argument 'domain' #
|
||||||
#--------------------------#
|
#--------------------------#
|
||||||
def manage_domain(target, option):
|
def manage_domain(target, option):
|
||||||
if option == 'Edit':
|
if option == 'Edit':
|
||||||
if tyto.domain_exists:
|
if db.domain_exists:
|
||||||
print(":D Edit domain configuration file:", tyto.domain_conf)
|
print(":D Edit domain configuration file:", db.domain_conf)
|
||||||
tyto.edit_file(tyto.domain_conf)
|
tyto.edit_file(db.domain_conf)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
elif option == 'New':
|
elif option == 'New':
|
||||||
if not tyto.domain_exists:
|
if not db.domain_exists:
|
||||||
create_domain(target, option)
|
create_domain(target, option)
|
||||||
else:
|
else:
|
||||||
print(':) A domain exists in this directory')
|
if not db.incomplete_domain:
|
||||||
ask = input('-> Edit it with the form ? ')
|
ask = input(' ├ Edit the domain configuration with the form ? ')
|
||||||
if ask in ['y', 'Y']: create_domain(target, option)
|
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':
|
elif option == 'Show':
|
||||||
if tyto.domain_exists:
|
if db.domain_exists:
|
||||||
domain_db = open(tyto.domain_conf).read()
|
domain_db = open(db.domain_conf).read()
|
||||||
for line in domain_db.rsplit('\n'):
|
for line in domain_db.rsplit('\n'):
|
||||||
print(line)
|
print(line)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
#=====================#
|
#=====================#
|
||||||
|
@ -51,10 +56,9 @@ def manage_domain(target, option):
|
||||||
#---------------------#
|
#---------------------#
|
||||||
def isurl(target):
|
def isurl(target):
|
||||||
global url
|
global url
|
||||||
if target.startswith('http'):
|
if target.startswith('http'): url = target
|
||||||
url = target
|
else: logs.out("2", target, True)
|
||||||
else:
|
|
||||||
tyto.exiting("2", target, True)
|
|
||||||
|
|
||||||
#=====================#
|
#=====================#
|
||||||
# Create a new domain #
|
# Create a new domain #
|
||||||
|
@ -75,322 +79,330 @@ def create_domain(target, option):
|
||||||
|
|
||||||
# Get complete URL from target or ask
|
# Get complete URL from target or ask
|
||||||
#------------------------------------
|
#------------------------------------
|
||||||
try: domain_url = tyto.domain_url
|
try:
|
||||||
except: domain_url = ''
|
domain_www_url = db.domain_www_url
|
||||||
|
except:
|
||||||
|
if target: domain_www_url = target
|
||||||
|
else: domain_www_url = ''
|
||||||
|
|
||||||
|
valid_url = ('http://', 'https://')
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ [HTTP...] URL to website ? ("%s") '%domain_url)
|
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url)
|
||||||
if ask:
|
if ask:
|
||||||
|
if not ask.startswith(valid_url):
|
||||||
|
logs.out("2", 'http(s)://...', True)
|
||||||
isurl(ask)
|
isurl(ask)
|
||||||
domain_url = url
|
domain_www_url = url
|
||||||
elif not domain_url:
|
elif not domain_www_url:
|
||||||
tyto.exiting("255", '', True)
|
logs.out("255", '', True)
|
||||||
|
|
||||||
|
domain_short = domain_www_url.rsplit('://')[1]
|
||||||
|
|
||||||
domain_short = domain_url.rsplit('://')[1]
|
|
||||||
|
|
||||||
# Prefix wip
|
# Prefix wip
|
||||||
#-----------
|
#-----------
|
||||||
try:
|
try:
|
||||||
try_wipurl = target.rsplit('.')
|
try_wip_url = target.rsplit('.')
|
||||||
try_wipurl = 'https://www-wip.%s.%s'%(try_wipurl[1], try_wipurl[2])
|
try_wip_url = 'https://www-wip.%s.%s'%(
|
||||||
|
try_wip_url[1], try_wip_url[2]
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
try_wipurl = 'https://www-wip.%s'%target
|
try_wip_url = 'https://www-wip.%s'%domain_short
|
||||||
|
|
||||||
try: domain_wipurl = tyto.domain_wipurl
|
try: domain_wip_url = db.domain_wip_url
|
||||||
except: domain_wipurl = try_wipurl
|
except: domain_wip_url = try_wip_url
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ URL to wip ? ("%s") '%domain_wipurl)
|
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url)
|
||||||
if ask:
|
if ask:
|
||||||
isurl(ask)
|
isurl(ask)
|
||||||
domain_wipurl = ask
|
domain_wip_url = ask
|
||||||
|
|
||||||
|
global navbars_conf
|
||||||
db_dir = '%s/.local/tyto/%s/'%(tyto.home_dir, domain_short)
|
db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short)
|
||||||
navbars_conf= '%sarticles/_configs/'%tyto.conf_dir
|
db_dir_html = '%shtml/'%db_dir
|
||||||
conf_domain = 'domain_dir = "%s"\n'%tyto.conf_dir + \
|
navbars_conf = '%sarticles/_configs/'%db.conf_dir
|
||||||
'domain_conf = "%s"\n'%tyto.domain_conf + \
|
conf_domain = \
|
||||||
'domain_articles = "%sarticles/"\n'%tyto.conf_dir + \
|
'domain_dir = "%s"\n'%db.conf_dir + \
|
||||||
'domain_files = "%sarticles/files/"\n'%tyto.conf_dir + \
|
'domain_conf = "%s"\n'%db.domain_conf + \
|
||||||
'domain_images = "%sarticles/images/"\n'%tyto.conf_dir + \
|
'domain_articles = "%sarticles/"\n'%db.conf_dir + \
|
||||||
'domain_db = "%sarticles/"\n'%(db_dir) + \
|
'domain_files = "%sarticles/files/"\n'%db.conf_dir + \
|
||||||
'html_db = "%shtml/"\n'%(db_dir) + \
|
'domain_images = "%sarticles/images/"\n'%db.conf_dir + \
|
||||||
'navbars_dir = "%s"\n'%navbars_conf + \
|
'domain_db = "%sarticles/"\n'%db_dir + \
|
||||||
'navbar_load = "%styto.navbar"\n'%navbars_conf + \
|
'html_db = "%s"\n'%db_dir_html + \
|
||||||
'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \
|
'navbars_dir = "%s"\n'%navbars_conf + \
|
||||||
'metas_load = "%styto.metas.html"\n'%navbars_conf + \
|
'navbar_load = "%styto.navbar"\n'%navbars_conf + \
|
||||||
'footer_load = "%styto.footer.html"\n'%navbars_conf + \
|
'navbar_load_db = "%snavbar_load.conf"\n'%db_dir_html + \
|
||||||
'\ndomain_short = "%s"\n'%domain_short + \
|
'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \
|
||||||
'domain_url = "%s"\n'%domain_url + \
|
'sidebar_load_db = "%ssidebar_load.conf"\n'%db_dir_html + \
|
||||||
'domain_wipurl = "%s"\n'%domain_wipurl
|
'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_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
|
# Get title domain
|
||||||
#-----------------
|
#-----------------
|
||||||
try: domain_title = tyto.domain_title
|
try: domain_title = db.domain_title
|
||||||
except: domain_title = ''
|
except: domain_title = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Domain title ? ("%s") '%domain_title)
|
ask = input(' ├ Domain title ? ("%s") '%domain_title)
|
||||||
if ask: domain_title = ask
|
if ask: domain_title = ask
|
||||||
elif not domain_title: tyto.exit("255")
|
elif not domain_title: logs.out("255", '', True)
|
||||||
if '"' in domain_title:
|
if '"' in domain_title:
|
||||||
domain_title = domain_title.replace('"', '')
|
domain_title = domain_title.replace('"', '')
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_title = "%s"'%domain_title)
|
'# Domain user\'s settings\n' + \
|
||||||
|
'domain_title = "%s"'%domain_title
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get Description domain
|
# Get Description domain
|
||||||
#-----------------------
|
#-----------------------
|
||||||
try: domain_about = tyto.domain_about
|
try: domain_about = db.domain_about
|
||||||
except: domain_about = ''
|
except: domain_about = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
|
ask = input(' ├ Domain Description ? ("%s") '%domain_about)
|
||||||
if ask: domain_about = ask
|
if ask: domain_about = ask
|
||||||
elif not domain_about: tyto.exit("255")
|
elif not domain_about: logs.out("255", '', True)
|
||||||
if '"' in domain_about:
|
if '"' in domain_about:
|
||||||
domain_about = domain_about.replace('"', '')
|
domain_about = domain_about.replace('"', '')
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_about = "%s"'%domain_about)
|
'domain_about = "%s"'%domain_about
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get Lang domain
|
# Get Lang domain
|
||||||
#----------------
|
#----------------
|
||||||
try: domain_lang = tyto.domain_lang
|
try: domain_lang = db.domain_lang
|
||||||
except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
|
except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
|
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang)
|
||||||
if ask:
|
if ask:
|
||||||
if len(ask) == 2: domain_lang = ask
|
if len(ask) == 2: domain_lang = ask
|
||||||
else: tyto.exiting("3", ask, True)
|
else: logs.out("3", ask, True)
|
||||||
elif not domain_lang: tyto.exiting("255", '', True)
|
elif not domain_lang: logs.out("255", '', True)
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_lang = "%s"'%domain_lang)
|
'domain_lang = "%s"'%domain_lang
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get mail domain
|
# Get mail domain
|
||||||
#----------------
|
#----------------
|
||||||
try: domain_mail = tyto.domain_mail
|
try: domain_mail = db.domain_mail
|
||||||
except: domain_mail = ''
|
except: domain_mail = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
|
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail)
|
||||||
if ask:
|
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
|
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,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_mail = "%s"'%domain_mail)
|
'domain_mail = "%s"'%domain_mail
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get Tags domain
|
# Get Tags domain
|
||||||
#----------------
|
#----------------
|
||||||
try: domain_tags = tyto.domain_tags
|
try: domain_tags = db.domain_tags
|
||||||
except: domain_tags = ''
|
except: domain_tags = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
|
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags)
|
||||||
if ask: domain_tags = ask
|
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,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_tags = "%s"'%domain_tags)
|
'domain_tags = "%s"'%domain_tags
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get logo's website
|
# Get logo's website
|
||||||
#-------------------
|
#-------------------
|
||||||
try: domain_logo = tyto.domain_logo
|
try: domain_logo = db.domain_logo
|
||||||
except: domain_logo = 'logo.png'
|
except: domain_logo = 'logo.png'
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ logo filename ? ("%s") '%domain_logo)
|
ask = input(' ├ logo filename ? ("%s") '%domain_logo)
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
if ask: domain_logo = ask
|
||||||
'domain_logo = "%s"'%domain_logo)
|
|
||||||
|
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
|
# Get License domain
|
||||||
#-------------------
|
#-------------------
|
||||||
try: domain_license = tyto.domain_license
|
try: domain_license = db.domain_license
|
||||||
except: domain_license = 'CC BY-NC-SA'
|
except: domain_license = 'CC BY-NC-SA'
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Domain License ? ("%s") '%domain_license)
|
ask = input(' ├ Domain License ? ("%s") '%domain_license)
|
||||||
if ask: domain_license = ask
|
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:
|
if '"' in domain_license:
|
||||||
domain_license = domain_license.replace('"', '')
|
domain_license = domain_license.replace('"', '')
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_license = "%s"'%domain_license)
|
'domain_license = "%s"'%domain_license
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get License URL (optionnal)
|
# Get License URL (optionnal)
|
||||||
#----------------------------
|
#----------------------------
|
||||||
try: domain_licurl = tyto.domain_licurl
|
try: domain_licurl = db.domain_licurl
|
||||||
except: domain_licurl = ''
|
except: domain_licurl = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
|
ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl)
|
||||||
if ask:
|
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
|
domain_licurl = ask
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_licurl = "%s"'%domain_licurl)
|
'domain_licurl = "%s"'%domain_licurl
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# CSS Prefix
|
# CSS Prefix
|
||||||
#-----------
|
#-----------
|
||||||
try: domain_css = tyto.domain_css
|
try: domain_css = db.domain_css
|
||||||
except: domain_css = 'tyto'
|
except: domain_css = 'tyto'
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
|
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css)
|
||||||
if ask:
|
if ask:
|
||||||
if not ask.isalnum(): tyto.exiting("3", ask, True)
|
if not ask.isalnum(): logs.out("3", ask, True)
|
||||||
domain_css = ask.lower()
|
domain_css = ask.lower()
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_css = "%s"'%domain_css)
|
'domain_css = "%s"'%domain_css
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Titles webpage separator
|
# Titles webpage separator
|
||||||
#-------------------------
|
#-------------------------
|
||||||
try: domain_sep = tyto.domain_sep
|
try: domain_sep = db.domain_sep
|
||||||
except: domain_sep = "-"
|
except: domain_sep = "-"
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
|
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep)
|
||||||
if ask:
|
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
|
domain_sep = ask
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_sep = "%s"'%domain_sep)
|
'domain_sep = "%s"'%domain_sep
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Profile for rel="me" (optionnal)
|
# Profile for rel="me" (optionnal)
|
||||||
#---------------------------------
|
#---------------------------------
|
||||||
try: domain_relme = tyto.domain_relme
|
try: domain_relme = db.domain_relme
|
||||||
except: domain_relme = ''
|
except: domain_relme = ''
|
||||||
|
|
||||||
ask = ''
|
ask = ''
|
||||||
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
|
ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme)
|
||||||
if ask:
|
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
|
domain_relme = ask
|
||||||
|
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False,
|
||||||
'domain_relme = "%s"'%domain_relme)
|
'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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
# Sidebar Title
|
||||||
#--------------
|
#--------------
|
||||||
try: sidebar_title = tyto.sidebar_title
|
try: sidebar_title = db.sidebar_title
|
||||||
except: sidebar_title = tyto.trans[0][tyto.n]
|
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,
|
ask = ''
|
||||||
'sidebar_title = "%s"'%(sidebar_title))
|
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title)
|
||||||
|
if ask: sidebar_title = ask
|
||||||
|
if '"' in sidebar_title:
|
||||||
|
sidebar_title = sidebar_title.replace('"', '')
|
||||||
|
|
||||||
|
tyto.set_file(db.domain_conf, False,
|
||||||
|
'sidebar_title = "%s"'%(sidebar_title)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Sidebar Items
|
# Sidebar Items
|
||||||
#--------------
|
#--------------
|
||||||
try: sidebar_items = tyto.sidebar_items
|
try: sidebar_items = db.sidebar_items
|
||||||
except: sidebar_items = "6"
|
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)
|
|
||||||
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 = ''
|
||||||
ask = input(' ├ System server ? ("%s") '%domain_srv)
|
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items)
|
||||||
if ask:
|
if ask:
|
||||||
if not os.path.exists(srv): tyto.exiting("1", ask, True)
|
if not ask.isdigit(): logs.out("3", ask, True)
|
||||||
elif not domain_srv: tyto.exiting("255", '', True)
|
elif int(ask) in range(1,17): sidebar_items = int(ask)
|
||||||
|
|
||||||
root_srv_dom = '%s/%s'%(domain_srv, domain_short)
|
tyto.set_file(db.domain_conf, False,
|
||||||
srvs = '\nsrv_root = "%s/"\n'%domain_srv + \
|
'sidebar_items = %s'%(sidebar_items)
|
||||||
'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)
|
|
||||||
|
|
||||||
|
|
||||||
# Activate Domain after Resumed configuration ?
|
# Activate Domain after Resumed configuration ?
|
||||||
#----------------------------------------------
|
#----------------------------------------------
|
||||||
try: domain_active = tyto.domain_active
|
try: domain_active = db.domain_active
|
||||||
except: domain_active = False
|
except: domain_active = False
|
||||||
|
|
||||||
file = open(tyto.domain_conf, 'r').read()
|
file = open(db.domain_conf, 'r').read()
|
||||||
resume = ' │\n' + \
|
resume = ' │\n' + \
|
||||||
' ├──────────────────────────────────────┐\n' + \
|
' ├──────────────────────────────────────┐\n' + \
|
||||||
' │ Please, READ the configuration datas │\n' + \
|
' │ Please, READ the configuration datas │\n' + \
|
||||||
|
@ -403,16 +415,15 @@ def create_domain(target, option):
|
||||||
|
|
||||||
ask = input(' ├ Activate and prepare domain ? ')
|
ask = input(' ├ Activate and prepare domain ? ')
|
||||||
if not ask in ['y', 'Y']:
|
if not ask in ['y', 'Y']:
|
||||||
tyto.set_file(tyto.domain_conf, False,
|
tyto.set_file(db.domain_conf, False, '\ndomain_active = False')
|
||||||
'\ndomain_active = False')
|
logs.out("255", '', True)
|
||||||
tyto.exiting("255", '', True)
|
|
||||||
|
|
||||||
# Activate Domain
|
# Activate Domain
|
||||||
#----------------
|
#----------------
|
||||||
tyto.set_file(tyto.domain_conf, False, '\ndomain_active = True')
|
tyto.set_file(db.domain_conf, False, '\ndomain_active = True')
|
||||||
|
|
||||||
# Load config
|
# Load config
|
||||||
exec(open(tyto.domain_conf).read(),globals())
|
exec(open(db.domain_conf).read(),globals())
|
||||||
|
|
||||||
# Create folders from configuration file
|
# Create folders from configuration file
|
||||||
folders = (
|
folders = (
|
||||||
|
@ -434,9 +445,9 @@ def create_domain(target, option):
|
||||||
print(' │')
|
print(' │')
|
||||||
#create_sidebar(option)
|
#create_sidebar(option)
|
||||||
html.manage_configs('sidebar', 'Force')
|
html.manage_configs('sidebar', 'Force')
|
||||||
html.manage_configs('navbar', 'Force')
|
html.manage_configs('navbar', 'Force')
|
||||||
html.manage_configs('metas', 'Force')
|
html.manage_configs('metas', 'Force')
|
||||||
html.manage_configs('footer', 'Force')
|
html.manage_configs('footer', 'Force')
|
||||||
|
|
||||||
print(' │')
|
print(' │')
|
||||||
print(' ├──────────────────────────────────────┐')
|
print(' ├──────────────────────────────────────┐')
|
||||||
|
@ -448,12 +459,45 @@ def create_domain(target, option):
|
||||||
# sidebar load file translated #
|
# sidebar load file translated #
|
||||||
#------------------------------#
|
#------------------------------#
|
||||||
def create_sidebar(option):
|
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' + \
|
sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \
|
||||||
'# Type : fichier texte\n' + \
|
'# Type : fichier texte\n' + \
|
||||||
'# Description : Fichier appelé par "tyto sidebar"\n' + \
|
'# Description : Fichier appelé par "tyto sidebar"\n' + \
|
||||||
'# (Liste d\'articles)\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' + \
|
'# Comment : 1 URI de l\'article par ligne\n' + \
|
||||||
'# (depuis articles/)\n' + \
|
'# (depuis articles/)\n' + \
|
||||||
'# Ne commence pas par "/"\n' + \
|
'# Ne commence pas par "/"\n' + \
|
||||||
|
@ -464,11 +508,12 @@ def create_sidebar(option):
|
||||||
'# dir1/index.tyto\n' + \
|
'# dir1/index.tyto\n' + \
|
||||||
'# %s\n\n'%(15 * "-")
|
'# %s\n\n'%(15 * "-")
|
||||||
|
|
||||||
|
# English sidebar_load content
|
||||||
sdb_load_en = '# For: Tyto - Littérateur\n' + \
|
sdb_load_en = '# For: Tyto - Littérateur\n' + \
|
||||||
'# Type: Text file\n' + \
|
'# Type: Text file\n' + \
|
||||||
'# Description: file called with "tyto sidebar"\n' + \
|
'# Description: file called with "tyto sidebar"\n' + \
|
||||||
'# (articles\'s list)\n' + \
|
'# (articles\'s list)\n' + \
|
||||||
'# File: %s\n'%sidebar_load + \
|
'# File: %s\n'%db.sidebar_load + \
|
||||||
'# Comment: 1 article URI per line\n' + \
|
'# Comment: 1 article URI per line\n' + \
|
||||||
'# (from articles/)\n' + \
|
'# (from articles/)\n' + \
|
||||||
'# not begining with "/"\n' + \
|
'# not begining with "/"\n' + \
|
||||||
|
@ -479,31 +524,71 @@ def create_sidebar(option):
|
||||||
'# dir1/index.tyto\n' + \
|
'# dir1/index.tyto\n' + \
|
||||||
'# %s\n\n'%(15 * "-")
|
'# %s\n\n'%(15 * "-")
|
||||||
|
|
||||||
|
# Set language file
|
||||||
if tyto.n == 0: sdb_load = sdb_load_fr
|
if tyto.n == 0: sdb_load = sdb_load_fr
|
||||||
elif tyto.n == 1: sdb_load = sdb_load_en
|
elif tyto.n == 1: sdb_load = sdb_load_en
|
||||||
|
|
||||||
# Create new file, or ask if exists
|
# Create sidebar_load
|
||||||
ask = ' ├ Use default (empty) _configs/tyto.sidebar file ? '
|
if create_load:
|
||||||
log = ' ├ Create file: %s'%sidebar_load
|
# Create new file, or ask if exists
|
||||||
|
ask = ' ├ Use default (empty) sidebar configuration ? '
|
||||||
if os.path.exists(sidebar_load):
|
log = ' ├ Create file: %s'%db.sidebar_load
|
||||||
res = input(ask)
|
res = ''
|
||||||
if not res in ['y', 'Y']: return
|
if os.path.exists(db.sidebar_load):
|
||||||
|
res = input(ask)
|
||||||
tyto.set_file(sidebar_load, 'new', sdb_load)
|
if not res in ['y', 'Y']: return
|
||||||
print(log)
|
|
||||||
|
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 #
|
# navbar load file translated #
|
||||||
#-----------------------------#
|
#-----------------------------#
|
||||||
def create_navbar(option):
|
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' + \
|
nav_load_fr = '# Pour : Tyto - Littérateur\n' + \
|
||||||
'# Type : fichier texte\n' + \
|
'# Type : fichier texte\n' + \
|
||||||
'# Description : Fichier utilisé par "tyto wip"\n' + \
|
'# Description : Fichier utilisé par "tyto wip"\n' + \
|
||||||
'# (Liste des catégories)\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' + \
|
'# Comment : 1 nom de dossier par ligne *1\n' + \
|
||||||
'# (depuis articles/)\n' + \
|
'# (depuis articles/)\n' + \
|
||||||
'# Ne commence pas par "/"\n' + \
|
'# Ne commence pas par "/"\n' + \
|
||||||
|
@ -524,7 +609,7 @@ def create_navbar(option):
|
||||||
'# Type: Text file\n' + \
|
'# Type: Text file\n' + \
|
||||||
'# Description: file used with "tyto wip"\n' + \
|
'# Description: file used with "tyto wip"\n' + \
|
||||||
'# (categories\'s list)\n' + \
|
'# (categories\'s list)\n' + \
|
||||||
'# File : %s\n'%navbar_load + \
|
'# File : %s\n'%db.navbar_load + \
|
||||||
'# Comment: 1 folder name per line *1\n' + \
|
'# Comment: 1 folder name per line *1\n' + \
|
||||||
'# (from articles/)\n' + \
|
'# (from articles/)\n' + \
|
||||||
'# not begining with "/"\n' + \
|
'# not begining with "/"\n' + \
|
||||||
|
@ -541,16 +626,24 @@ def create_navbar(option):
|
||||||
'# about # infos about this website\n' + \
|
'# about # infos about this website\n' + \
|
||||||
'# %s\n\n'%(15 * "-")
|
'# %s\n\n'%(15 * "-")
|
||||||
|
|
||||||
if tyto.n == 0: nav_load = nav_load_fr
|
# Set language file
|
||||||
elif tyto.n == 1: nav_load = nav_load_en
|
if tyto.n == 0: nvb_load = nav_load_fr
|
||||||
|
elif tyto.n == 1: nvb_load = nav_load_en
|
||||||
|
|
||||||
# Create new file, or ask if exists
|
# Create sidebar_load
|
||||||
ask = ' ├ Use default (empty) _configs/tyto.navbar file ? '
|
if create_load:
|
||||||
log = ' ├ Create file: %s'%navbar_load
|
# Create new file, or ask if exists
|
||||||
|
ask = ' ├ Use default (empty) navbar configuration ? '
|
||||||
if os.path.exists(navbar_load):
|
log = ' ├ Create file: %s'%db.navbar_load
|
||||||
res = input(ask)
|
res = ''
|
||||||
if not res in ['y', 'Y']: return
|
if os.path.exists(db.navbar_load):
|
||||||
|
res = input(ask)
|
||||||
tyto.set_file(navbar_load, 'new', nav_load)
|
if not res in ['y', 'Y']: return
|
||||||
print(log)
|
|
||||||
|
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)
|
||||||
|
|
|
@ -16,23 +16,9 @@
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
import logs, db, tyto, domain
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
#==================================#
|
#==================================#
|
||||||
|
@ -40,16 +26,17 @@ navbar_file = '%snavbar.html'%srv_wip_tpl
|
||||||
# (sidebar, metas, footer, navbar) #
|
# (sidebar, metas, footer, navbar) #
|
||||||
#----------------------------------#
|
#----------------------------------#
|
||||||
def manage_configs(target, option):
|
def manage_configs(target, option):
|
||||||
|
# Arguments
|
||||||
args1 = ('metas', 'sidebar', 'footer', 'navbar')
|
args1 = ('metas', 'sidebar', 'footer', 'navbar')
|
||||||
args2 = ('-n', '-e', '-F', )
|
args2 = ('-n', '-e', '-F', '-c')
|
||||||
opts = ('New', 'Edit', 'Force')
|
opts = ('New', 'Edit', 'Force', 'Create')
|
||||||
|
|
||||||
|
# Check arguments (from form domain)
|
||||||
if target in args1: sys.argv[1] = target
|
if target in args1: sys.argv[1] = target
|
||||||
elif target and not option: option = 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:
|
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 = {
|
actions = {
|
||||||
'sidebar' : domain.create_sidebar,
|
'sidebar' : domain.create_sidebar,
|
||||||
|
@ -69,7 +56,7 @@ def set_page(post_db, target, article_bottom):
|
||||||
exec(open(post_db).read(),globals())
|
exec(open(post_db).read(),globals())
|
||||||
|
|
||||||
create_metas_page() # Include metas tags
|
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 = ''
|
metas_page = ''
|
||||||
scale = 'width=device-width, initial-scale=1.0'
|
scale = 'width=device-width, initial-scale=1.0'
|
||||||
all_tags = domain_tags + ',' + tags
|
all_tags = db.domain_tags + ',' + tags
|
||||||
post_url = domain_url + http_uri
|
|
||||||
css_file = 'template/style.css'
|
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_file = 'rss.xml'
|
||||||
rss_ref = 'type="application/rss+xml" ' + \
|
rss_ref = 'type="application/rss+xml" ' + \
|
||||||
'href="%s%s" title="RSS 2.0. %s %s %s'%(
|
'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_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])
|
en_date = tyto.set_en_date(date[0])
|
||||||
relme = '' # External URL in metas (if exists in config domain)
|
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">'%(
|
relme = '\n <link rel="me" type="text/html" href="%s">'%(
|
||||||
domain_relme
|
db.domain_relme
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set all raw HTML metas
|
# Set all raw HTML metas
|
||||||
|
@ -106,29 +95,29 @@ def create_metas_page():
|
||||||
metas = \
|
metas = \
|
||||||
' <meta charset="UTF-8" />\n' + \
|
' <meta charset="UTF-8" />\n' + \
|
||||||
' <meta name="viewport" content="%s" />\n'%scale + \
|
' <meta name="viewport" content="%s" />\n'%scale + \
|
||||||
' <meta name=”url” content=”%s” />\n'%domain_url + \
|
' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \
|
||||||
' <meta name="language" content="%s" />\n'%domain_lang + \
|
' <meta name="language" content="%s" />\n'%db.domain_lang + \
|
||||||
' <meta name="reply-to" content="%s" />\n'%domain_mail + \
|
' <meta name="reply-to" content="%s" />\n'%db.domain_mail + \
|
||||||
' <meta name="copyright" content="%s" />\n'%domain_license + \
|
' <meta name="copyright" content="%s" />\n'%db.domain_license + \
|
||||||
' <meta name="generator" content="%s" />\n'%Tyto + \
|
' <meta name="generator" content="%s" />\n'%tyto.Tyto + \
|
||||||
' <meta name="title" content="%s" />\n'%title + \
|
' <meta name="title" content="%s" />\n'%title + \
|
||||||
' <meta name="author" content="%s" />\n'%author + \
|
' <meta name="author" content="%s" />\n'%author + \
|
||||||
' <meta name="description" content="%s" />\n'%about + \
|
' <meta name="description" content="%s" />\n'%about + \
|
||||||
' <meta name="keywords" content="%s" />\n'%all_tags + \
|
' <meta name="keywords" content="%s" />\n'%all_tags + \
|
||||||
' <meta name="search_date" content="%s" />\n'%en_date + \
|
' <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="alternate" %s />\n'%(rss_ref) + \
|
||||||
' <link rel="stylesheet" %s /\n'%css_ref + \
|
' <link rel="stylesheet" %s />\n'%css_ref + \
|
||||||
' <link rel="shortcut icon" %s />'%icon_ref + \
|
' <link rel="shortcut icon" %s />\n'%icon_ref + \
|
||||||
' <!-- Open Graph data -->\n' + \
|
' <!-- 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:title" content="%s" />\n'%title + \
|
||||||
' <meta property="og:type" content="article" />\n' + \
|
' <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:description" content="%s" />\n'%about + \
|
||||||
' <meta property="og:image" content="%s" />\n'%snpic + \
|
' <meta property="og:image" content="%s" />\n'%snpic + \
|
||||||
'%s'%relme + \
|
'%s'%relme + \
|
||||||
'\n<!--# include virtual="/template/metas.html"-->\n' + \
|
'<!--# include virtual="/template/metas.html"-->\n' + \
|
||||||
' <title>%s</title>'%title
|
' <title>%s</title>'%title
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,38 +127,33 @@ def create_metas_page():
|
||||||
def create_main_page(target, article_bottom):
|
def create_main_page(target, article_bottom):
|
||||||
global main_page
|
global main_page
|
||||||
|
|
||||||
# Check needed footer.html
|
if not os.path.exists(db.wip_footer):
|
||||||
footer_file = '%sfooter.html'%srv_wip_tpl
|
logs.out("1", db.wip_footer, True)
|
||||||
if not os.path.exists(footer_file):
|
|
||||||
tyto.exiting("1", footer_file, True)
|
|
||||||
|
|
||||||
# Check optional metas.html
|
if not os.path.exists(db.wip_metas):
|
||||||
metas_file = '%smetas.html'%srv_wip_tpl
|
logs.out("24", '(HTML metas): %s'%db.wip_metas, False)
|
||||||
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)
|
|
||||||
|
|
||||||
# Create link for website's logo
|
# Create link for website's logo
|
||||||
#-------------------------------
|
#-------------------------------
|
||||||
logo_html = '<a href="/"\n' + \
|
logo_html = '<a href="/"\n' + \
|
||||||
'%stitle="%s %s logo: %s"\n'%(11 * " ",
|
'%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 * " ") + \
|
'%sid="site_logo_link">\n'%(11 * " ") + \
|
||||||
'%s<img src=""\n'%(10 * " ") + \
|
'%s<img src="%stemplate/%s"\n'%(10 * " ", sub_uri, db.domain_logo) + \
|
||||||
'%salt="logo: %s">\n'%(15 * " ", domain_title) + \
|
'%salt="logo: %s"\n'%(15 * " ", db.domain_title) + \
|
||||||
'%sid="site_logo_image">\n'%(15 * " ") + \
|
'%sid="site_logo_image" />\n'%(15 * " ") + \
|
||||||
'%s</a>'%(8 * " ")
|
'%s</a>'%(8 * " ")
|
||||||
|
|
||||||
|
# Create author and date publish section infos
|
||||||
|
create_html_infos_section('wip')
|
||||||
|
|
||||||
#-----------------------#
|
#-----------------------#
|
||||||
# Create main HTML Page #
|
# Create main HTML Page #
|
||||||
#-----------------------#
|
#-----------------------#
|
||||||
main_page = \
|
main_page = \
|
||||||
'<!Doctype html>\n' + \
|
'<!Doctype html>\n' + \
|
||||||
'<html lang="%s">\n'%domain_lang + \
|
'<html lang="%s">\n'%db.domain_lang + \
|
||||||
' <head>\n' + \
|
' <head>\n' + \
|
||||||
'%s\n'%metas + \
|
'%s\n'%metas + \
|
||||||
' </head>\n\n' + \
|
' </head>\n\n' + \
|
||||||
|
@ -183,48 +167,215 @@ def create_main_page(target, article_bottom):
|
||||||
' <a href="/"\n' + \
|
' <a href="/"\n' + \
|
||||||
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
|
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
|
||||||
' id="site_link">\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' + \
|
' </a>\n' + \
|
||||||
' <p id="site_about">%s</p>\n'%domain_about + \
|
' <p id="site_about">%s</p>\n'%db.domain_about + \
|
||||||
' </div>\n' + \
|
' </div>\n' + \
|
||||||
'<!--# include virtual="/template/navbar.html"-->\n' + \
|
'<!--# include virtual="/template/navbar.html"-->\n' + \
|
||||||
' </header>\n' + \
|
' </header>\n' + \
|
||||||
'\n' + \
|
'\n' + \
|
||||||
' <article id="article_main">\n' + \
|
' <article id="article_main">\n' + \
|
||||||
|
' <section id="article_infos">\n' + \
|
||||||
|
'%s\n'%html_infos + \
|
||||||
|
' </section>\n' + \
|
||||||
'%s\n'%article_bottom + \
|
'%s\n'%article_bottom + \
|
||||||
' </article>\n' + \
|
' </article>\n' + \
|
||||||
'\n' + \
|
'\n' + \
|
||||||
|
'<!--# include virtual="/template/sidebar.html"-->\n' + \
|
||||||
'<!--# include virtual="/template/footer.html"-->\n' + \
|
'<!--# include virtual="/template/footer.html"-->\n' + \
|
||||||
' </body>\n' + \
|
' </body>\n' + \
|
||||||
'</html>'
|
'</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 #
|
# Create HTML menu from root folders #
|
||||||
#------------------------------------#
|
#------------------------------------#
|
||||||
def create_navbar(option, target):
|
def create_navbar(target):
|
||||||
# Conditions to create navbar
|
if not db.domain_exists: return
|
||||||
if not domain_menubar:
|
|
||||||
tyto.exiting("26", 'domain_menubar', False)
|
# If content in sidebar, go True
|
||||||
if os.path.exists(navbar_file) and os.stat(navbar_file).st_size > 1:
|
navbar_new = False
|
||||||
tyto.set_file(navbar_file, 'new', '')
|
navbar_has = False
|
||||||
tyto.exiting('27', 'contents (navbar): %s'%navbar_file, False)
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Open HTML tags
|
|
||||||
empty = True
|
|
||||||
menu_html = '%s<nav id="site_menu">\n'%(6 * ' ') + \
|
menu_html = '%s<nav id="site_menu">\n'%(6 * ' ') + \
|
||||||
'%s<ul id="site_menu_items">'%(8 * ' ')
|
'%s<ul id="site_menu_items">'%(8 * ' ')
|
||||||
|
|
||||||
nolines = ('#', '/')
|
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
|
if not line or line.startswith(nolines): continue
|
||||||
|
|
||||||
|
navbar_has = True
|
||||||
|
# Get HTML title if defined (commented after)
|
||||||
if '#' in line:
|
if '#' in line:
|
||||||
direc = line.rsplit('#')[0].rstrip()
|
direc = line.rsplit('#')[0].rstrip()
|
||||||
title = '%stitle="%s"\n'%(15 * ' ', line.rsplit('#')[1].lstrip())
|
title = '%stitle="%s"\n'%(15 * ' ', line.rsplit('#')[1].lstrip())
|
||||||
|
@ -232,37 +383,101 @@ def create_navbar(option, target):
|
||||||
direc = line
|
direc = line
|
||||||
title = ''
|
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):
|
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
|
continue
|
||||||
|
|
||||||
# Add link to HTML structure
|
# Add link to HTML structure
|
||||||
empty = False
|
navbar_new = True
|
||||||
menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
|
menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
|
||||||
'%s<a class="site_menu_link"\n'%(12 * ' ') + \
|
'%s<a class="site_menu_link"\n'%(12 * ' ') + \
|
||||||
'%s'%title + \
|
'%s'%title + \
|
||||||
'%shref="/%s/">%s</a>\n'%(
|
'%shref="/%s/">%s</a>\n'%(
|
||||||
15 * ' ', direc, direc
|
15 * ' ', direc, direc
|
||||||
) + \
|
) + \
|
||||||
'%s</li>'%(10 * ' ')
|
'%s</li>'%(10 * ' ')
|
||||||
menu_html = '%s%s'%(menu_html, menu_item)
|
menu_html = '%s%s'%(menu_html, menu_item)
|
||||||
|
|
||||||
# Close HTML tags
|
# Close HTML tags
|
||||||
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
|
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', '')
|
|
||||||
else:
|
|
||||||
tyto.set_file(navbar_file, 'new', menu_html)
|
|
||||||
log_html = ' ├ Create file: %s'%navbar_file
|
|
||||||
print(log_html)
|
|
||||||
|
|
||||||
#========================================#
|
if not navbar_new:
|
||||||
# Create metas.html from tyto.metas.html #
|
if not navbar_has:
|
||||||
#----------------------------------------#
|
logs.out('29', '(navbar): %s'%db.navbar_load, True)
|
||||||
|
else:
|
||||||
|
logs.out('28', '(navbar)', True)
|
||||||
|
|
||||||
|
# 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):
|
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 = \
|
metas_tags = \
|
||||||
'<!-- Custom HTML metas for all pages\n' + \
|
'<!-- Custom HTML metas for all pages\n' + \
|
||||||
'# You can add/edit HTML tags\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="medium" content="website">\n' + \
|
||||||
'<meta name="revisit-after" content="3 days">'
|
'<meta name="revisit-after" content="3 days">'
|
||||||
|
|
||||||
# Create new file, or ask if exists
|
# Create metas_load file according to option
|
||||||
ask_load = ' ├ Use default _configs/tyto.metas.html ? '
|
#-------------------------------------------
|
||||||
log_load = ' ├ Create file: %s'%metas_load
|
|
||||||
create_load = True
|
|
||||||
|
|
||||||
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
|
|
||||||
create_html = True
|
|
||||||
|
|
||||||
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:
|
if create_load:
|
||||||
tyto.set_file(metas_load, 'new', metas_tags)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
print(log_load)
|
||||||
|
|
||||||
# Auto create if not metas.html in template/
|
# Create wip metas.html file according to option
|
||||||
# Create if option is 'New'
|
#-----------------------------------------------
|
||||||
res = ''
|
|
||||||
if os.path.exists(metas_html):
|
|
||||||
if option == 'New':
|
|
||||||
create_html = True
|
|
||||||
else:
|
|
||||||
res = input(ask_html)
|
|
||||||
if not res in ['y', 'Y']: create_html = False
|
|
||||||
|
|
||||||
if create_html:
|
if create_html:
|
||||||
user_file = open(metas_load, 'r').read()
|
ask_html = ' ├ Replace %s ? '%db.wip_metas
|
||||||
|
log_html = ' ├ Create file: %s'%db.wip_metas
|
||||||
|
user_metas = ''
|
||||||
|
metas_used = ('<meta ', '<link ')
|
||||||
|
|
||||||
|
res = ''
|
||||||
|
if os.path.exists(db.wip_metas):
|
||||||
|
res = input(ask_html)
|
||||||
|
if not res in ['y', 'Y']: return
|
||||||
|
|
||||||
|
user_file = open(db.metas_load, 'r').read()
|
||||||
|
|
||||||
for line in user_file.rsplit('\n'):
|
for line in user_file.rsplit('\n'):
|
||||||
if line.startswith(metas_used):
|
if line.startswith(metas_used):
|
||||||
if user_metas: user_metas = "%s\n %s"%(user_metas, line)
|
if user_metas: user_metas = "%s\n %s"%(user_metas, line)
|
||||||
else: user_metas = ' %s'%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)
|
print(log_html)
|
||||||
|
|
||||||
|
|
||||||
|
@ -353,93 +559,106 @@ def create_user_metas(option):
|
||||||
# Create generic footer from domain datas #
|
# Create generic footer from domain datas #
|
||||||
#-----------------------------------------#
|
#-----------------------------------------#
|
||||||
def create_user_footer(option):
|
def create_user_footer(option):
|
||||||
try:
|
if not db.domain_exists: return
|
||||||
tyto.domain_licurl
|
|
||||||
domain_licurl = tyto.domain_licurl
|
create_load = False # file in _configs
|
||||||
except:
|
create_html = False # file in template/
|
||||||
domain_licurl = "/"
|
|
||||||
|
# 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
|
# 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 = \
|
footer = \
|
||||||
'<!-- Default <footer> generated by %s -->\n'%Tyto + \
|
'<!-- Default <footer> generated by %s -->\n'%tyto.Tyto + \
|
||||||
'<footer id="footer_page">\n' + \
|
'<footer id="footer_page">\n' + \
|
||||||
' <div id="footer_infos">\n' + \
|
' <div id="footer_infos">\n' + \
|
||||||
' <a href="/"\n' + \
|
' <a href="/"\n' + \
|
||||||
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
|
' title="%s"\n'%(tyto.trans[1][tyto.n]) + \
|
||||||
' id="footer_title_link">\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' + \
|
' </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' + \
|
' </div>\n' + \
|
||||||
'\n' + \
|
'\n' + \
|
||||||
' <div id="footer_references">\n' + \
|
' <div id="footer_references">\n' + \
|
||||||
' <ul> id="footer_items"\n' + \
|
' <ul> id="footer_items"\n' + \
|
||||||
' <li id="fotter_item">\n' + \
|
' <li id="footer_item">\n' + \
|
||||||
' <a href="%s"\n'%domain_licurl + \
|
' <a href="%s"\n'%db.domain_licurl + \
|
||||||
' title="%s %s %s"\n'%(
|
' title="%s %s %s"\n'%(
|
||||||
tyto.trans[2][tyto.n],
|
tyto.trans[2][tyto.n],
|
||||||
domain_sep, domain_title) + \
|
db.domain_sep, db.domain_title) + \
|
||||||
' id="footer_item_link">%s</a>\n'%(
|
' id="footer_item_link">%s</a>\n'%(
|
||||||
domain_license) + \
|
db.domain_license) + \
|
||||||
' </li>\n' + \
|
' </li>\n' + \
|
||||||
' <li id="fotter_item">\n' + \
|
' <li id="footer_item">\n' + \
|
||||||
' <a href="%s"\n'%Tytoweb + \
|
' <a href="%s"\n'%tyto.Tytoweb + \
|
||||||
' title="%s"\n'%Tytowti + \
|
' title="%s"\n'%tyto.trans[5][tyto.n] + \
|
||||||
' id="footer_item_link">%s</a> %s\n'%(Tyto, Tytosrc) + \
|
' id="footer_item_link">%s</a> %s\n'%(tyto.Tyto, Tytosrc) + \
|
||||||
' </li>\n' + \
|
' </li>\n' + \
|
||||||
' </ul>\n' + \
|
' </ul>\n' + \
|
||||||
' </div>\n' + \
|
' </div>\n' + \
|
||||||
'</footer>'
|
'</footer>'
|
||||||
|
|
||||||
|
|
||||||
# Create new file, or ask if exists
|
# Create new default footer_load, 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
|
|
||||||
|
|
||||||
if create_load:
|
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)
|
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:
|
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'):
|
for line in user_file.rsplit('\n'):
|
||||||
if not line: continue
|
if not line: continue
|
||||||
if user_footer: user_footer = "%s\n %s"%(user_footer, line)
|
if user_footer: user_footer = "%s\n %s"%(user_footer, line)
|
||||||
else: user_footer = ' %s'%line
|
else: user_footer = ' %s'%line
|
||||||
|
|
||||||
tyto.set_file(footer_html, 'new', user_footer)
|
tyto.set_file(db.wip_footer, 'new', user_footer)
|
||||||
print(log_html)
|
print(log_load)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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))
|
|
@ -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
|
|
||||||
|
|
|
@ -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)
|
|
@ -20,79 +20,41 @@
|
||||||
import os, sys, subprocess, locale, base64, datetime
|
import os, sys, subprocess, locale, base64, datetime
|
||||||
from hashlib import blake2b
|
from hashlib import blake2b
|
||||||
|
|
||||||
# Second argument in command
|
import db, logs
|
||||||
#---------------------------
|
|
||||||
arguments = (
|
|
||||||
'-a', 'add',
|
|
||||||
'-R', 'remove',
|
|
||||||
'-e', 'edit',
|
|
||||||
'-n', 'new',
|
|
||||||
'-F', 'force',
|
|
||||||
'-d',
|
|
||||||
'again'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Settings
|
|
||||||
#---------
|
|
||||||
domain_active = False
|
domain_active = False
|
||||||
home_dir = os.path.expanduser('~')
|
home_dir = os.path.expanduser('~')
|
||||||
in_dir = os.getcwd()
|
in_dir = os.getcwd()
|
||||||
domain_conf = in_dir
|
domain_conf = in_dir
|
||||||
|
|
||||||
if '/articles' in in_dir:
|
if db.domain_exists:
|
||||||
domain_conf = in_dir.rsplit('/articles')[0]
|
db_dir = db.domain_db
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# Check if domain config file
|
# Set translations: french, english
|
||||||
#----------------------------
|
#----------------------------------
|
||||||
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
|
|
||||||
#------------------------------------
|
|
||||||
try: lang = domain_lang
|
try: lang = domain_lang
|
||||||
except: lang = locale.getdefaultlocale()[0].split('_')[0]
|
except: lang = locale.getdefaultlocale()[0].split('_')[0]
|
||||||
if lang.lower() == 'fr': n = 0
|
if lang.lower() == 'fr': n = 0
|
||||||
else: n = 1
|
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
|
# Translations French/English
|
||||||
trans = [
|
trans = [
|
||||||
('À l\'affiche !', 'Featured !'), #0
|
('À l\'affiche !', 'Featured !'), #0
|
||||||
('Accueil', 'Home'), #1
|
('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...)
|
# Words and template Tags (paragraphs, lists, bold, strong...)
|
||||||
# Used to check, and replace (wip) tags
|
# Used to check, and replace (wip) tags
|
||||||
# As base64 is used, do NOT set marker: =_ _=
|
# 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 = [
|
tpl_tags = [
|
||||||
('(', ')'),
|
('(', ')'),
|
||||||
('[', ']'),
|
('[', ']'),
|
||||||
|
@ -181,6 +136,7 @@ quote_tags = [
|
||||||
# Tags to check in header in content _TAG
|
# Tags to check in header in content _TAG
|
||||||
head_tags = ("image:", "raw:")
|
head_tags = ("image:", "raw:")
|
||||||
|
|
||||||
|
|
||||||
#=======#
|
#=======#
|
||||||
# TOOLS #
|
# TOOLS #
|
||||||
#=======#--------------------------------------------------------------
|
#=======#--------------------------------------------------------------
|
||||||
|
@ -209,7 +165,7 @@ def nowdate():
|
||||||
# Convert date DD/MM/YYYY to YYYY-MM-DD #
|
# Convert date DD/MM/YYYY to YYYY-MM-DD #
|
||||||
#---------------------------------------#
|
#---------------------------------------#
|
||||||
def set_en_date(date):
|
def set_en_date(date):
|
||||||
if domain_lang.lower() == 'fr':
|
if db.domain_lang.lower() == 'fr':
|
||||||
udate = date.rsplit('/')
|
udate = date.rsplit('/')
|
||||||
return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
|
return('%s-%s-%s'%(udate[2], udate[1], udate[0]))
|
||||||
|
|
||||||
|
@ -220,44 +176,59 @@ def set_en_date(date):
|
||||||
#-----------------------#
|
#-----------------------#
|
||||||
def get_db_post(target):
|
def get_db_post(target):
|
||||||
# Check if target file exists
|
# Check if target file exists
|
||||||
global uri_post
|
global uri_file
|
||||||
uri_post = '%s/%s'%(in_dir, target)
|
uri_file = '%s/%s'%(in_dir, target)
|
||||||
if not os.path.exists(uri_post):
|
if not os.path.exists(uri_file):
|
||||||
exiting("1", uri_post, True)
|
logs.out("1", uri_file, True)
|
||||||
|
|
||||||
global uri_root
|
# Get extension from target, set short uris
|
||||||
uri_root = uri_post
|
ext_src = os.path.splitext(target)
|
||||||
|
|
||||||
global uri_src
|
# Get uri after articles/ (no /...)
|
||||||
uri_src = '/' + uri_post.rsplit(domain_articles)[1]
|
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
|
global hash_post
|
||||||
hash_post = get_filesum(uri_post, True) # From content file
|
hash_post = get_filesum(uri_file, True)
|
||||||
|
|
||||||
global web_uri
|
# Hash from URI file
|
||||||
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, '')
|
|
||||||
|
|
||||||
global uri_id
|
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
|
global post_db
|
||||||
post_db = '%s/%s.conf'%(db_dir, uri_id)
|
post_db = '%s/%s.conf'%(db_dir, uri_id)
|
||||||
|
|
||||||
if os.path.exists(post_db): db_exists = True
|
if os.path.exists(post_db): db_exists = True
|
||||||
else : db_exists = False
|
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
|
# Check if null byte
|
||||||
if db_exists and os.stat(post_db).st_size < 1000:
|
if db_exists and os.stat(post_db).st_size < 1000:
|
||||||
os.remove(post_db)
|
os.remove(post_db)
|
||||||
exiting('23', post_db, False)
|
logs.out('23', post_db, False)
|
||||||
db_exists = False
|
db_exists = False
|
||||||
|
|
||||||
return(db_exists)
|
return(db_exists)
|
||||||
|
@ -267,6 +238,9 @@ def get_db_post(target):
|
||||||
# Open and edit a file #
|
# Open and edit a file #
|
||||||
#----------------------#
|
#----------------------#
|
||||||
def edit_file(edit_file):
|
def edit_file(edit_file):
|
||||||
|
if not os.path.exists(edit_file):
|
||||||
|
logs.out("1", edit_file, True)
|
||||||
|
|
||||||
file_edit = subprocess.run(
|
file_edit = subprocess.run(
|
||||||
[
|
[
|
||||||
'/usr/bin/nano',
|
'/usr/bin/nano',
|
||||||
|
@ -513,6 +487,10 @@ def exiting(nbr, value, out):
|
||||||
'27' : ':? %sDeleted%s %s'%(CY, CS, value),
|
'27' : ':? %sDeleted%s %s'%(CY, CS, value),
|
||||||
'28' : ':? %sUnused directory%s: %s'%(CY, CS, value),
|
'28' : ':? %sUnused directory%s: %s'%(CY, CS, value),
|
||||||
'29' : ':? %sEmpty configuration%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...'
|
'255' : ':| Maybe later...'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,15 @@
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
import os, re
|
|
||||||
|
|
||||||
import tyto, html
|
import os, re, shutil
|
||||||
|
import logs, db, tyto, html
|
||||||
|
|
||||||
def manage_wip(target, option):
|
def manage_wip(target, option):
|
||||||
global post_db, hash_post
|
global post_db, hash_post
|
||||||
|
|
||||||
|
if not db.domain_exists: return
|
||||||
|
|
||||||
#-----------------------------------------
|
#-----------------------------------------
|
||||||
# Option 'Again' to wip again, based on DB
|
# Option 'Again' to wip again, based on DB
|
||||||
#-----------------------------------------
|
#-----------------------------------------
|
||||||
|
@ -33,30 +35,26 @@ def manage_wip(target, option):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Load domain configuration DB
|
# Load domain configuration DB
|
||||||
exec(open(tyto.domain_conf).read(),globals())
|
for post_db in os.listdir(db.domain_db):
|
||||||
for post_db in os.listdir(domain_db):
|
|
||||||
if post_db.endswith('.conf'):
|
if post_db.endswith('.conf'):
|
||||||
# Load DB
|
# 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())
|
exec(open(post_db).read(),globals())
|
||||||
if not hash_wip: continue
|
if not hash_wip: continue
|
||||||
|
|
||||||
print("->", root_uri)
|
print("->", post_src)
|
||||||
hash_post = tyto.get_filesum(root_uri, True) # From content file
|
hash_post = tyto.get_filesum(post_src, True) # From content file
|
||||||
wip_article(root_uri)
|
wip_article(post_src)
|
||||||
return
|
return
|
||||||
|
|
||||||
#------------------------
|
#------------------------
|
||||||
# Per article with target
|
# Per article with target
|
||||||
#------------------------
|
#------------------------
|
||||||
# target needed
|
|
||||||
if not target: tyto.exiting("5", '', True)
|
|
||||||
|
|
||||||
# Article exists + has DB ?
|
# Article exists + has DB ?
|
||||||
db_exists = tyto.get_db_post(target)
|
db_exists = tyto.get_db_post(target)
|
||||||
target = tyto.uri_root
|
target = tyto.uri_file # tyto.uri_root
|
||||||
if not db_exists:
|
if not db_exists:
|
||||||
tyto.exiting("4", '', True)
|
logs.out("25", target, True)
|
||||||
|
|
||||||
# Load DB
|
# Load DB
|
||||||
post_db = tyto.post_db
|
post_db = tyto.post_db
|
||||||
|
@ -64,7 +62,7 @@ def manage_wip(target, option):
|
||||||
exec(open(post_db).read(),globals())
|
exec(open(post_db).read(),globals())
|
||||||
|
|
||||||
# Exit if article has changed
|
# 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
|
# In any case, if Force
|
||||||
if option == 'Force':
|
if option == 'Force':
|
||||||
|
@ -75,11 +73,11 @@ def manage_wip(target, option):
|
||||||
if hash_wip != hash_chk:
|
if hash_wip != hash_chk:
|
||||||
wip_article(target)
|
wip_article(target)
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(wip_uri):
|
if not os.path.exists(post_wip):
|
||||||
tyto.exiting("24", '(wip article): %s'%wip_uri, False)
|
logs.out("24", '(wip article): %s'%post_wip, False)
|
||||||
wip_article(target)
|
wip_article(target)
|
||||||
else:
|
else:
|
||||||
tyto.exiting("20", date_wip, True)
|
logs.out("19", date_wip, True)
|
||||||
|
|
||||||
|
|
||||||
#===================#
|
#===================#
|
||||||
|
@ -121,8 +119,19 @@ def wip_article(target):
|
||||||
|
|
||||||
# Get article DB in html.py
|
# Get article DB in html.py
|
||||||
html.set_page(post_db, target, article_bottom)
|
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
|
# Replace in DB hash_wip and date_wip
|
||||||
tyto.replace_in_db(post_db, 'wip', hash_post)
|
tyto.replace_in_db(post_db, 'wip', hash_post)
|
||||||
|
|
||||||
|
@ -190,7 +199,7 @@ def wip_words_tags():
|
||||||
for ln, line in enumerate(article_bottom.rsplit('\n')):
|
for ln, line in enumerate(article_bottom.rsplit('\n')):
|
||||||
# Open tag
|
# Open tag
|
||||||
if line.startswith(tyto.words_tags[10][0]):
|
if line.startswith(tyto.words_tags[10][0]):
|
||||||
set_css = tyto.get_css(line)
|
set_css = tyto.get_css(line)
|
||||||
article_bottom = article_bottom.replace(
|
article_bottom = article_bottom.replace(
|
||||||
article_bottom.rsplit('\n')[ln],
|
article_bottom.rsplit('\n')[ln],
|
||||||
tyto.words_tags[10][2]%set_css
|
tyto.words_tags[10][2]%set_css
|
||||||
|
@ -278,7 +287,7 @@ def wip_images():
|
||||||
for i in range(1, uniq_images + 1):
|
for i in range(1, uniq_images + 1):
|
||||||
image = 'image_%s'%i
|
image = 'image_%s'%i
|
||||||
target = width = height = False
|
target = width = height = False
|
||||||
set_css = tyto.domain_css + '_image'
|
set_css = db.domain_css + '_image'
|
||||||
imag_html = ''
|
imag_html = ''
|
||||||
|
|
||||||
if eval(image)[0] == values[0]:
|
if eval(image)[0] == values[0]:
|
||||||
|
@ -607,15 +616,17 @@ def wip_raws(target):
|
||||||
raw = 'raw_%s'%i
|
raw = 'raw_%s'%i
|
||||||
raw_file = open(
|
raw_file = open(
|
||||||
'%s%s'%(
|
'%s%s'%(
|
||||||
tyto.domain_articles, eval(raw)[1]
|
db.domain_articles, eval(raw)[1]
|
||||||
)
|
)
|
||||||
).read()
|
).read()
|
||||||
raw_html = '<pre class="%s" title="%s">\n'%(
|
raw_html = '<pre class="%s" title="%s">\n'%(
|
||||||
tyto.domain_css, eval(raw)[2]
|
db.domain_css, eval(raw)[2]
|
||||||
) + \
|
) + \
|
||||||
' <code class="bcode">'
|
' <code class="bcode">'
|
||||||
for line in raw_file.rsplit('\n'):
|
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)
|
raw_html = '%s\n </code>\n</pre>'%(raw_html)
|
||||||
article_bottom = article_bottom.replace(
|
article_bottom = article_bottom.replace(
|
||||||
|
|
Loading…
Reference in New Issue