diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto
index 646a9de..70d747a 100755
--- a/src/usr/bin/tyto
+++ b/src/usr/bin/tyto
@@ -26,15 +26,16 @@
import sys
sys.path.insert(0, '/var/lib/tyto/program')
+
#====================#
# MAIN #
# Treat Arguments #
#--------------------#-------------------------------------------------
import logs
+
if not __name__ == "__main__":
logs.out("14", '', True)
-
# Check arguments
import args
action = args.set_action()
@@ -42,22 +43,24 @@ target = args.set_target()
# Command start argument
-import check, domain, html, new, publish, show, wip, infos
+import check, form, html, new, publish, show, wip, infos
actions = {
- 'check' : check.manage_check,
- 'help' : infos.tyto,
- 'edit' : show.manage_show,
- 'edit-db' : show.manage_show,
- 'edit-wip' : show.manage_show,
- 'edit-www' : show.manage_show,
- 'new' : new.manage_new,
- 'publish' : publish.manage_publish,
- 'show' : show.manage_show,
- 'show-db' : show.manage_show,
- 'show-wip' : show.manage_show,
- 'show-www' : show.manage_show,
- 'template' : publish.manage_publish,
- 'wip' : wip.manage_wip,
+ 'check' : check.manage,
+ 'help' : infos.tyto,
+ 'edit' : show.manage,
+ 'edit-about' : show.manage,
+ 'edit-db' : show.manage,
+ 'edit-wip' : show.manage,
+ 'edit-www' : show.manage,
+ 'new' : new.manage,
+ 'publish' : publish.manage_publish,
+ 'show' : show.manage,
+ 'show-about' : show.manage,
+ 'show-db' : show.manage,
+ 'show-wip' : show.manage,
+ 'show-www' : show.manage,
+ 'template' : publish.manage_publish,
+ 'wip' : wip.manage_wip,
}
diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py
index b37813d..1d8f800 100644
--- a/src/var/lib/tyto/program/args.py
+++ b/src/var/lib/tyto/program/args.py
@@ -27,12 +27,14 @@ actions = \
(
'check',
'edit',
+ 'edit-about',
'edit-db',
'edit-wip',
'edit-www',
'help',
'new',
'show',
+ 'show-about',
'show-db',
'show-wip',
'show-www',
diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py
index 7b23dd5..63e4d92 100644
--- a/src/var/lib/tyto/program/check.py
+++ b/src/var/lib/tyto/program/check.py
@@ -18,37 +18,65 @@
#**********************************************************************
# Import needed libs
-import sys, os, re, datetime
+import time, importlib, sys, os, re, datetime
from datetime import datetime
from time import gmtime, strftime
-import time, importlib
-import args, logs, db, domain, tyto
+import args, logs, dom, db, form, tyto
+
+# load locale translation
+trans_dir = '/var/lib/tyto/translations'
+sys.path.insert(0, trans_dir)
+
+
+# Get default system language
+# or set "en" (english) if no translation file
+try:
+ lang_site = locale.getdefaultlocale()[0].split('_')[0]
+ os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
+except:
+ lang_site = 'en'
+
+lang_sys = lang_site
+
+# Set language site/form from configuration domain
+# or set default english if not known
+try:
+ dom.exists
+ lang_site = dom.lang_site
+ os.path.exists('%s/site_%s.py'%(trans_dir, lang_site))
+ tr = importlib.import_module('site_%s'%lang_site, package=None)
+except:
+ tr = importlib.import_module('site_%s'%lang_site, package=None)
post_err = False
+
#=========================#
# Manage Argument 'check' #
# Start checking article #
#-------------------------#--------------------------------------------
-def manage_check(target):
- domain.domain_needed()
+def manage(target):
+ dom.valid()
# target needed
if not target:
- logs.out("5", '', True)
+ logs.out("5", args.action, True)
+
+ elif not db.post:
+ sys.exit(1)
elif not target in args.multi_chk \
- and db.db_exists \
+ and db.exists \
and not db.old_chk:
- logs.out("20", db.date_chk, False)
- ask = ' ├ Check again this article ? '
+ logs.out("20", '%s > %s'%(db.date_chk, db.uri_file), False)
+ ask = ''
try:
- res = input(ask)
+ ask = input(' ├ %s%s '%(tr.check_a, tr.q))
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
- if not res in ['y', 'Y']:
+ if not ask in form.answer_yes:
return
check_process(target)
@@ -59,7 +87,7 @@ def manage_check(target):
check_process(target)
if post_err and not target in args.multi_chk:
- logs.out("7", '', True)
+ logs.out("7", db.uri_file, True)
#==============================================#
@@ -94,7 +122,7 @@ def check_all(option):
# Check articles process #
#------------------------#
def check_process(target):
- if not db.post_exists: sys.exit(1)
+ if not db.post: sys.exit(1)
global post_bottom, article_bottom
global post_words
@@ -104,7 +132,7 @@ def check_process(target):
post_err = False
# Set values for wip and www from DB
- if db.db_exists:
+ if db.exists:
date_wip = db.date_wip
hash_wip = db.hash_wip
date_www = db.date_www
@@ -116,10 +144,11 @@ def check_process(target):
# Get uri after articles/ (no starting / in value)
global src_post_short_uri, srv_post_short_uri, direc_src
global srv_post_wip_uri, srv_post_www_uri
- src_post_short_uri = db.uri_file.rsplit(db.domain_articles)[1]
+
+ src_post_short_uri = db.uri_file.rsplit(dom.articles_d)[1]
srv_post_short_uri = src_post_short_uri.replace(ext_src[1], '.html')
- srv_post_wip_uri = db.srv_wip + srv_post_short_uri
- srv_post_www_uri = db.srv_www + srv_post_short_uri
+ srv_post_wip_uri = dom.srv_wip + srv_post_short_uri
+ srv_post_www_uri = dom.srv_www + srv_post_short_uri
direc_src = src_post_short_uri.split("/")[-1]
direc_src = src_post_short_uri.rsplit(direc_src)[0]
@@ -127,23 +156,26 @@ def check_process(target):
global sub_uri
sub_uri = db.uri_file.rsplit('articles/')[1]
sub_nbr = sub_uri.count('/')
- if sub_nbr == 0 : sub_uri = './'
- else: sub_uri = sub_nbr * '../'
+ 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/%s"%(db.domain_www_url, direc_src)
- http_wip = '%s/%s'%(db.domain_wip_url, direc_src)
+ http_www = "%s/%s"%(dom.www_url, direc_src)
+ http_wip = '%s/%s'%(dom.wip_url, direc_src)
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)
+ http_www = "%s/%s"%(dom.www_url, srv_post_short_uri)
+ http_wip = '%s/%s'%(dom.wip_url, srv_post_short_uri)
# Start checking processes
#-------------------------
- file_to_string(db.uri_file)
+ # Convert file to string
+ # Also check for separator and empty article
+ file_to_string()
- # Specific to inline-code: check markers on same line
+ # Check for icodes, bcodes, quotes
+ # check icodes marks on same line
if_icodes_bcodes_quotes(post_bottom)
# Protect block-codes and quotes
@@ -156,25 +188,34 @@ def check_process(target):
tyto.protect_icodes(post_bottom)
post_bottom = tyto.protect_article
+ # Check tags configuration
+ check_headers(post_header.rsplit('\n'))
+ if post_err: return
- # Count words in article. Quotes, block-codes, icode = 1 per each
- post_words = len(post_bottom.strip().split(" "))
-
# Check for valid contents
check_content(post_bottom)
- post_bottom = post_bottom.rsplit('\n')
- #post_header = post_header.rsplit('\n')
- check_headers(post_header.rsplit('\n'))
-
- # Exit if unused needed tags
+ # Remove db (if exists) on post error and return
if post_err:
- if db.db_exists and os.path.exists(db.post_db):
- os.remove(db.post_db)
- #logs.out("7", '', False)
+ if db.exists and tyto.exists(db.config):
+ os.remove(db.config)
return
+
+
+ # Count words in article.
+ # Quotes, block-codes, icode = 1 per each
+ # At db creation, remove title numbers
+ post_words = 0
+ for line in post_bottom.rsplit("\n"):
+ if not line \
+ or line.startswith(tyto.nolinewords) \
+ or line.startswith("#") and \
+ not line.startswith(tyto.titles_tags):
+ continue
+ post_words = post_words + len(line.strip().split(" "))
- # No error
+
+ # Create article's database
create_database()
@@ -182,12 +223,12 @@ def check_process(target):
# Create string article from file #
# Check if separator or exit #
#---------------------------------#
-def file_to_string(post_file):
+def file_to_string():
global article, post_header, post_bottom
post_header = post_bottom = ''
- sep = False
- article = open(post_file, 'r').read()
+ sep = content = False
+ article = open(db.uri_file, 'r').read()
for line in article.rsplit('\n'):
if line.startswith('-----'):
@@ -195,6 +236,7 @@ def file_to_string(post_file):
continue
if sep:
+ if line: content = True
if not post_bottom: post_bottom = line
else: post_bottom = '%s\n%s'%(post_bottom, line)
else:
@@ -203,7 +245,12 @@ def file_to_string(post_file):
# Check if separator or exit
if not sep:
- logs.out("6", '-----', True)
+ logs.out("6", db.uri_file, True)
+
+ if not content:
+ if db.exists and tyto.exists(db.config):
+ os.remove(db.config)
+ logs.out("18", db.uri_file, True)
#=============================================#
@@ -212,8 +259,9 @@ def file_to_string(post_file):
# Stats for titles, quotes, bcodes, uniq_ancs #
#---------------------------------------------#
def if_icodes_bcodes_quotes(post_bottom):
- global icode, quote, bcode
+ global icode, quote, bcode, post_err
global nbr_titles, nbr_quotes, nbr_bcodes, nbr_ancs
+
icode = quote = in_quote = bcode = in_bcode = False
nbr_titles = nbr_quotes = nbr_bcodes = nbr_ancs = 0
@@ -255,10 +303,13 @@ def if_icodes_bcodes_quotes(post_bottom):
icode_m1 = line.count(tyto.words_tags[9][0])
icode_m2 = line.count(tyto.words_tags[9][1])
if icode_m1 != icode_m2:
- logs.out("8", 'inline-code: line %s. %s %s'%(ln,
- tyto.words_tags[9][0], tyto.words_tags[9][1]
- ), True
+ print(" ├─", line)
+ logs.out("8", 'icode: L=%s. "%s %s" > %s'%(ln,
+ tyto.words_tags[9][0], tyto.words_tags[9][1],
+ db.uri_file
+ ), False
)
+ post_err = True
else:
icode = True
@@ -325,10 +376,10 @@ def check_headers(post_header):
if line.startswith(tag):
if date: continue
date = line.rsplit(tag)[1].lstrip()
- check_date(date, ln)
+ check_date(date, ln, line)
if not post_err:
- if tyto.n == 0:
+ if lang_site == 'fr':
date = date.rsplit('-')
date = date[2] + '/' + date[1] + '/' + date[0]
date = (date, date_check)
@@ -338,18 +389,19 @@ def check_headers(post_header):
# Check needed tags #
#-------------------#
# Set needed tags
- need_headers = {
- tyto.headers[0] : title,
- tyto.headers[1] : about,
- tyto.headers[2] : author,
- tyto.headers[3] : tags,
- tyto.headers[4] : date
- }
+ need_headers = \
+ {
+ tyto.headers[0] : title,
+ tyto.headers[1] : about,
+ tyto.headers[2] : author,
+ tyto.headers[3] : tags,
+ tyto.headers[4] : date
+ }
# Check if set needed tags
for tag in need_headers:
if not need_headers[tag]:
- logs.out("6", tag, False)
+ logs.out("17", tag, False)
post_err = True
@@ -560,7 +612,7 @@ def check_headers(post_header):
#----------------------------------------------
if snpic_name: continue
- snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo)
+ snpic_url = '%s/template/%s'%(dom.www_url, dom.logo)
tag = tyto.headers[11] # snpic:
if line.startswith(tag):
snpic_name = post_header[ln - 1].rsplit(tag)[1].lstrip()
@@ -570,7 +622,7 @@ def check_headers(post_header):
image_uri = post_header[ln].lstrip()
check_file_uri('image', image_uri, ln + 1)
snshare = True
- snpic_url = '%s%s'%(db.domain_www_url, web_uri)
+ snpic_url = '%s%s'%(dom.www_url, web_uri)
break
if not snshare:
@@ -582,7 +634,7 @@ def check_headers(post_header):
# Check Date format and validity #
# Create False date_check #
#--------------------------------#
-def check_date(date, ln):
+def check_date(date, ln, line):
global post_err, date_check
# Check if article date is valid (True)
@@ -592,7 +644,10 @@ def check_date(date, ln):
bool(datetime.strptime(date, fmt_article))
except ValueError:
post_err = True
- logs.out("3", 'Line %s (date, %s)'%(ln, date), False)
+ print(" ├─", line)
+ logs.out("3", 'date: L=%s. "%s" > %s'%(
+ ln, date, db.uri_file
+ ), False)
# Create date_check (epoch) from article's Date + now TIME
if not post_err:
@@ -626,7 +681,7 @@ def check_file_uri(filetype, filename, ln):
fileuri = post_dir + filename
# Check if file exists
- if not os.path.exists(fileuri):
+ if not tyto.exists(fileuri):
logs.out("1", "Line %s, %s"%(ln, fileuri), False)
post_err = True
return
@@ -640,6 +695,9 @@ def check_file_uri(filetype, filename, ln):
def check_content(post_bottom):
global post_err
+ #print("post_bottom")
+ #print(post_bottom)
+
# Check tags for words (strongs, italics...)
# Set stats for each one
#-------------------------------------------
@@ -766,12 +824,12 @@ def create_database():
'date_www = "%s"\n'%date_www + \
'hash_www = "%s"\n'%hash_www + \
'\n# Post configuration from needed tags\n' + \
- 'title = "%s"\n'%title + \
- 'about = "%s"\n'%about + \
- 'author = "%s"\n'%author + \
- 'tags = "%s"\n'%tags + \
- 'date = %s\n'%str(date) + \
- 'snpic = "%s"\n'%snpic_url + \
+ 'title = "%s"\n'%title + \
+ 'about = "%s"\n'%about + \
+ 'author = "%s"\n'%author + \
+ 'tags = "%s"\n'%tags + \
+ 'date = %s\n'%str(date) + \
+ 'snpic = "%s"\n'%snpic_url + \
'\n# Used files\n' + \
'uris = (%s)\n'%files_post + \
'\n# Post configuration from optional tags'
@@ -806,16 +864,19 @@ def create_database():
database, i, globals()['raw_%s'%i]
)
+ # Count real words
+ stat_words = post_words - nbr_titles
+
db_stats = '\n# Statistics from optional tags\n' + \
- 'uniq_anchors = %d\n'%nbr_ancs + \
- 'uniq_abbrs = %d\n'%stat_abbrs + \
- 'uniq_links = %d\n'%stat_links + \
- 'uniq_images = %d\n'%stat_images + \
- 'uniq_files = %d\n'%stat_files + \
- 'uniq_raws = %d\n'%stat_raws + \
+ 'uniq_anchors = %d\n'%nbr_ancs + \
+ 'uniq_abbrs = %d\n'%stat_abbrs + \
+ 'uniq_links = %d\n'%stat_links + \
+ 'uniq_images = %d\n'%stat_images + \
+ 'uniq_files = %d\n'%stat_files + \
+ 'uniq_raws = %d\n'%stat_raws + \
'\n# Statistics from post content\n' + \
'stat_tags = %d\n'%post_tags + \
- 'stat_words = %d\n'%post_words + \
+ 'stat_words = %d\n'%stat_words + \
'stat_titles = %d\n'%nbr_titles + \
'stat_paragraphs = %d\n'%post_paragraphs + \
'stat_anchors = %d\n'%post_anchors + \
@@ -834,8 +895,8 @@ def create_database():
database = '%s\n%s'%(database, db_stats)
- tyto.set_file(db.post_db, 'new', database)
- logs.out("21", '', False)
+ tyto.set_file(db.config, 'new', database)
+ logs.out("21", db.uri_file, False)
#=====================#
diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py
index a1414dd..635867b 100644
--- a/src/var/lib/tyto/program/db.py
+++ b/src/var/lib/tyto/program/db.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
-# Type: DBs tools
-# Description: Search DBs (domain + post) and exec
+# Type: DB for article
+# Description: Search article database and exec
# file: db.py
# Folder: /var/lib/tyto/program/
# By echolib (XMPP: im@echolib.re)
@@ -17,259 +17,116 @@
#**********************************************************************
-import os, sys
-import args, logs, tyto, domain, wip, publish
+import os
-action = args.action
-target = args.target
-
-
-#======================#
-#----------------------#
-# DOMAIN Configuration #
-#----------------------#
-#======================#
-# Settings
-#---------
-domain_active = False
-incomplete_domain = False
-db_exists = post_exists = db_remove = False
-no_chk = no_wip = no_www = False
-old_chk = old_wip = old_www = False
-file_wip = file_www = False
-sync_srvs = False
-home_dir = os.path.expanduser('~')
+import args, dom, form, tyto, logs
+remove = exists = post = corrupt = False
try: in_dir = os.getcwd()
except: logs.out("13", '', True)
-domain_conf = in_dir
-
-
-# Settings for domain, check if db is not corrupted
-domain_values = \
-(
- 'domain_dir',
- 'domain_conf',
- 'domain_articles',
- 'domain_files',
- 'domain_images',
- 'articles_db',
- 'navbars_dir',
- 'navbar_load',
- 'sidebar_load',
- 'metas_load',
- 'footer_load',
- 'domain_short',
- 'domain_www_url',
- 'domain_wip_url',
- 'domain_title',
- 'domain_date',
- 'domain_about',
- 'domain_lang',
- 'domain_mail',
- 'domain_tags',
- 'domain_logo',
- 'domain_license',
- 'domain_licurl',
- 'domain_legalurl',
- 'domain_termsurl',
- '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',
- 'www_rss',
- 'domain_rss',
- 'domain_rssitems',
- 'domain_footer_about',
- 'domain_active',
-)
-
-
-# Values in article's database
-article_values = \
-(
-'post_id',
-'post_src',
-'post_wip',
-'post_www',
-'direc_src',
-'short_src',
-'short_srv',
-'sub_uri',
-'http_wip',
-'http_www',
-'date_chk',
-'hash_chk',
-'date_wip',
-'hash_wip',
-'date_www',
-'hash_www',
-'title',
-'about',
-'author',
-'tags',
-'date',
-'snpic',
-'uris',
-'uniq_anchors',
-'uniq_abbrs',
-'uniq_links',
-'uniq_images',
-'uniq_files',
-'uniq_raws',
-'stat_tags',
-'stat_words',
-'stat_titles',
-'stat_paragraphs',
-'stat_anchors',
-'stat_strongs',
-'stat_bolds',
-'stat_emphasis',
-'stat_italics',
-'stat_dels',
-'stat_underlines',
-'stat_cites',
-'stat_customs',
-'stat_icodes',
-'stat_bcodes',
-'stat_quotes',
-'stat_lists'
-)
-
-# 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: 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
-
-stdout = '%s %s domain "%s" in %s' # Show domain status
-
-if domain_exists:
- exec(open(domain_conf).read())
-
- # Check if domain conf is valid
- for conf in domain_values:
- try:
- eval(str(conf))
- except:
- incomplete_domain = True
- logs.out("10", conf, False)
-
- # Stop process if error, continue if 'new'
- if not action in args.pass_actions:
- if incomplete_domain: sys.exit(1)
-
- try: domain_active
- except: domain_active = False
-
- # Internal process. No need to show when import reloaded
- try:
- domain_show
- except:
- 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)
- domain_show = True
-
-else:
- logs.out("43", domain_conf, False)
- domain_show = True
-
-
-
-#==================#
-#------------------#
-# ARTICLE DATABASE #
-#------------------#
-#================================#
-# Get post DB from target #
-# Conditions from command line #
-# Get some post settings fom uri #
-#--------------------------------#
if args.target \
and args.action in args.pass_db \
and not args.target in args.pass_targets:
# Domain must be valid
- domain.domain_needed()
+ dom.valid()
uri_file = '%s/%s'%(in_dir, args.target)
uri_id = tyto.get_filesum(uri_file, False)
# DB
- post_db = '%s%s.conf'%(articles_db, uri_id)
- if os.path.exists(post_db): db_exists = True
- else: db_exists = False
-
+ config = '%s%s.config'%(dom.articles_db_d, uri_id)
+ if tyto.exists(config):
+ exists = True
+ exec(open(config).read())
+ else:
+ exists = False
+
# Article
- if os.path.exists(uri_file):
- post_exists = True
+ if tyto.exists(uri_file):
+ post = True
hash_post = tyto.get_filesum(uri_file, True)
else:
- post_exists = False
+ post = False
+ remove = True
logs.out("1", uri_file, False)
# Remove DB if unused source article or corrupted DB
- if db_exists:
- if not post_exists:
- db_remove = True
- elif os.stat(post_db).st_size < 1000:
- db_remove = True
- logs.out('23', post_db, False)
- else:
- exec(open(post_db).read(),globals())
-
- # Check if database conf is valid
- for conf in article_values:
- try: eval(str(conf))
- except: db_remove = True
+ if exists:
+ # Check if database config is valid (contains values)
+ values = \
+ (
+ 'post_id',
+ 'post_src',
+ 'post_wip',
+ 'post_www',
+ 'direc_src',
+ 'short_src',
+ 'short_srv',
+ 'sub_uri',
+ 'http_wip',
+ 'http_www',
+ 'date_chk',
+ 'hash_chk',
+ 'date_wip',
+ 'hash_wip',
+ 'date_www',
+ 'hash_www',
+ 'title',
+ 'about',
+ 'author',
+ 'tags',
+ 'date',
+ 'snpic',
+ 'uris',
+ 'uniq_anchors',
+ 'uniq_abbrs',
+ 'uniq_links',
+ 'uniq_images',
+ 'uniq_files',
+ 'uniq_raws',
+ 'stat_tags',
+ 'stat_words',
+ 'stat_titles',
+ 'stat_paragraphs',
+ 'stat_anchors',
+ 'stat_strongs',
+ 'stat_bolds',
+ 'stat_emphasis',
+ 'stat_italics',
+ 'stat_dels',
+ 'stat_underlines',
+ 'stat_cites',
+ 'stat_customs',
+ 'stat_icodes',
+ 'stat_bcodes',
+ 'stat_quotes',
+ 'stat_lists'
+ )
+ for value in values:
+ try:
+ eval(str(value))
+ except:
+ remove = True
+ corrupt = True
+ break
- if db_remove:
- os.remove(post_db)
- db_exists = False
- logs.out("23", post_db, False)
+ if remove and exists:
+ os.remove(config)
+ exists = False
+ logs.out("23", config, False)
+ file_wip = file_www = False
+ old_chk = old_wip = old_www = False
+ no_chk = no_wip = no_www = False
+ sync_srvs = False
# Set Statuses for chk, wip, www
- if db_exists:
+ if exists:
# File exists on servers
- if os.path.exists(post_wip): file_wip = True
- if os.path.exists(post_www): file_www = True
+ if tyto.exists(post_wip): file_wip = True
+ if tyto.exists(post_www): file_www = True
# Source article has changed
if hash_post != hash_chk: old_chk = True
diff --git a/src/var/lib/tyto/program/dom.py b/src/var/lib/tyto/program/dom.py
new file mode 100644
index 0000000..ac2d4c9
--- /dev/null
+++ b/src/var/lib/tyto/program/dom.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env python3
+# Name: Tyto - Littérateur
+# Type: DB for domain
+# Description: Search domain datas and get statuses
+# file: dom.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, importlib, locale
+
+lib = 'tyto_domain'
+exists = incomplete = active = valid = shortname = False
+local_user = articles_db = activated = False
+hole = False
+
+# Set current directory
+try: in_dir = os.getcwd()
+except: hole = True
+
+if not hole:
+ home_dir = os.path.expanduser('~')
+
+ # Set configuration domain directory
+ folder = in_dir
+ if '/articles' in in_dir:
+ folder = in_dir.rsplit('/articles')[0]
+
+ # Set configuration domain file
+ config = '%s/tyto_domain.py'%folder
+
+ # Set exists if configuration file
+ if os.path.exists(config):
+ exists = True
+ exec(open(config).read())
+
+ # For logs: show uri if not shortname known
+ try: shortname
+ except: shortname = config
+
+ if activated:
+ active = True
+ # Settings for domain, check if db is not corrupted
+ values = \
+ (
+ 'directory',
+ 'database',
+ 'local_user',
+ 'lang_sys',
+ 'lang_logs',
+ 'articles_db_d',
+ 'articles_d',
+ 'files_d',
+ 'images_d',
+ 'modules_d',
+ 'navbar_f',
+ 'sidebar_f',
+ 'metas_f',
+ 'footer_f',
+ 'footer_about_f',
+ 'shortname',
+ 'www_url',
+ 'wip_url',
+ 'srv_root',
+ 'srv_domain',
+ 'srv_wip',
+ 'srv_wip_tpl_d',
+ 'srv_wip_images_d',
+ 'srv_wip_files_d',
+ 'srv_www',
+ 'srv_www_tpl_d',
+ 'srv_www_images_d',
+ 'srv_www_files_d',
+ 'wip_navbar_f',
+ 'wip_sidebar_f',
+ 'wip_metas_f',
+ 'wip_footer_f',
+ 'www_navbar_f',
+ 'www_sidebar_f',
+ 'www_metas_f',
+ 'www_footer_f',
+ 'wip_logo_f',
+ 'www_logo_f',
+ 'www_rss_f',
+ 'logo',
+ 'rss',
+ 'rss_items',
+ 'title',
+ 'date',
+ 'about',
+ 'lang_site',
+ 'mail',
+ 'tags',
+ 'license',
+ 'license_url',
+ 'legal_url',
+ 'terms_url',
+ 'css',
+ 'sep',
+ 'article_code',
+ 'relme',
+ 'sidebar_title',
+ 'sidebar_items',
+ 'activated'
+ )
+
+ err_val = (()) # Make a list from values error
+ dir_new = (()) # Make a list for directories to create
+ for value in values:
+ try:
+ eval(str(value))
+ except:
+ err_val = err_val + ((value),)
+ incomplete = True
+ active = False
+
+ # Check if directory exists
+ if not incomplete and value.endswith('_d'):
+ if not os.path.exists(eval(str(value))):
+ os.makedirs(eval(str(value)), exist_ok=True)
+ dir_new = dir_new + ((eval(str(value))),)
+
+ if articles_db and not os.path.exists(articles_db):
+ incomplete = True
+
+ #==============================================#
+ # When an active and complete domain is needed #
+ #----------------------------------------------#
+ if exists and not incomplete and active: valid = True
+
+
+#====================================#
+# Check if domain is valid and ready #
+#------------------------------------#
+def valid():
+ if incomplete: sys.exit(41)
+ elif not active: sys.exit(42)
+ elif not exists: sys.exit(1)
diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py
deleted file mode 100644
index 557bc31..0000000
--- a/src/var/lib/tyto/program/domain.py
+++ /dev/null
@@ -1,1037 +0,0 @@
-#!/usr/bin/env python3
-# Name: Tyto - Littérateur
-# Type: Global functions for domain
-# Description: Create/edit a domain
-# file: domain.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:
-#----------------------------------------------------------------------
-
-#**********************************************************************
-
-from datetime import datetime
-import os, sys, locale, importlib
-
-import logs, db, tyto, html
-
-
-#==========================#
-# Manage Argument 'domain' #
-# target: 3rd argument #
-#--------------------------#
-def manage_domain(target):
- if not db.domain_exists or db.incomplete_domain:
- create_domain(target)
- else:
- try:
- ask = input(' ├ Edit the domain configuration with the form ? ')
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if ask in ['y', 'Y']: create_domain(target)
- else: logs.out("255", '', True)
-
-
-#==============================================#
-# When an active and complete domain is needed #
-#----------------------------------------------#
-def domain_needed():
- if not db.domain_exists \
- or db.incomplete_domain \
- or not db.domain_active:
- sys.exit(1)
-
-
-#=====================#
-# Create a new domain #
-#---------------------#
-def create_domain(target):
- if target and not target.startswith('http'):
- logs.out("51", '"%s" -> http(s)://...'%target, False)
- target = ''
-
- print('\n'
- ' ┌──────────────────────────────────────────────┐\n'
- ' │ Configure a new domain for current directory │\n'
- ' │ Answer Y/y = yes. Enter to set {default} │\n'
- ' │ Empty Answer cancel process, except for │\n'
- ' │ - [Optional] │\n'
- ' │ - {default} value │\n'
- ' ├──────────────────────────────────────────────┘'
- )
-
-
- # Get complete URL from target or ask
- #------------------------------------
- try:
- domain_www_url = db.domain_www_url
- except:
- if target: domain_www_url = target
- else: domain_www_url = ''
-
- valid_url = ('http://', 'https://')
- ask = ''
- try:
- ask = input(' ├ [http(s)://...] URL to website ? {%s} '%domain_www_url)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.startswith(valid_url):
- logs.out("2", '"%s" -> http(s)://...'%ask, True)
- domain_www_url = ask
- if not domain_www_url:
- logs.out("255", '', True)
-
- # Remove unused last / if exists
- if domain_www_url[-1] == "/":
- domain_www_url = domain_www_url[:-1]
-
- domain_proto = domain_www_url.rsplit('://')[0]
- domain_short = domain_www_url.rsplit('://')[1]
-
-
- # Prefix wip
- #-----------
- domain_wip_url = ''
- # Set domain with www-wip.
- try:
- domain_wip_url = db.domain_wip_url
- except:
- wip_url = domain_short.rsplit('.', 2)
- wip_url[0] = '%s://www-wip'%domain_proto
- for t in wip_url:
- if domain_wip_url:
- domain_wip_url = '%s.%s'%(domain_wip_url, t)
- else:
- domain_wip_url = t
-
- ask = ''
- try:
- ask = input(' ├ URL to wip ? {%s} '%domain_wip_url)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if ask:
- if not ask.startswith(valid_url):
- logs.out("2", '"%s" -> http(s)://...'%ask, True)
- domain_wip_url = ask
-
- # Remove unused last / if exists
- if domain_wip_url[-1] == "/":
- domain_wip_url = domain_wip_url[:-1]
-
- # Register variables in domain database
- global navbars_conf
- db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short)
- db_dir_html = '%shtml/'%db_dir
- navbars_conf = '%sarticles/_configs/'%db.conf_dir
- set_f = 'domain_dir = "%s"\n'%db.conf_dir + \
- 'domain_conf = "%s"\n'%db.domain_conf + \
- 'domain_articles = "%sarticles/"\n'%db.conf_dir + \
- 'domain_files = "%sarticles/files/"\n'%db.conf_dir + \
- 'domain_images = "%sarticles/images/"\n'%db.conf_dir + \
- 'articles_db = "%sarticles/"\n'%db_dir + \
- 'navbars_dir = "%s"\n'%navbars_conf + \
- 'navbar_load = "%styto.navbar"\n'%navbars_conf + \
- 'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \
- 'metas_load = "%styto.metas.html"\n'%navbars_conf + \
- 'footer_load = "%styto.footer.html"\n'%navbars_conf + \
- '\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(db.domain_conf, True, set_f)
- print(' ├ Created new database')
-
- # Get srv root
- #-------------
- try: domain_srv = db.domain_srv
- except: domain_srv = '/var/www'
-
- ask = ''
- try:
- ask = input(' ├ System server ? {%s} '%domain_srv)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- 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
- set_f = '# 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"'%srv_www_tpl
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get logo's website
- #-------------------
- try: domain_logo = db.domain_logo
- except: domain_logo = 'logo.png'
-
- ask = ''
- try:
- ask = input(' ├ logo filename ? {%s} '%domain_logo)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: domain_logo = ask
-
- set_f = 'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \
- 'www_logo = "%s%s"'%(srv_www_tpl, domain_logo)
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # RSS/Atom filename
- #------------------
- try: domain_rss = db.domain_rss
- except: domain_rss = 'rss.xml'
-
- ask = ''
- try:
- ask = input(' ├ Atom/RSS filename ? {%s} '%domain_rss)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- www_rss = ask
-
- set_f = 'www_rss = "%s/www/%s"\n'%(root_srv_dom, domain_rss) + \
- '\n# Domain user\'s settings\n' + \
- 'domain_logo = "%s"\n'%domain_logo + \
- 'domain_rss = "%s"'%domain_rss
-
-
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # RSS/Atom max items
- #-------------------
- try: domain_rssitems = db.domain_rssitems
- except: domain_rssitems = "100"
-
- ask = ''
- try:
- ask = input(' ├ Atom/RSS items to show ? {%s} '%domain_rssitems)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.isdigit(): logs.out("3", ask, True)
- domain_rssitems = ask
-
- set_f = 'domain_rssitems = %d'%domain_rssitems
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get title domain
- #-----------------
- try: domain_title = db.domain_title
- except: domain_title = ''
-
- ask = ''
- try:
- ask = input(' ├ Domain title ? {%s} '%domain_title)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: domain_title = ask
- elif not domain_title: logs.out("255", '', True)
- if '"' in domain_title:
- domain_title = domain_title.replace('"', '')
-
- set_f = 'domain_title = "%s"'%domain_title
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get creation date
- #------------------
- try: domain_date
- except: domain_date = datetime.now().year
-
- ask = ''
- try:
- ask = input(' ├ Domain creation yeay ? {%s} '%domain_date)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.isdigit(): logs.out("3", ask, True)
- domain_date = ask
-
- set_f = 'domain_date = "%s"'%domain_date
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get Description domain
- #-----------------------
- try: domain_about = db.domain_about
- except: domain_about = ''
-
- ask = ''
- try:
- ask = input(' ├ Domain Description ? {%s} '%domain_about)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: domain_about = ask
- elif not domain_about: logs.out("255", '', True)
- if '"' in domain_about:
- domain_about = domain_about.replace('"', '')
-
- set_f = 'domain_about = "%s"'%domain_about
- tyto.set_file(db.domain_conf, False, set_f)
-
- # Get Lang domain
- #----------------
- try: domain_lang = db.domain_lang
- except: domain_lang = locale.getdefaultlocale()[0].split('_')[0]
-
- ask = ''
- try:
- ask = input(' ├ [2 char] Website language ? {%s} '%domain_lang)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if len(ask) == 2: domain_lang = ask
- else: logs.out("3", ask, True)
- elif not domain_lang: logs.out("255", '', True)
-
- set_f = 'domain_lang = "%s"'%domain_lang
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get mail domain
- #----------------
- try: domain_mail = db.domain_mail
- except: domain_mail = ''
-
- ask = ''
- try:
- ask = input(' ├ Webmaster\'s mail ? {%s} '%domain_mail)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not "@" in ask and not "." in ask: logs.out("3", ask, True)
- domain_mail = ask
- elif not domain_mail: logs.out("255", '', True)
-
- set_f = 'domain_mail = "%s"'%domain_mail
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get Tags domain
- #----------------
- try: domain_tags = db.domain_tags
- except: domain_tags = ''
-
- ask = ''
- try:
- ask = input(' ├ [comma separated] Domain tags ? {%s} '%domain_tags)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: domain_tags = ask
- elif not domain_tags: logs.out("255", '', True)
-
- set_f = 'domain_tags = "%s"'%domain_tags
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get License domain
- #-------------------
- try: domain_license = db.domain_license
- except: domain_license = 'CC BY-NC-SA'
-
- ask = ''
- try:
- ask = input(' ├ Domain License ? {%s} '%domain_license)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: domain_license = ask
- elif not domain_license: logs.out("255", '', True)
- if '"' in domain_license:
- domain_license = domain_license.replace('"', '')
-
- set_f = 'domain_license = "%s"'%domain_license
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Get License URL (optionnal)
- #----------------------------
- try: domain_licurl = db.domain_licurl
- except: domain_licurl = ''
-
- ask = ''
- try:
- ask = input(' ├ [Optional] License URL ? {%s} '%domain_licurl)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.startswith('http'): logs.out("3", ask, True)
- domain_licurl = ask
-
- set_f = 'domain_licurl = "%s"'%domain_licurl
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Legal Notice URL
- #-----------------
- try: domain_legalurl = db.domain_legalurl
- except: domain_legalurl = ''
-
- ask = ''
- try:
- ask = input(' ├ [Optional] Legal Notice URL ? {%s} '%domain_legalurl)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.startswith('http'): logs.out("3", ask, True)
- domain_legalurl = ask
-
- set_f = 'domain_legalurl = "%s"'%domain_legalurl
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Terms URL
- #-----------------
- try: domain_termsurl = db.domain_termsurl
- except: domain_termsurl = ''
-
- ask = ''
- try:
- ask = input(' ├ [Optional] Terms of Use URL ? {%s} '%domain_termsurl)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.startswith('http'): logs.out("3", ask, True)
- domain_legalurl = ask
-
- set_f = 'domain_termsurl = "%s"'%domain_termsurl
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # CSS Prefix
- #-----------
- try: domain_css = db.domain_css
- except: domain_css = 'tyto'
-
- ask = ''
- try:
- ask = input(' ├ [alnum] Prefix CSS ? {%s} '%domain_css)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.isalnum(): logs.out("3", ask, True)
- domain_css = ask.lower()
-
- set_f = 'domain_css = "%s"'%domain_css
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Titles webpage separator
- #-------------------------
- try: domain_sep = db.domain_sep
- except: domain_sep = "-"
-
- ask = ''
- try:
- ask = input(' ├ [1 char] Pages titles separator ? {%s} '%domain_sep)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not len(ask) == 1: logs.out("3", ask, True)
- domain_sep = ask
-
- set_f = 'domain_sep = "%s"'%domain_sep
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Show article source ?
- #----------------------
- try:
- db.article_code
- article_code = "True"
- except:
- article_code = "False"
-
- ask = ''
- try:
- ask = input(' ├ Show Article\'s code ? {%s} (Y/y) '%article_code)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask in ['y', 'Y']:
- article_code = "True"
-
- set_f = 'article_code = %s'%article_code
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Profile for rel="me" (optionnal)
- #---------------------------------
- try: domain_relme = db.domain_relme
- except: domain_relme = ''
-
- ask = ''
- try:
- ask = input(' ├ [Optional] rel="me" URL ? {%s} '%domain_relme)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.startswith('http'): logs.out("3", ask, True)
- domain_relme = ask
-
- set_f = 'domain_relme = "%s"'%domain_relme
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Sidebar Title
- #--------------
- try: sidebar_title = db.sidebar_title
- except: sidebar_title = tyto.trans[0][tyto.n]
-
- ask = ''
- try:
- ask = input(' ├ Sidebar title ? {%s} '%sidebar_title)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask: sidebar_title = ask
- if '"' in sidebar_title:
- sidebar_title = sidebar_title.replace('"', '')
-
- set_f = 'sidebar_title = "%s"'%sidebar_title
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Sidebar Items
- #--------------
- try: sidebar_items = db.sidebar_items
- except: sidebar_items = "6"
-
- ask = ''
- try:
- ask = input(' ├ [max=16] Sidebar Items ? {%s} '%sidebar_items)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
-
- if ask:
- if not ask.isdigit(): logs.out("3", ask, True)
- elif int(ask) in range(1,17): sidebar_items = int(ask)
-
- set_f = 'sidebar_items = %d'%int(sidebar_items)
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Create domain_footer_about (user custom description in footer)
- #---------------------------------------------------------------
- try:
- domain_footer_about = db.domain_footer_about
- set_f = '\n# Custom HTML (ONE Line)\n' + \
- "domain_footer_about = '%s'"%domain_footer_about
- except:
- set_f = '\n# Custom HTML (ONE Line)\n' + \
- "domain_footer_about = '
%s
'"%domain_about
-
- tyto.set_file(db.domain_conf, False, set_f)
-
-
- # Activate Domain after Resumed configuration ?
- #----------------------------------------------
- try: domain_active = db.domain_active
- except: domain_active = False
-
- file = open(db.domain_conf, 'r').read()
- resume = ' │\n' + \
- ' ├──────────────────────────────────────┐\n' + \
- ' │ Please, READ the configuration datas │\n' + \
- ' ├──────────────────────────────────────┘'
-
- print(resume)
-
- for line in file.rsplit('\n'):
- print(' │', line)
-
- try:
- ask = input(' ├ Activate and prepare domain ? ')
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if not ask in ['y', 'Y']:
- tyto.set_file(db.domain_conf, False, '\ndomain_active = False')
- logs.out("255", '', True)
-
- # Activate Domain
- #----------------
- tyto.set_file(db.domain_conf, False, '\ndomain_active = True')
-
- # Load config
- importlib.reload(db)
-
- # Create folders from configuration file
- folders = (
- db.srv_wip_tpl, db.srv_wip_images, db.srv_wip_files,
- db.srv_www_tpl, db.srv_www_images, db.srv_www_files,
- db.domain_files, db.domain_images, db.navbars_dir,
- db.articles_db
- )
-
- print(' │')
- for folder in folders:
- if not os.makedirs(folder, exist_ok=True):
- print(' │ Exists directory: %s'%folder)
- else:
- print(' ├ Create directory: %s'%folder)
-
- # Create in _configs files
- # Parameter could be used later
- print(' │')
- create_sidebar('new')
- create_navbar('new')
- create_metas('new')
- create_footer('new')
-
- print(' │')
- print(' ├──────────────────────────────────────┐')
- print(' │ Domain is ready. Have fun, writers ! │')
- print(' └──────────────────────────────────────┘')
-
-
-#==============================#
-# sidebar load file translated #
-#------------------------------#
-def create_sidebar(option):
- # Check if can process
- domain_needed()
-
- # Create an empty html file in wip/www server if not exists
- if not os.path.exists(db.wip_sidebar):
- tyto.set_file(db.wip_sidebar, 'new', '')
- print(' ├ Create empty file: %s'%db.wip_sidebar)
-
- # Create new file, or ask if exists with option = 'reset'
- ask = ' ├ Reset sidebar configuration file ? '
- res = ''
- if os.path.exists(db.sidebar_load):
- try:
- res = input(ask)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if not res in ['y', 'Y']: return
-
- # French sidebar_load content
- sdb_load_fr = \
- '# Pour : Tyto - Littérateur\n' + \
- '# Type : fichier texte\n' + \
- '# Description : Fichier utilisé par "tyto wip/publish"\n' + \
- '# (Liste d\'articles)\n' + \
- '# Fichier : %s\n'%db.sidebar_load + \
- "# Commandes: tyto new sidebar (réinitialiser)\n" + \
- '# tyto wip/publish sidebar (créer)\n' + \
- '# tyto edit sidebar (editer ce fichier)\n' + \
- '# Comment : 1 URI de l\'article par ligne\n' + \
- '# (depuis articles/)\n' + \
- '# Ne commence pas par "/"\n' + \
- '# L\'ordre définit la position\n' + \
- '# Option : : Titre de la sidebar\n' + \
- '\n# %s\n'%(15 * "-") + \
- '# Exemples :\n' + \
- '# : Ma liste des nouveaux articles\n' + \
- '# index.tyto\n' + \
- '# dir1/index.tyto\n' + \
- '# %s\n\n'%(15 * "-")
-
- # English sidebar_load content
- sdb_load_en = \
- '# For: Tyto - Littérateur\n' + \
- '# Type: Text file\n' + \
- '# Description: Used with "wip/publish sidebar"\n' + \
- '# (articles\'s list)\n' + \
- '# File: %s\n'%db.sidebar_load + \
- '# Commands: tyto new sidebar (reset)\n' + \
- '# tyto wip/publish sidebar (Create)\n' + \
- '# tyto edit sidebar (edit this file)\n' + \
- '# How: 1 article URI per line\n' + \
- '# (from articles/)\n' + \
- '# not begining with "/"\n' + \
- '# Order in sidebar position\n' + \
- '# Option: : Sidebar Title\n' + \
- '\n# %s\n'%(15 * "-") + \
- '# Examples :\n' + \
- '# : My new articles list'
- '# index.tyto\n' + \
- '# dir1/index.tyto\n' + \
- '# %s\n\n'%(15 * "-")
-
- # Set language file
- if tyto.n == 0: sdb_load = sdb_load_fr
- elif tyto.n == 1: sdb_load = sdb_load_en
-
- tyto.set_file(db.sidebar_load, 'new', sdb_load)
- logs.out("33", db.sidebar_load, False)
-
-
-#=============================#
-# navbar load file translated #
-#-----------------------------#
-def create_navbar(option):
- # Check if can process
- domain_needed()
-
- # Create an empty html file in wip/www server if not exists
- if not os.path.exists(db.wip_navbar):
- tyto.set_file(db.wip_navbar, 'new', '')
- print(' ├ Create empty file: %s'%db.wip_navbar)
-
- # Create new file, or ask if exists
- ask = ' ├ Reset navbar configuration file ? '
- res = ''
- if os.path.exists(db.navbar_load):
- try:
- res = input(ask)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if not res in ['y', 'Y']: return
-
-
- # French navbar_load content
- nav_load_fr = '# Pour : Tyto - Littérateur\n' + \
- '# Type : fichier texte\n' + \
- '# Description : Utilisé par "wip/publish sidebar"\n' + \
- '# (Liste des dossiers)\n' + \
- '# Fichier : %s\n'%db.navbar_load + \
- '# Comment : 1 nom de dossier par ligne *1\n' + \
- '# (depuis articles/)\n' + \
- '# Ne commence pas par "/"\n' + \
- '# L\'ordre définit la position\n' + \
- '# Note : Pour éviter l\'erreur 404 :\n' + \
- '# - ajouter un article index.{ext}\n' + \
- '# dans le dossier mentionné\n' + \
- '# - utiliser check et wip dessus\n' + \
- '# *1 Option : Pour définir un titre de lien :\n' + \
- '# - ajouter "# titre de lien"\n' + \
- '\n# %s\n'%(15 * "-") +\
- '# Exemples :\n' + \
- '# documentation\n' + \
- '# a-propos # Informations concernant ce site\n' + \
- '# %s\n\n'%(15 * "-")
-
- # English navbar_load content
- nav_load_en = '# For: Tyto - Littérateur\n' + \
- '# Type: Text file\n' + \
- '# Description: Used with "wip/publish navbar"\n' + \
- '# (directories\'s list)\n' + \
- '# File : %s\n'%db.navbar_load + \
- '# Comment: 1 folder name per line *1\n' + \
- '# (from articles/)\n' + \
- '# not begining with "/"\n' + \
- '# Order in sidebar position\n' + \
- '# Remember: To avoid 404 error, you must:\n' + \
- '# - add index.{ext} file article\n' + \
- '# in set folder\n' + \
- '# - check and wip it\n' + \
- '# *1 Option : To define a title link:' + \
- '# - add "# title link"\n' + \
- '\n# %s\n'%(15 * "-") +\
- '# Examples :\n' + \
- '# documentation\n' + \
- '# about # infos about this website\n' + \
- '# %s\n\n'%(15 * "-")
-
- # Set language file
- if tyto.n == 0: nvb_load = nav_load_fr
- elif tyto.n == 1: nvb_load = nav_load_en
-
- tyto.set_file(db.navbar_load, 'new', nvb_load)
- logs.out("33", db.navbar_load, False)
-
-
-#========================#
-# metas_load source file #
-#------------------------#
-def create_metas(option):
- # Check if can process
- domain_needed()
-
-
- # Set metas_load default content
- #-------------------------------
- metas_tags = \
- '# Custom HTML metas for all pages\n' + \
- '# You can add/edit HTML tags\n' + \
- '# ! Only and lines are used !\n' + \
- '# After editing, use "tyto wip/publish metas"\n' + \
- '# (You should NOT copy this file to template)\n' + \
- '\n' + \
- '# Already set metas with values:\n' + \
- '# \n' + \
- '\n' + \
- '\n' + \
- ''
-
- metas_srvs = \
- ' \n' + \
- ' \n' + \
- ' \n' + \
- ' '
-
- # Create an empty html file in wip/www server if not exists
- if not os.path.exists(db.wip_metas):
- tyto.set_file(db.wip_metas, 'new', metas_srvs)
- print(' ├ Create empty file: %s'%db.wip_metas)
-
- # Create new default file, or ask if exists
- ask = ' ├ Reset metas configuration file ? '
- res = ''
- if os.path.exists(db.metas_load):
- try:
- res = input(ask)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if not res in ['y', 'Y']: return
-
- tyto.set_file(db.metas_load, 'new', metas_tags)
- logs.out("33", db.metas_load, False)
-
-
-#=============================#
-# footer load file translated #
-#-----------------------------#
-def create_footer(option):
- # Check if can process
- domain_needed()
-
- # Create an empty html file in wip/www server if not exists
- if not os.path.exists(db.wip_footer):
- tyto.set_file(db.wip_footer, 'new', '')
- print(' ├ Create empty file: %s'%db.wip_footer)
-
- # Create new default file, or ask if exists
- ask = ' ├ Reset footer configuration file ? '
- res = ''
- if os.path.exists(db.footer_load):
- try:
- res = input(ask)
- except KeyboardInterrupt:
- print('')
- logs.out("255", '', True)
- if not res in ['y', 'Y']: return
-
- # Default footer contents
- Tytosrc = \
- '\n%s(%s)'%(9 * ' ', tyto.trans[3][tyto.n])
- tyto_show = \
- '%s%s %s'%(9 * ' ', tyto.Tyto, Tytosrc)
-
- # Show copyright date from creation to now year
- if int(db.domain_date) == int(datetime.now().year):
- footer_date = db.domain_date
- else:
- footer_date = '%s - %s'%(db.domain_date, datetime.now().year)
-
- # Simple link to home
- domain_home = \
- '\n%s%s'%(9 * ' ', db.domain_title)
-
- # Show domain_footer_about
- footer_about = ''
- for line in db.domain_footer_about.rsplit('\n'):
- if not line: continue
- line = '%s%s'%(6 * ' ', line)
- if footer_about: footer_about = '%s\n%s'%(footer_about, line)
- else: footer_about = line
-
- # License URL
- if not db.domain_licurl: db.domain_licurl = '/'
-
- # Links for laws (Terms and legals)
- if db.domain_legalurl:
- legal_link = \
- '%s'%(
- 11 * ' ', tyto.trans[16][tyto.n]
- )
-
- if db.domain_termsurl:
- terms_link = \
- '%s'%(11 * ' ', tyto.trans[15][tyto.n])
-
- footer_law = ''
- if db.domain_termsurl and db.domain_legalurl:
- footer_law = '%s - \n%s%s'%(legal_link, 8 * ' ', terms_link)
- elif db.domain_termsurl:
- footer_law = terms_link
- elif db.domain_legalurl:
- footer_law = legal_link
-
- footer_law_link = ''
- if footer_law:
- footer_law_link = \
- ' \n'
-
- # Final HTML footer code
- footer = \
- '# Default