diff --git a/src/var/lib/tyto/program/args.py b/src/var/lib/tyto/program/args.py index 0342b9e..d401a62 100644 --- a/src/var/lib/tyto/program/args.py +++ b/src/var/lib/tyto/program/args.py @@ -60,6 +60,11 @@ arguments = ( 'again' ) + +pass_actions = ( + 'domain' + ) + option = '' target = '' diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 2acde83..c67376a 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -26,8 +26,6 @@ import time import logs, db, tyto post_err = False -date_wip = hash_wip = date_www = hash_www = '' - #=========================# # Manage Argument 'check' # @@ -36,40 +34,81 @@ date_wip = hash_wip = date_www = hash_www = '' def manage_check(target, option): # target needed if not target: logs.out("5", '', True) - - - global post_bottom, article_bottom - global post_words - - # Article exists + has DB ? - db_exists = tyto.get_db_post(target) # Manage option + #-------------- if option == 'Edit': - tyto.edit_file(tyto.uri_file) + tyto.edit_file(db.uri_file) return elif option == 'Show': - article_raw = open(tyto.uri_file).read() + article_raw = open(db.uri_file).read() for line in article_raw.rsplit('\n'): print(line) return - - if db_exists: - # Just read the DB from command - if option == 'DB': - article_db = open(tyto.post_db).read() + # Just read the DB from command + elif option == 'DB': + if db.db_exists: + article_db = open(db.post_db).read() for line in article_db.rsplit('\n'): print(line) return + else: + logs.out("25", db.uri_file, True) - try: - exec(open(tyto.post_db).read(),globals()) - if hash_chk == tyto.hash_post and not option == 'Force': - logs.out("20", date_chk, True) - finally: pass + # Article has DB + if db.db_exists: + # ... but domain needs to be active and ready + if not db.domain_active: sys.exit(1) + if db.incomplete_domain: sys.exit(1) + + # ... was already check and not changed + if db.hash_chk == db.hash_post and not option == 'Force': + logs.out("20", db.date_chk, True) + + # ... Set values for wip and www from DB + global date_wip, hash_wip, date_www, hash_www + date_wip = hash_wip = date_www = hash_www = '' + + date_wip = db.date_wip + hash_wip = db.hash_wip + date_www = db.date_www + hash_www = db.hash_wip - # Start processes - file_to_string(tyto.uri_file) + # Set variables + #-------------- + global post_bottom, article_bottom + global post_words + + # Get extension from target, set short uris + ext_src = os.path.splitext(target) + + # Get uri after articles/ (no starting / in value) + global src_post_short_uri, srv_post_short_uri + global srv_post_wip_uri, srv_post_www_uri + src_post_short_uri = db.uri_file.rsplit(db.domain_articles)[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 + + # Get sub_uri for HTML + 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 * '../' + + # Set HTTP link for wip and www + global http_www, http_wip + if srv_post_short_uri.endswith('index.html'): + http_www = "%s/"%db.domain_www_url + http_wip = '%s/'%db.domain_wip_url + else: + http_www = "%s%s"%(db.domain_www_url, srv_post_short_uri) + http_wip = '%s%s'%(db.domain_wip_url, srv_post_short_uri) + + # Start checking processes + #------------------------- + file_to_string(db.uri_file) # Specific to inline-code: check markers on same line check_icodes(article.rsplit('\n')) @@ -614,7 +653,7 @@ def check_content(post_bottom): ptag = '_%s'%htag if line.startswith(ptag): - ptag_set = line.rsplit(':', 1)[1].lstrip() # Get set tag + ptag_set = line.rsplit(':', 1)[1].lstrip().rsplit(' ')[0] if ptag_set in set_tags: continue for hline in post_header: if re.search(r"^%s\s+%s$"%(htag,ptag_set), hline): @@ -641,19 +680,19 @@ def check_content(post_bottom): #-----------------------------------------------# def create_database(): database = '# Post Configuration for Tyto\n' + \ - '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 + \ + 'post_id = "%s"\n'%db.uri_id + \ + 'post_src = "%s"\n'%db.uri_file + \ + 'post_wip = "%s"\n'%srv_post_wip_uri + \ + 'post_www = "%s"\n'%srv_post_www_uri + \ '\n' + \ - 'short_src = "%s"\n'%tyto.src_post_short_uri + \ - 'short_srv = "%s"\n'%tyto.srv_post_short_uri + \ - 'sub_uri = "%s"\n'%tyto.sub_uri + \ - 'http_wip = "%s"\n'%tyto.http_wip + \ - 'http_www = "%s"\n'%tyto.http_www + \ + 'short_src = "%s"\n'%src_post_short_uri + \ + 'short_srv = "%s"\n'%srv_post_short_uri + \ + 'sub_uri = "%s"\n'%sub_uri + \ + 'http_wip = "%s"\n'%http_wip + \ + 'http_www = "%s"\n'%http_www + \ '\n' + \ 'date_chk = "%s"\n'%tyto.nowdate() + \ - 'hash_chk = "%s"\n'%tyto.hash_post + \ + 'hash_chk = "%s"\n'%db.hash_post + \ 'date_wip = "%s"\n'%date_wip + \ 'hash_wip = "%s"\n'%hash_wip + \ 'date_www = "%s"\n'%date_www + \ @@ -726,5 +765,5 @@ def create_database(): 'stat_lists = %d\n'%post_lists database = '%s\n%s'%(database, db_stats) - tyto.set_file(tyto.post_db, 'new', database) + tyto.set_file(db.post_db, 'new', database) logs.out("21", '', True) diff --git a/src/var/lib/tyto/program/db.py b/src/var/lib/tyto/program/db.py index b76d832..66be81d 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 and exec +# Description: Search DBs (domain + post) and exec # file: db.py # Folder: /var/lib/tyto/program/ # By echolib (XMPP: im@echolib.re) @@ -18,7 +18,7 @@ #********************************************************************** import os, sys -import args, logs +import args, logs, tyto # Settings #--------- @@ -39,7 +39,7 @@ domain_values = ( 'domain_articles', 'domain_files', 'domain_images', - 'domain_db', + 'articles_db', 'html_db', 'navbars_dir', 'navbar_load', @@ -109,8 +109,12 @@ 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 -#----------------------- + +#====================================================================== +#------------------------# +# Check if domain is set # +#------------------------# +#====================================================================== stdout = '%s %s domain "%s" in %s' # Show domain status if domain_exists: @@ -137,3 +141,38 @@ if domain_exists: else: logs.out("43", domain_conf, False) + +#====================================================================== +#--------------------------------# +# Get post DB from target # +# Get some post settings fom uri # +#--------------------------------# +#====================================================================== +if args.target: + if not sys.argv[1] in args.pass_actions: + uri_file = '%s/%s'%(in_dir, args.target) + if not os.path.exists(uri_file): + logs.out("1", uri_file, True) + + # Get hash for uri and content file + uri_id = tyto.get_filesum(uri_file, False) + hash_post = tyto.get_filesum(uri_file, True) + + + if domain_exists and not incomplete_domain: + # Set DB file for this post + post_db = '%s%s.conf'%(articles_db, uri_id) + if not os.path.exists(post_db): + db_exists = False + else: + if os.stat(post_db).st_size < 1000: + os.remove(post_db) + logs.out('23', post_db, False) + db_exists = False + else: + db_exists = True + + # Load post database + if db_exists: + exec(open(post_db).read(),globals()) + diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 7d4ca55..b26bec3 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -20,6 +20,7 @@ import os, sys, locale import logs, db, tyto, html + #==========================# # Manage Argument 'domain' # #--------------------------# @@ -87,7 +88,11 @@ def create_domain(target, option): valid_url = ('http://', 'https://') ask = '' - ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url) + 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", 'http(s)://...', True) @@ -113,7 +118,11 @@ def create_domain(target, option): except: domain_wip_url = try_wip_url ask = '' - ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url) + try: + ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) if ask: isurl(ask) domain_wip_url = ask @@ -128,7 +137,7 @@ def create_domain(target, option): '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 + \ + 'articles_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 + \ @@ -152,7 +161,11 @@ def create_domain(target, option): except: domain_srv = '/var/www' ask = '' - ask = input(' ├ System server ? ("%s") '%domain_srv) + 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) @@ -190,7 +203,11 @@ def create_domain(target, option): except: domain_title = '' ask = '' - ask = input(' ├ Domain title ? ("%s") '%domain_title) + 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: @@ -208,7 +225,11 @@ def create_domain(target, option): except: domain_about = '' ask = '' - ask = input(' ├ Domain Description ? ("%s") '%domain_about) + 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: @@ -225,7 +246,11 @@ def create_domain(target, option): except: domain_lang = locale.getdefaultlocale()[0].split('_')[0] ask = '' - ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang) + try: + ask = input(' ├ [2 characters] 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) @@ -242,7 +267,11 @@ def create_domain(target, option): except: domain_mail = '' ask = '' - ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail) + 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 @@ -259,7 +288,11 @@ def create_domain(target, option): except: domain_tags = '' ask = '' - ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags) + 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) @@ -274,7 +307,11 @@ def create_domain(target, option): except: domain_logo = 'logo.png' ask = '' - ask = input(' ├ logo filename ? ("%s") '%domain_logo) + try: + ask = input(' ├ logo filename ? ("%s") '%domain_logo) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) if ask: domain_logo = ask tyto.set_file(db.domain_conf, False, @@ -290,7 +327,11 @@ def create_domain(target, option): except: domain_license = 'CC BY-NC-SA' ask = '' - ask = input(' ├ Domain License ? ("%s") '%domain_license) + 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: @@ -307,7 +348,11 @@ def create_domain(target, option): except: domain_licurl = '' ask = '' - ask = input(' ├ Optional. License URL ? ("%s") '%domain_licurl) + 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 @@ -323,7 +368,11 @@ def create_domain(target, option): except: domain_css = 'tyto' ask = '' - ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css) + 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() @@ -339,7 +388,11 @@ def create_domain(target, option): except: domain_sep = "-" ask = '' - ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep) + try: + ask = input(' ├ [1 character] 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 @@ -355,7 +408,11 @@ def create_domain(target, option): except: domain_relme = '' ask = '' - ask = input(' ├ Optional. Profile URL ? ("%s") '%domain_relme) + try: + ask = input(' ├ Optional. Profile 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 @@ -371,7 +428,11 @@ def create_domain(target, option): except: sidebar_title = tyto.trans[0][tyto.n] ask = '' - ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title) + 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('"', '') @@ -387,7 +448,11 @@ def create_domain(target, option): except: sidebar_items = "6" ask = '' - ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items) + 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) @@ -413,7 +478,11 @@ def create_domain(target, option): for line in file.rsplit('\n'): print(' │', line) - ask = input(' ├ Activate and prepare domain ? ') + 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) @@ -443,7 +512,6 @@ def create_domain(target, option): # Create in _configs files # Force will ask to create in template print(' │') - #create_sidebar(option) html.manage_configs('sidebar', 'Force') html.manage_configs('navbar', 'Force') html.manage_configs('metas', 'Force') @@ -535,7 +603,11 @@ def create_sidebar(option): log = ' ├ Create file: %s'%db.sidebar_load res = '' if os.path.exists(db.sidebar_load): - res = input(ask) + try: + res = input(ask) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) if not res in ['y', 'Y']: return tyto.set_file(db.sidebar_load, 'new', sdb_load) @@ -637,7 +709,11 @@ def create_navbar(option): log = ' ├ Create file: %s'%db.navbar_load res = '' if os.path.exists(db.navbar_load): - res = input(ask) + try: + res = input(ask) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) if not res in ['y', 'Y']: return tyto.set_file(db.navbar_load, 'new', nvb_load) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 0afdf0c..65582cc 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -176,7 +176,7 @@ def create_main_page(target, article_bottom): '\n' + \ '
\n' + \ '
\n' + \ - '%s\n'%html_infos + \ + '%s\n'%post_pub + \ '
\n' + \ '%s\n'%article_bottom + \ '
\n' + \ @@ -191,8 +191,10 @@ def create_main_page(target, article_bottom): # Create HTML line for article infos section # # when wip, and publish # #--------------------------------------------# -def create_html_infos_section(process): - global html_infos +def create_html_infos_section(process): + # Need to reload the DB to get last time updated + exec(open(db.post_db).read(), globals()) + global post_pub if process == 'wip': date_raw = date_wip #