diff --git a/src/usr/bin/tyto b/src/usr/bin/tyto index 819c3f8..5256a1b 100755 --- a/src/usr/bin/tyto +++ b/src/usr/bin/tyto @@ -26,8 +26,6 @@ import sys sys.path.insert(0, '/var/lib/tyto/program') -import check, domain, wip, html - #====================# # MAIN # # Treat Arguments # @@ -36,6 +34,9 @@ if not __name__ == "__main__": print(':< Mismatch program start') sys.exit(1) +import args +import check, domain, wip, html + noarg = False target = '' option = '' @@ -51,38 +52,7 @@ actions = { 'footer' : html.manage_configs } -# Dict for Options -options = { - '-a' : 'Add', 'add' : 'Add', - '-R' : "Remove", 'remove' : "Remove", - '-n' : "New", 'new' : "New", - '-e' : "Edit", 'edit' : "Edit", - '-F' : "Force", 'force' : "Force", - '-s' : "Show", - '-d' : 'DB', - 'again': 'Again' - } - -# Set Argument 2 or 3 -#-------------------- -for i in range(2,4): - try: - sys.argv[i] - try: - if not option: option = options[sys.argv[i]] - else: target: target = sys.argv[i] - except: - if not target: target = sys.argv[i] - else: option: option = options[sys.argv[i]] - except: - noarg = True - - if noarg: continue - # Argument 1 #----------- -try: - actions[sys.argv[1]](target, option) -except KeyError: - print(':< Invalid action "%s": [check, wip...]'%sys.argv[1]) +actions[sys.argv[1]](args.target, args.option) diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py new file mode 100644 index 0000000..0342b9e --- /dev/null +++ b/src/var/lib/tyto/program/args.py @@ -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 diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index a047a3e..2acde83 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -23,10 +23,7 @@ from datetime import datetime from time import gmtime, strftime import time -import tyto - -# Load domain configuration if exists -if tyto.domain_exists: exec(open(tyto.domain_conf).read()) +import logs, db, tyto post_err = False date_wip = hash_wip = date_www = hash_www = '' @@ -37,21 +34,22 @@ date_wip = hash_wip = date_www = hash_www = '' # Start checking article # #-------------------------#-------------------------------------------- def manage_check(target, option): + # target needed + if not target: logs.out("5", '', True) + + global post_bottom, article_bottom global post_words - - # target needed - if not target: tyto.exiting("5", '', True) # Article exists + has DB ? db_exists = tyto.get_db_post(target) # Manage option if option == 'Edit': - tyto.edit_file(tyto.uri_root) + tyto.edit_file(tyto.uri_file) return elif option == 'Show': - article_raw = open(tyto.uri_root).read() + article_raw = open(tyto.uri_file).read() for line in article_raw.rsplit('\n'): print(line) return @@ -66,21 +64,12 @@ def manage_check(target, option): try: exec(open(tyto.post_db).read(),globals()) - try: - if hash_chk == tyto.hash_post and not option == 'Force': - tyto.exiting("20", date_chk, True) - except: pass - except: pass - - # Get sub_uri for HTML - global sub_uri - sub_uri = tyto.uri_post.rsplit('articles/')[1] - sub_nbr = sub_uri.count('/') - if sub_nbr == 0 : sub_uri = './' - else: sub_uri = sub_nbr * '../' + if hash_chk == tyto.hash_post and not option == 'Force': + logs.out("20", date_chk, True) + finally: pass # Start processes - file_to_string(tyto.uri_root) + file_to_string(tyto.uri_file) # Specific to inline-code: check markers on same line check_icodes(article.rsplit('\n')) @@ -106,7 +95,7 @@ def manage_check(target, option): check_headers(post_header) # Exit if unused needed tags - if post_err: tyto.exiting("7", '', True) + if post_err: logs.out("7", '', True) # No error create_database() @@ -134,8 +123,7 @@ def file_to_string(post_file): article = open(post_file, 'r').read() # Check if separator or exit - if not '-----' in article: - tyto.exiting("6", '-----', True) + if not '-----' in article: logs.out("6", '-----', True) # Set from separator, NOT splitted by new line article_header = article.rsplit('-----')[0] @@ -146,9 +134,9 @@ def file_to_string(post_file): post_bottom = article.rsplit('-----')[1].rsplit('\n') -# -# Check inline code, for markers on same line -# +#=============================================# +# Check inline code, for markers on same line # +#---------------------------------------------# def check_icodes(article): quote = bcode = False @@ -172,10 +160,11 @@ def check_icodes(article): icode_m1 = line.count(tyto.words_tags[9][0]) icode_m2 = line.count(tyto.words_tags[9][1]) if icode_m1 != icode_m2: - tyto.exiting("8", 'inline-code: line %s. %s %s'%(ln, + logs.out("8", 'inline-code: line %s. %s %s'%(ln, tyto.words_tags[9][0], tyto.words_tags[9][1] ), True - ) + ) + #==================================# # Check tags from article's header # @@ -186,6 +175,11 @@ def check_headers(post_header): global stat_links, stat_images, stat_files, stat_raws, stat_abbrs global post_tags global snpic_url + global files_post + + # Contains all files URIs needed for article + # Used with publish command to copy needed files + files_post = ('') snshare = False snpic_name = '' @@ -259,7 +253,7 @@ def check_headers(post_header): # Check if set needed tags for tag in need_headers: if not need_headers[tag]: - tyto.exiting("6", tag, False) + logs_out("6", tag, False) ### @@ -282,20 +276,20 @@ def check_headers(post_header): abbr_short = post_header[ln - 1].rsplit(tag)[1].lstrip() if not abbr_short: - tyto.exiting("2", "Line %s (SHORT, %s)"%(ln, tag), False) + logs.out("2", "Line %s (SHORT, %s)"%(ln, tag), False) post_err = True if not abbr_short.isupper(): - tyto.exiting("3", "Line %s (Upper SHORT, %s)"%(ln, tag), False) + logs.out("3", "Line %s (Upper SHORT, %s)"%(ln, tag), False) post_err = True continue if not isin(r'!\b%s\b'%abbr_short, post_bottom): - tyto.exiting("6", '!%s'%abbr_short, False) + logs.out("6", '!%s'%abbr_short, False) post_err = True abbr_long = post_header[ln].lstrip() if abbr_long.startswith(tyto.headers): abbr_long = '' if not abbr_long: - tyto.exiting("2", "Line %s (Long, %s)"%(ln + 1, tag), False) + logs.out("2", "Line %s (Long, %s)"%(ln + 1, tag), False) post_err = True abbr_alt = post_header[ln + 1].lstrip() @@ -319,22 +313,22 @@ def check_headers(post_header): link_name = post_header[ln - 1].rsplit(tag)[1].lstrip() if not link_name: - tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False) + logs.out("2", "Line %s (Name, %s)"%(ln, tag), False) post_err = True if not isin(r'\b_%s\b'%link_name, post_bottom): - tyto.exiting("6", "_%s"%link_name, False) + logs.out("6", "_%s"%link_name, False) post_err = True link_url = post_header[ln].lstrip() if link_url.startswith(tyto.headers): link_url = '' if not link_url: - tyto.exiting("2", "Line %s (URL, %s)"%(ln + 1, tag), False) + logs.out("2", "Line %s (URL, %s)"%(ln + 1, tag), False) post_err = True link_alt = post_header[ln + 1].lstrip() if link_alt.startswith(tyto.headers): link_alt = '' if not link_alt: - tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) + logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) post_err = True if not post_err: @@ -356,24 +350,26 @@ def check_headers(post_header): image_name = post_header[ln - 1] image_name = image_name.rsplit(tag)[1].lstrip().rsplit(' ')[0] if not image_name: - tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False) + logs.out("2", "Line %s (Name, %s)"%(ln, tag), False) post_err = True if not isin(r'\b_%s%s\b'%(tag, image_name), post_bottom): - tyto.exiting("6", "_%s%s"%(tag, image_name), False) + logs.out("6", "_%s%s"%(tag, image_name), False) post_err = True image_uri = post_header[ln].lstrip() if image_uri.startswith(tyto.headers): image_uri = '' if not image_uri: - tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False) + logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False) post_err = True else: check_file_uri('image', image_uri, ln + 1) + f_uri = web_uri[1:len(web_uri)] + files_post = (files_post + "'%s', "%f_uri) image_alt = post_header[ln + 1].lstrip() if image_alt.startswith(tyto.headers): image_alt = '' if not image_alt: - tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) + logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) post_err = True if not post_err: @@ -393,24 +389,26 @@ def check_headers(post_header): raw_name = post_header[ln - 1] raw_name = raw_name.rsplit(tag)[1].lstrip().rsplit(' ')[0] if not raw_name: - tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False) + logs.out("2", "Line %s (Name, %s)"%(ln, tag), False) post_err = True if not isin(r'\b_%s%s\b'%(tag, raw_name), post_bottom): - tyto.exiting("6", "_%s%s"%(tag, raw_name), False) + logs.out("6", "_%s%s"%(tag, raw_name), False) post_err = True raw_uri = post_header[ln].lstrip() if raw_uri.startswith(tyto.headers): raw_uri = '' if not raw_uri: - tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False) + logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False) post_err = True else: check_file_uri('file', raw_uri, ln + 1) + f_uri = web_uri[1:len(web_uri)] + files_post = (files_post + "'%s', "%f_uri) raw_alt = post_header[ln + 1].lstrip() if raw_alt.startswith(tyto.headers): raw_alt = '' if not raw_alt: - tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) + logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) post_err = True if not post_err: @@ -429,24 +427,26 @@ def check_headers(post_header): file_name = post_header[ln - 1].rsplit(tag)[1].lstrip() if not file_name: - tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False) + logs.out("2", "Line %s (Name, %s)"%(ln, tag), False) post_err = True if not isin(r'\b__%s\b'%file_name, post_bottom): - tyto.exiting("6", "__%s"%file_name, False) + logs.out("6", "__%s"%file_name, False) post_err = True file_uri = post_header[ln].lstrip() if file_uri.startswith(tyto.headers): file_uri = '' if not file_uri: - tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False) + logs.out("2", "Line %s (URI, %s)"%(ln + 1, tag), False) post_err = True else: check_file_uri('file', file_uri, ln + 1) + f_uri = web_uri[1:len(web_uri)] + files_post = (files_post + "'%s', "%f_uri) file_alt = post_header[ln + 1].lstrip() if file_alt.startswith(tyto.headers): file_alt = '' if not file_alt: - tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) + logs.out("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) post_err = True if not post_err: @@ -461,24 +461,24 @@ def check_headers(post_header): # snpic (set image to share to social networks) #---------------------------------------------- if snpic_name: continue + snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo) tag = tyto.headers[11] # snpic: if line.startswith(tag): snpic_name = post_header[ln - 1].rsplit(tag)[1].lstrip() for ln, line in enumerate(post_header, 1): 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) snshare = True - snpic_url = '%s%s'%(domain_url, web_uri) + snpic_url = '%s%s'%(db.domain_www_url, web_uri) break if not snshare: - tyto.exiting("10", '%s %s'%(tyto.headers[6], snpic_name), True) + logs.out("12", '%s %s'%(tyto.headers[6], snpic_name), True) # Exit if error in optional tags #------------------------------- - if post_err: - tyto.exiting("7", '', True) + if post_err: logs.out("7", '', True) #================================# @@ -495,7 +495,7 @@ def check_date(date, ln): bool(datetime.strptime(date, fmt_article)) except ValueError: post_err = True - tyto.exiting("3", 'Line %s (date, %s)'%(ln, date), False) + logs.out("3", 'Line %s (date, %s)'%(ln, date), False) # Create date_check (epoch) from article's Date + now TIME if not post_err: @@ -516,9 +516,9 @@ def check_file_uri(filetype, filename, ln): # (@ = images/, / = articles/, else = post_dir) if filename.startswith('@'): if filetype == 'image': - fileuri = domain_images + filename[1: len(filename)] + fileuri = db.domain_images + filename[1: len(filename)] elif filetype == 'file': - fileuri = domain_files + filename[1: len(filename)] + fileuri = db.domain_files + filename[1: len(filename)] elif filename.startswith('/'): fileuri = tyto.post_dir + filename[1: len(filename)] @@ -528,11 +528,11 @@ def check_file_uri(filetype, filename, ln): # Check if file exists if not os.path.exists(fileuri): - tyto.exiting("1", "Line %s, %s"%(ln, fileuri), False) + logs.out("1", "Line %s, %s"%(ln, fileuri), False) post_err = True return - web_uri = '/' + fileuri.replace(domain_articles, "") + web_uri = '/' + fileuri.replace(db.domain_articles, "") #===========================# @@ -560,7 +560,7 @@ def check_content(post_bottom): if line.startswith(tag[1]): c_closed += 1 if c_opened != c_closed: - tyto.exiting("8", '%s: "%s", "%s"'%(tag[4], tag[0], tag[1]), False) + logs.out("8", '%s: "%s", "%s"'%(tag[4], tag[0], tag[1]), False) post_err = True return # Useless and could code errors to check nexts else: @@ -581,7 +581,7 @@ def check_content(post_bottom): css_anchor = anchor.rsplit(':')[0] tag = '%s %s'%(tyto.single_tags[1][0], css_anchor) if not tag in post_bottom: - tyto.exiting("6", 'anchor, %s'%tag, False) + logs.out("6", 'anchor, %s'%tag, False) post_err = True @@ -598,9 +598,10 @@ def check_content(post_bottom): if not inlist: continue if not line[0] in tyto.markers_lists: - tyto.exiting("3", 'line %s must start with %s'%( + logs.out("3", 'line %s must start with %s'%( ln, markers_lists - ), False) + ), False + ) post_err = True @@ -621,7 +622,7 @@ def check_content(post_bottom): set_tags = (ptag_set) if match: continue - else: tyto.exiting("10", "%s %s"%(htag, ptag_set), True) + else: logs.out("12", "%s %s"%(htag, ptag_set), True) # Template Tags (warning for not paired symbols) @@ -631,7 +632,7 @@ def check_content(post_bottom): tpl2 = article_bottom.count(tag[1]) if tpl1 != tpl2: - tyto.exiting("22", '"%s", "%s"'%(tag[0], tag[1]), False) + logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False) @@ -639,25 +640,24 @@ def check_content(post_bottom): # Create new article's database at each check ! # #-----------------------------------------------# def create_database(): - # No first / from dir post - web_uri = tyto.web_uri[1: len(tyto.web_uri)] - # No need index.html for web link - if tyto.web_uri.endswith('index.html'): tyto.web_uri = '/' - database = '# Post Configuration for Tyto\n' + \ - 'post_id = "%s"\n'%tyto.uri_id + \ - 'root_uri = "%s"\n'%tyto.uri_root + \ - 'wip_uri = "%s%s"\n'%(srv_wip, web_uri) + \ - 'www_uri = "%s%s"\n'%(srv_www, web_uri) + \ - 'http_uri = "%s"\n'%tyto.web_uri + \ - 'sub_uri = "%s"\n'%sub_uri + \ + 'post_id = "%s"\n'%tyto.uri_id + \ + 'post_src = "%s"\n'%tyto.uti_file + \ + 'post_wip = "%s"\n'%tyto.srv_post_wip_uri + \ + 'post_www = "%s"\n'%tyto.srv_post_www_uri + \ '\n' + \ - '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 + \ + 'short_src = "%s"\n'%tyto.src_post_short_uri + \ + 'short_srv = "%s"\n'%tyto.srv_post_short_uri + \ + 'sub_uri = "%s"\n'%tyto.sub_uri + \ + 'http_wip = "%s"\n'%tyto.http_wip + \ + 'http_www = "%s"\n'%tyto.http_www + \ + '\n' + \ + 'date_chk = "%s"\n'%tyto.nowdate() + \ + 'hash_chk = "%s"\n'%tyto.hash_post + \ + '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' + \ 'title = "%s"\n'%title + \ 'about = "%s"\n'%about + \ @@ -665,6 +665,8 @@ def create_database(): 'tags = "%s"\n'%tags + \ 'date = %s\n'%str(date) + \ 'snpic = "%s"\n'%snpic_url + \ + '\n# Used files\n' + \ + 'uris = (%s)\n'%files_post + \ '\n# Post configuration from optional tags' if stat_abbrs > 0: @@ -698,31 +700,31 @@ def create_database(): ) db_stats = '\n# Statistics from optional tags\n' + \ - 'uniq_anchors = %s\n'%(int(stat_ancs)) + \ - 'uniq_abbrs = %s\n'%(int(stat_abbrs)) + \ - 'uniq_links = %s\n'%(int(stat_links)) + \ - 'uniq_images = %s\n'%(int(stat_images)) + \ - 'uniq_files = %s\n'%(int(stat_files)) + \ - 'uniq_raws = %s\n'%(int(stat_raws)) + \ + 'uniq_anchors = %d\n'%stat_ancs + \ + 'uniq_abbrs = %d\n'%stat_abbrs + \ + 'uniq_links = %d\n'%stat_links + \ + 'uniq_images = %d\n'%stat_images + \ + 'uniq_files = %d\n'%stat_files + \ + 'uniq_raws = %d\n'%stat_raws + \ '\n# Statistics from post content\n' + \ - 'stat_tags = %s\n'%(int(post_tags)) + \ - 'stat_words = %s\n'%(int(post_words)) + \ - 'stat_titles = %s\n'%(int(tyto.nbr_titles)) + \ - 'stat_paragraphs = %s\n'%(int(post_paragraphs)) + \ - 'stat_anchors = %s\n'%(int(post_anchors)) + \ - 'stat_strongs = %s\n'%(int(post_strongs)) + \ - 'stat_bolds = %s\n'%(int(post_bolds)) + \ - 'stat_emphasis = %s\n'%(int(post_emphasis)) + \ - 'stat_italics = %s\n'%(int(post_italics)) + \ - 'stat_dels = %s\n'%(int(post_dels)) + \ - 'stat_underlines = %s\n'%(int(post_underlines)) + \ - 'stat_cites = %s\n'%(int(post_cites)) + \ - 'stat_customs = %s\n'%(int(post_customs)) + \ - 'stat_icodes = %s\n'%(int(tyto.nbr_icodes)) + \ - 'stat_bcodes = %s\n'%(int(tyto.nbr_bcodes)) + \ - 'stat_quotes = %s\n'%(int(tyto.nbr_quotes)) + \ - 'stat_lists = %s\n'%(int(post_lists)) + 'stat_tags = %d\n'%post_tags + \ + 'stat_words = %d\n'%post_words + \ + 'stat_titles = %d\n'%tyto.nbr_titles + \ + 'stat_paragraphs = %d\n'%post_paragraphs + \ + 'stat_anchors = %d\n'%post_anchors + \ + 'stat_strongs = %d\n'%post_strongs + \ + 'stat_bolds = %d\n'%post_bolds + \ + 'stat_emphasis = %d\n'%post_emphasis + \ + 'stat_italics = %d\n'%post_italics + \ + 'stat_dels = %d\n'%post_dels + \ + 'stat_underlines = %d\n'%post_underlines + \ + 'stat_cites = %d\n'%post_cites + \ + 'stat_customs = %d\n'%post_customs + \ + 'stat_icodes = %d\n'%tyto.nbr_icodes + \ + 'stat_bcodes = %d\n'%tyto.nbr_bcodes + \ + 'stat_quotes = %d\n'%tyto.nbr_quotes + \ + 'stat_lists = %d\n'%post_lists database = '%s\n%s'%(database, db_stats) tyto.set_file(tyto.post_db, 'new', database) - tyto.exiting("21", '', True) + logs.out("21", '', True) diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py new file mode 100644 index 0000000..b76d832 --- /dev/null +++ b/src/var/lib/tyto/program/db.py @@ -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) + diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 6d0023f..7d4ca55 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -17,33 +17,38 @@ #********************************************************************** -import os, locale - -import tyto, html +import os, sys, locale +import logs, db, tyto, html #==========================# # Manage Argument 'domain' # #--------------------------# def manage_domain(target, option): if option == 'Edit': - if tyto.domain_exists: - print(":D Edit domain configuration file:", tyto.domain_conf) - tyto.edit_file(tyto.domain_conf) + if db.domain_exists: + print(":D Edit domain configuration file:", db.domain_conf) + tyto.edit_file(db.domain_conf) + else: + sys.exit(1) elif option == 'New': - if not tyto.domain_exists: + if not db.domain_exists: create_domain(target, option) else: - print(':) A domain exists in this directory') - ask = input('-> Edit it with the form ? ') - if ask in ['y', 'Y']: create_domain(target, option) - else: tyto.exiting("255", '', True) + if not db.incomplete_domain: + ask = input(' ├ Edit the domain configuration with the form ? ') + if ask in ['y', 'Y']: create_domain(target, option) + else: logs.out("255", '', True) + else: + create_domain(target, option) - elif option == 'DB' or option == 'Show': - if tyto.domain_exists: - domain_db = open(tyto.domain_conf).read() + elif option == 'Show': + if db.domain_exists: + domain_db = open(db.domain_conf).read() for line in domain_db.rsplit('\n'): print(line) + else: + sys.exit(1) #=====================# @@ -51,10 +56,9 @@ def manage_domain(target, option): #---------------------# def isurl(target): global url - if target.startswith('http'): - url = target - else: - tyto.exiting("2", target, True) + if target.startswith('http'): url = target + else: logs.out("2", target, True) + #=====================# # Create a new domain # @@ -75,322 +79,330 @@ def create_domain(target, option): # Get complete URL from target or ask #------------------------------------ - try: domain_url = tyto.domain_url - except: domain_url = '' + try: + domain_www_url = db.domain_www_url + except: + if target: domain_www_url = target + else: domain_www_url = '' + valid_url = ('http://', 'https://') ask = '' - ask = input(' ├ [HTTP...] URL to website ? ("%s") '%domain_url) + ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url) if ask: + if not ask.startswith(valid_url): + logs.out("2", 'http(s)://...', True) isurl(ask) - domain_url = url - elif not domain_url: - tyto.exiting("255", '', True) + domain_www_url = url + elif not domain_www_url: + logs.out("255", '', True) + + domain_short = domain_www_url.rsplit('://')[1] - domain_short = domain_url.rsplit('://')[1] # Prefix wip #----------- try: - try_wipurl = target.rsplit('.') - try_wipurl = 'https://www-wip.%s.%s'%(try_wipurl[1], try_wipurl[2]) + try_wip_url = target.rsplit('.') + try_wip_url = 'https://www-wip.%s.%s'%( + try_wip_url[1], try_wip_url[2] + ) except: - try_wipurl = 'https://www-wip.%s'%target + try_wip_url = 'https://www-wip.%s'%domain_short - try: domain_wipurl = tyto.domain_wipurl - except: domain_wipurl = try_wipurl + try: domain_wip_url = db.domain_wip_url + except: domain_wip_url = try_wip_url ask = '' - ask = input(' ├ URL to wip ? ("%s") '%domain_wipurl) + ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url) if ask: isurl(ask) - domain_wipurl = ask + domain_wip_url = ask - - db_dir = '%s/.local/tyto/%s/'%(tyto.home_dir, domain_short) - navbars_conf= '%sarticles/_configs/'%tyto.conf_dir - conf_domain = 'domain_dir = "%s"\n'%tyto.conf_dir + \ - 'domain_conf = "%s"\n'%tyto.domain_conf + \ - 'domain_articles = "%sarticles/"\n'%tyto.conf_dir + \ - 'domain_files = "%sarticles/files/"\n'%tyto.conf_dir + \ - 'domain_images = "%sarticles/images/"\n'%tyto.conf_dir + \ - 'domain_db = "%sarticles/"\n'%(db_dir) + \ - 'html_db = "%shtml/"\n'%(db_dir) + \ - '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_url = "%s"\n'%domain_url + \ - 'domain_wipurl = "%s"\n'%domain_wipurl + global navbars_conf + db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short) + db_dir_html = '%shtml/'%db_dir + navbars_conf = '%sarticles/_configs/'%db.conf_dir + conf_domain = \ + 'domain_dir = "%s"\n'%db.conf_dir + \ + 'domain_conf = "%s"\n'%db.domain_conf + \ + 'domain_articles = "%sarticles/"\n'%db.conf_dir + \ + 'domain_files = "%sarticles/files/"\n'%db.conf_dir + \ + 'domain_images = "%sarticles/images/"\n'%db.conf_dir + \ + 'domain_db = "%sarticles/"\n'%db_dir + \ + 'html_db = "%s"\n'%db_dir_html + \ + 'navbars_dir = "%s"\n'%navbars_conf + \ + 'navbar_load = "%styto.navbar"\n'%navbars_conf + \ + 'navbar_load_db = "%snavbar_load.conf"\n'%db_dir_html + \ + 'sidebar_load = "%styto.sidebar"\n'%navbars_conf + \ + 'sidebar_load_db = "%ssidebar_load.conf"\n'%db_dir_html + \ + 'metas_load = "%styto.metas.html"\n'%navbars_conf + \ + 'metas_load_db = "%smetas_load.conf"\n'%db_dir_html + \ + 'footer_load = "%styto.footer.html"\n'%navbars_conf + \ + 'footer_load_db = "%sfooter_load.conf"\n'%db_dir_html + \ + '\ndomain_short = "%s"\n'%domain_short + \ + 'domain_www_url = "%s"\n'%domain_www_url + \ + 'domain_wip_url = "%s"\n'%domain_wip_url - tyto.set_file(tyto.domain_conf, True, conf_domain) + tyto.set_file(db.domain_conf, True, conf_domain) + + + # Get srv root + #------------- + try: domain_srv = db.domain_srv + except: domain_srv = '/var/www' + + ask = '' + ask = input(' ├ System server ? ("%s") '%domain_srv) + if ask: + if not os.path.exists(srv): logs.out("1", ask, True) + elif not domain_srv: logs.out("255", '', True) + + root_srv_dom = '%s/%s'%(domain_srv, domain_short) + srv_wip_tpl = "%s/wip/template/"%root_srv_dom + srv_www_tpl = "%s/www/template/"%root_srv_dom + srvs = '# Servers directories\n' + \ + 'srv_root = "%s/"\n'%domain_srv + \ + 'srv_domain = "%s/"\n'%root_srv_dom + \ + 'srv_wip = "%s/wip/"\n'%root_srv_dom + \ + 'srv_wip_tpl = "%s"\n'%srv_wip_tpl + \ + 'srv_wip_images = "%s/wip/images/"\n'%root_srv_dom + \ + 'srv_wip_files = "%s/wip/files/"\n'%root_srv_dom + \ + 'srv_www = "%s/www/"\n'%root_srv_dom + \ + 'srv_www_tpl = "%s"\n'%srv_www_tpl + \ + 'srv_www_images = "%s/www/images/"\n'%root_srv_dom + \ + 'srv_www_files = "%s/www/files/"\n'%root_srv_dom + \ + '\n' + \ + '# Servers files\n' + \ + 'wip_navbar = "%snavbar.html"\n'%srv_wip_tpl + \ + 'wip_sidebar = "%ssidebar.html"\n'%srv_wip_tpl + \ + 'wip_metas = "%smetas.html"\n'%srv_wip_tpl + \ + 'wip_footer = "%sfooter.html"\n'%srv_wip_tpl + \ + 'www_navbar = "%snavbar.html"\n'%srv_www_tpl + \ + 'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \ + 'www_metas = "%smetas.html"\n'%srv_www_tpl + \ + 'www_footer = "%sfooter.html"\n'%srv_www_tpl + tyto.set_file(db.domain_conf, False, srvs) # Get title domain #----------------- - try: domain_title = tyto.domain_title + try: domain_title = db.domain_title except: domain_title = '' ask = '' ask = input(' ├ Domain title ? ("%s") '%domain_title) if ask: domain_title = ask - elif not domain_title: tyto.exit("255") + elif not domain_title: logs.out("255", '', True) if '"' in domain_title: domain_title = domain_title.replace('"', '') - tyto.set_file(tyto.domain_conf, False, - 'domain_title = "%s"'%domain_title) + tyto.set_file(db.domain_conf, False, + '# Domain user\'s settings\n' + \ + 'domain_title = "%s"'%domain_title + ) # Get Description domain #----------------------- - try: domain_about = tyto.domain_about + try: domain_about = db.domain_about except: domain_about = '' ask = '' ask = input(' ├ Domain Description ? ("%s") '%domain_about) if ask: domain_about = ask - elif not domain_about: tyto.exit("255") + elif not domain_about: logs.out("255", '', True) if '"' in domain_about: domain_about = domain_about.replace('"', '') - tyto.set_file(tyto.domain_conf, False, - 'domain_about = "%s"'%domain_about) + tyto.set_file(db.domain_conf, False, + 'domain_about = "%s"'%domain_about + ) # Get Lang domain #---------------- - try: domain_lang = tyto.domain_lang + try: domain_lang = db.domain_lang except: domain_lang = locale.getdefaultlocale()[0].split('_')[0] ask = '' ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang) if ask: if len(ask) == 2: domain_lang = ask - else: tyto.exiting("3", ask, True) - elif not domain_lang: tyto.exiting("255", '', True) + else: logs.out("3", ask, True) + elif not domain_lang: logs.out("255", '', True) - tyto.set_file(tyto.domain_conf, False, - 'domain_lang = "%s"'%domain_lang) + tyto.set_file(db.domain_conf, False, + 'domain_lang = "%s"'%domain_lang + ) # Get mail domain #---------------- - try: domain_mail = tyto.domain_mail + try: domain_mail = db.domain_mail except: domain_mail = '' ask = '' ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail) if ask: - if not "@" in ask and not "." in ask: tyto.exiting("3", ask, True) + if not "@" in ask and not "." in ask: logs.out("3", ask, True) domain_mail = ask - elif not domain_mail: tyto.exiting("255", '', True) + elif not domain_mail: logs.out("255", '', True) - tyto.set_file(tyto.domain_conf, False, - 'domain_mail = "%s"'%domain_mail) + tyto.set_file(db.domain_conf, False, + 'domain_mail = "%s"'%domain_mail + ) # Get Tags domain #---------------- - try: domain_tags = tyto.domain_tags + try: domain_tags = db.domain_tags except: domain_tags = '' ask = '' ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags) if ask: domain_tags = ask - elif not domain_tags: tyto.exiting("255", '', True) + elif not domain_tags: logs.out("255", '', True) - tyto.set_file(tyto.domain_conf, False, - 'domain_tags = "%s"'%domain_tags) + tyto.set_file(db.domain_conf, False, + 'domain_tags = "%s"'%domain_tags + ) # Get logo's website #------------------- - try: domain_logo = tyto.domain_logo + try: domain_logo = db.domain_logo except: domain_logo = 'logo.png' ask = '' ask = input(' ├ logo filename ? ("%s") '%domain_logo) - tyto.set_file(tyto.domain_conf, False, - 'domain_logo = "%s"'%domain_logo) + if ask: domain_logo = ask + + tyto.set_file(db.domain_conf, False, + 'domain_logo = "%s"\n'%domain_logo + \ + 'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \ + 'www_logo = "%s%s"\n'%(srv_www_tpl, domain_logo) + ) # Get License domain #------------------- - try: domain_license = tyto.domain_license + try: domain_license = db.domain_license except: domain_license = 'CC BY-NC-SA' ask = '' ask = input(' ├ Domain License ? ("%s") '%domain_license) if ask: domain_license = ask - elif not domain_license: tyto.exiting("255", '', True) + elif not domain_license: logs.out("255", '', True) if '"' in domain_license: domain_license = domain_license.replace('"', '') - tyto.set_file(tyto.domain_conf, False, - 'domain_license = "%s"'%domain_license) + tyto.set_file(db.domain_conf, False, + 'domain_license = "%s"'%domain_license + ) # Get License URL (optionnal) #---------------------------- - try: domain_licurl = tyto.domain_licurl + try: domain_licurl = db.domain_licurl except: domain_licurl = '' ask = '' ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl) if ask: - if not ask.startswith('http'): tyto.exiting("3", ask, True) + if not ask.startswith('http'): logs.out("3", ask, True) domain_licurl = ask - tyto.set_file(tyto.domain_conf, False, - 'domain_licurl = "%s"'%domain_licurl) + tyto.set_file(db.domain_conf, False, + 'domain_licurl = "%s"'%domain_licurl + ) # CSS Prefix #----------- - try: domain_css = tyto.domain_css + try: domain_css = db.domain_css except: domain_css = 'tyto' ask = '' ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css) if ask: - if not ask.isalnum(): tyto.exiting("3", ask, True) + if not ask.isalnum(): logs.out("3", ask, True) domain_css = ask.lower() - tyto.set_file(tyto.domain_conf, False, - 'domain_css = "%s"'%domain_css) + tyto.set_file(db.domain_conf, False, + 'domain_css = "%s"'%domain_css + ) # Titles webpage separator #------------------------- - try: domain_sep = tyto.domain_sep + try: domain_sep = db.domain_sep except: domain_sep = "-" ask = '' ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep) if ask: - if not len(ask) == 1: tyto.exiting("3", ask, True) + if not len(ask) == 1: logs.out("3", ask, True) domain_sep = ask - tyto.set_file(tyto.domain_conf, False, - 'domain_sep = "%s"'%domain_sep) + tyto.set_file(db.domain_conf, False, + 'domain_sep = "%s"'%domain_sep + ) # Profile for rel="me" (optionnal) #--------------------------------- - try: domain_relme = tyto.domain_relme + try: domain_relme = db.domain_relme except: domain_relme = '' ask = '' ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme) if ask: - if not ask.startswith('http'): tyto.exiting("3", ask, True) + if not ask.startswith('http'): logs.out("3", ask, True) domain_relme = ask - tyto.set_file(tyto.domain_conf, False, - 'domain_relme = "%s"'%domain_relme) - - - # Activate menu bar from tyto.navbar ? - #------------------------------------- - try: domain_menubar = tyto.domain_menubar - except: domain_menubar = 'False' - - ask = '' - ask = input(' ├ Create menu bar from tyto.navbar file ? (%s) '%( - domain_menubar - ) - ) - - 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)) + tyto.set_file(db.domain_conf, False, + 'domain_relme = "%s"'%domain_relme + ) # Sidebar Title #-------------- - try: sidebar_title = tyto.sidebar_title + try: sidebar_title = db.sidebar_title except: sidebar_title = tyto.trans[0][tyto.n] - - if domain_sidebar: - ask = '' - ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title) - if ask: sidebar_title = ask - if '"' in sidebar_title: - sidebar_title = sidebar_title.replace('"', '') - tyto.set_file(tyto.domain_conf, False, - 'sidebar_title = "%s"'%(sidebar_title)) + 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(db.domain_conf, False, + 'sidebar_title = "%s"'%(sidebar_title) + ) # Sidebar Items #-------------- - try: sidebar_items = tyto.sidebar_items + try: sidebar_items = db.sidebar_items except: sidebar_items = "6" - if domain_sidebar: - ask = '' - ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items) - if ask: - if not ask.isdigit(): tyto.exiting("3", ask, True) - elif int(ask) in range(1,17): sidebar_items = int(ask) - - tyto.set_file(tyto.domain_conf, False, - 'sidebar_items = %s'%(sidebar_items)) - - - # Get srv root - #------------- - try: domain_srv = tyto.domain_srv - except: domain_srv = '/var/www' - ask = '' - ask = input(' ├ System server ? ("%s") '%domain_srv) + ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items) if ask: - if not os.path.exists(srv): tyto.exiting("1", ask, True) - elif not domain_srv: tyto.exiting("255", '', True) + if not ask.isdigit(): logs.out("3", ask, True) + elif int(ask) in range(1,17): sidebar_items = int(ask) - root_srv_dom = '%s/%s'%(domain_srv, domain_short) - srvs = '\nsrv_root = "%s/"\n'%domain_srv + \ - 'srv_domain = "%s/"\n'%root_srv_dom + \ - 'srv_wip = "%s/wip/"\n'%root_srv_dom + \ - 'srv_wip_tpl = "%s/wip/template/"\n'%root_srv_dom + \ - 'srv_wip_images = "%s/wip/images/"\n'%root_srv_dom + \ - 'srv_wip_files = "%s/wip/files/"\n'%root_srv_dom + \ - 'srv_www = "%s/www/"\n'%root_srv_dom + \ - 'srv_www_tpl = "%s/www/template/"\n'%root_srv_dom + \ - 'srv_www_images = "%s/www/images/"\n'%root_srv_dom + \ - 'srv_www_files = "%s/www/files/"'%root_srv_dom - tyto.set_file(tyto.domain_conf, False, srvs) + tyto.set_file(db.domain_conf, False, + 'sidebar_items = %s'%(sidebar_items) + ) # Activate Domain after Resumed configuration ? #---------------------------------------------- - try: domain_active = tyto.domain_active + try: domain_active = db.domain_active except: domain_active = False - file = open(tyto.domain_conf, 'r').read() + file = open(db.domain_conf, 'r').read() resume = ' │\n' + \ ' ├──────────────────────────────────────┐\n' + \ ' │ Please, READ the configuration datas │\n' + \ @@ -403,16 +415,15 @@ def create_domain(target, option): ask = input(' ├ Activate and prepare domain ? ') if not ask in ['y', 'Y']: - tyto.set_file(tyto.domain_conf, False, - '\ndomain_active = False') - tyto.exiting("255", '', True) + tyto.set_file(db.domain_conf, False, '\ndomain_active = False') + logs.out("255", '', True) # Activate Domain #---------------- - tyto.set_file(tyto.domain_conf, False, '\ndomain_active = True') + tyto.set_file(db.domain_conf, False, '\ndomain_active = True') # Load config - exec(open(tyto.domain_conf).read(),globals()) + exec(open(db.domain_conf).read(),globals()) # Create folders from configuration file folders = ( @@ -434,9 +445,9 @@ def create_domain(target, option): print(' │') #create_sidebar(option) html.manage_configs('sidebar', 'Force') - html.manage_configs('navbar', 'Force') - html.manage_configs('metas', 'Force') - html.manage_configs('footer', 'Force') + html.manage_configs('navbar', 'Force') + html.manage_configs('metas', 'Force') + html.manage_configs('footer', 'Force') print(' │') print(' ├──────────────────────────────────────┐') @@ -448,12 +459,45 @@ def create_domain(target, option): # sidebar load file translated # #------------------------------# def create_sidebar(option): - sidebar_load = tyto.sidebar_load + if not db.domain_active: return + + # Create an empty html file if not exists + if not os.path.exists(db.wip_sidebar): + tyto.set_file(db.wip_sidebar, 'new', '') + print(' ├ Create file: %s'%db.wip_sidebar) + + create_load = False # file in _configs + create_html = False # file in template/ + + # Get metas_load hash or create metas db file if not exists + #---------------------------------------------------------- + if os.path.exists(db.sidebar_load): + html.create_db_load(db.sidebar_load, db.sidebar_load_db) + + # Manage option + #-------------- + if not os.path.exists(db.sidebar_load): + create_load = True + elif option == 'New': + create_load = True + elif option == 'Create': + create_html = True + elif option == 'Edit': + hash_load_old = tyto.get_filesum(db.sidebar_load, True) + tyto.edit_file(db.sidebar_load) + hash_load_new = tyto.get_filesum(db.sidebar_load, True) + if not hash_load_old == hash_load_new: + html.create_db_load(db.sidebar_load, db.sidebar_load_db) + create_html = True + elif option == 'Force': + create_load = True + + # French sidebar_load content sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \ '# Type : fichier texte\n' + \ '# Description : Fichier appelé par "tyto sidebar"\n' + \ '# (Liste d\'articles)\n' + \ - '# Fichier : %s\n'%sidebar_load + \ + '# Fichier : %s\n'%db.sidebar_load + \ '# Comment : 1 URI de l\'article par ligne\n' + \ '# (depuis articles/)\n' + \ '# Ne commence pas par "/"\n' + \ @@ -464,11 +508,12 @@ def create_sidebar(option): '# dir1/index.tyto\n' + \ '# %s\n\n'%(15 * "-") + # English sidebar_load content sdb_load_en = '# For: Tyto - Littérateur\n' + \ '# Type: Text file\n' + \ '# Description: file called with "tyto sidebar"\n' + \ '# (articles\'s list)\n' + \ - '# File: %s\n'%sidebar_load + \ + '# File: %s\n'%db.sidebar_load + \ '# Comment: 1 article URI per line\n' + \ '# (from articles/)\n' + \ '# not begining with "/"\n' + \ @@ -479,31 +524,71 @@ def create_sidebar(option): '# dir1/index.tyto\n' + \ '# %s\n\n'%(15 * "-") + # Set language file if tyto.n == 0: sdb_load = sdb_load_fr elif tyto.n == 1: sdb_load = sdb_load_en - # Create new file, or ask if exists - ask = ' ├ Use default (empty) _configs/tyto.sidebar file ? ' - log = ' ├ Create file: %s'%sidebar_load - - if os.path.exists(sidebar_load): - res = input(ask) - if not res in ['y', 'Y']: return - - tyto.set_file(sidebar_load, 'new', sdb_load) - print(log) + # Create sidebar_load + if create_load: + # Create new file, or ask if exists + ask = ' ├ Use default (empty) sidebar configuration ? ' + log = ' ├ Create file: %s'%db.sidebar_load + res = '' + if os.path.exists(db.sidebar_load): + res = input(ask) + if not res in ['y', 'Y']: return + + tyto.set_file(db.sidebar_load, 'new', sdb_load) + print(log) + html.create_db_load(db.sidebar_load, db.sidebar_load_db) + + # Create wip/template/sidebar.html + if create_html: + html.create_sidebar(db.wip_sidebar) #=============================# # navbar load file translated # #-----------------------------# def create_navbar(option): - navbar_load = tyto.navbar_load + if not db.domain_active: return + + # Create an empty html file if not exists + if not os.path.exists(db.wip_navbar): + tyto.set_file(db.wip_navbar, 'new', '') + print(' ├ Create file: %s'%db.wip_navbar) + + create_load = False # file in _configs + create_html = False # file in template/ + + # Get metas_load hash or create metas db file if not exists + #---------------------------------------------------------- + if os.path.exists(db.navbar_load): + html.create_db_load(db.navbar_load, db.navbar_load_db) + + # Manage option + #-------------- + if not os.path.exists(db.navbar_load): + create_load = True + elif option == 'New': + create_load = True + elif option == 'Create': + create_html = True + elif option == 'Edit': + hash_load_old = tyto.get_filesum(db.navbar_load, True) + tyto.edit_file(db.navbar_load) + hash_load_new = tyto.get_filesum(db.navbar_load, True) + if not hash_load_old == hash_load_new: + html.create_db_load(db.navbar_load, db.navbar_load_db) + create_html = True + elif option == 'Force': + create_load = True + nav_load_fr = '# Pour : Tyto - Littérateur\n' + \ '# Type : fichier texte\n' + \ '# Description : Fichier utilisé par "tyto wip"\n' + \ '# (Liste des catégories)\n' + \ - '# Fichier : %s\n'%navbar_load + \ + '# Fichier : %s\n'%db.navbar_load + \ '# Comment : 1 nom de dossier par ligne *1\n' + \ '# (depuis articles/)\n' + \ '# Ne commence pas par "/"\n' + \ @@ -524,7 +609,7 @@ def create_navbar(option): '# Type: Text file\n' + \ '# Description: file used with "tyto wip"\n' + \ '# (categories\'s list)\n' + \ - '# File : %s\n'%navbar_load + \ + '# File : %s\n'%db.navbar_load + \ '# Comment: 1 folder name per line *1\n' + \ '# (from articles/)\n' + \ '# not begining with "/"\n' + \ @@ -541,16 +626,24 @@ def create_navbar(option): '# about # infos about this website\n' + \ '# %s\n\n'%(15 * "-") - if tyto.n == 0: nav_load = nav_load_fr - elif tyto.n == 1: nav_load = nav_load_en + # Set language file + if tyto.n == 0: nvb_load = nav_load_fr + elif tyto.n == 1: nvb_load = nav_load_en - # Create new file, or ask if exists - ask = ' ├ Use default (empty) _configs/tyto.navbar file ? ' - log = ' ├ Create file: %s'%navbar_load - - if os.path.exists(navbar_load): - res = input(ask) - if not res in ['y', 'Y']: return - - tyto.set_file(navbar_load, 'new', nav_load) - print(log) + # Create sidebar_load + if create_load: + # Create new file, or ask if exists + ask = ' ├ Use default (empty) navbar configuration ? ' + log = ' ├ Create file: %s'%db.navbar_load + res = '' + if os.path.exists(db.navbar_load): + res = input(ask) + if not res in ['y', 'Y']: return + + tyto.set_file(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) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index a193600..0afdf0c 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -16,23 +16,9 @@ #---------------------------------------------------------------------- #********************************************************************** + import os, sys - -import tyto, domain - -# Load domain configuration DB -exec(open(tyto.domain_conf).read()) - -Tyto = 'Tyto - Littérateur' -Tytogit = 'https://git.a-lec.org/echolib/tyto-litterateur' -Tytogti = 'Dépôt officiel du code source de Tyto - Littérateur' -Tytoweb = 'https://tyto.echolib.re' -Tytowti = 'Site web officiel du logiciel Tyto - Littérateur' -Tytosrc = '(Code source)' - -navbar_file = '%snavbar.html'%srv_wip_tpl +import logs, db, tyto, domain #==================================# @@ -40,16 +26,17 @@ navbar_file = '%snavbar.html'%srv_wip_tpl # (sidebar, metas, footer, navbar) # #----------------------------------# def manage_configs(target, option): - + # Arguments args1 = ('metas', 'sidebar', 'footer', 'navbar') - args2 = ('-n', '-e', '-F', ) - opts = ('New', 'Edit', 'Force') + args2 = ('-n', '-e', '-F', '-c') + opts = ('New', 'Edit', 'Force', 'Create') + # Check arguments (from form domain) if target in args1: sys.argv[1] = target elif target and not option: option = target - if not sys.argv[1] in args1: tyto.exiting('11', '%s'%str(args1), True) + if not sys.argv[1] in args1: logs.out('11', '%s'%str(args1), True) if not option in opts and not option == '-i' and not option in args2: - tyto.exiting('11', '%s'%str(args2), True) + logs.out('11', '%s'%str(args2), True) actions = { 'sidebar' : domain.create_sidebar, @@ -69,7 +56,7 @@ def set_page(post_db, target, article_bottom): exec(open(post_db).read(),globals()) create_metas_page() # Include metas tags - create_main_page(target, article_bottom) # At last, create main page + create_main_page(target, article_bottom) # Create main page #============================================# @@ -82,22 +69,24 @@ def create_metas_page(): #------------------- metas_page = '' scale = 'width=device-width, initial-scale=1.0' - all_tags = domain_tags + ',' + tags - post_url = domain_url + http_uri + all_tags = db.domain_tags + ',' + tags css_file = 'template/style.css' - css_ref = 'media="screen" href="%s%s" />'%(sub_uri, css_file) + css_ref = 'media="screen" href="%s%s"'%(sub_uri, css_file) rss_file = 'rss.xml' rss_ref = 'type="application/rss+xml" ' + \ 'href="%s%s" title="RSS 2.0. %s %s %s'%( - sub_uri, rss_file, domain_title, domain_sep, domain_short + sub_uri, rss_file, + db.domain_title, db.domain_sep, db.domain_short ) icon_file = 'favicon.png' - icon_ref = 'type="image/png" href="%stemplate/%s"'%(sub_uri, icon_file) + icon_ref = 'type="image/png" href="%stemplate/%s"'%( + sub_uri, icon_file + ) en_date = tyto.set_en_date(date[0]) relme = '' # External URL in metas (if exists in config domain) - if domain_relme: + if db.domain_relme: relme = '\n '%( - domain_relme + db.domain_relme ) # Set all raw HTML metas @@ -106,29 +95,29 @@ def create_metas_page(): metas = \ ' \n' + \ ' \n'%scale + \ - ' \n'%domain_url + \ - ' \n'%domain_lang + \ - ' \n'%domain_mail + \ - ' \n'%domain_license + \ - ' \n'%Tyto + \ + ' \n'%db.domain_www_url + \ + ' \n'%db.domain_lang + \ + ' \n'%db.domain_mail + \ + ' \n'%db.domain_license + \ + ' \n'%tyto.Tyto + \ ' \n'%title + \ ' \n'%author + \ ' \n'%about + \ ' \n'%all_tags + \ ' \n'%en_date + \ - ' \n'%post_url + \ + ' \n'%http_www + \ ' \n'%(rss_ref) + \ - ' '%icon_ref + \ + ' \n'%css_ref + \ + ' \n'%icon_ref + \ ' \n' + \ - ' \n'%domain_title + \ + ' \n'%db.domain_title + \ ' \n'%title + \ ' \n' + \ - ' \n'%post_url + \ + ' \n'%http_www + \ ' \n'%about + \ ' \n'%snpic + \ '%s'%relme + \ - '\n\n' + \ + '\n' + \ '
%s
\n'%domain_about + \ + '%s
\n'%db.domain_about + \ ' \n' + \ '\n' + \ ' \n' + \ '\n' + \ '