From 6eec2a7d90852a22e3833c66449ab9fc6d5c1ae6 Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Thu, 16 Feb 2023 11:36:40 +0100 Subject: [PATCH] updated footer/metas/navbar/sidebar managing --- src/var/lib/tyto/program/domain.py | 150 +++++++++++++++++++++++------ src/var/lib/tyto/program/html.py | 145 +++++----------------------- src/var/lib/tyto/program/new.py | 22 +++-- src/var/lib/tyto/program/tyto.py | 18 ++++ 4 files changed, 173 insertions(+), 162 deletions(-) diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 8ee2cff..80a257b 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -497,10 +497,12 @@ def create_domain(target): print(' │ Exists directory: %s'%folder) # Create in _configs files - # Force will ask to create in template + # Parameter could be used later print(' │') create_sidebar('new') create_navbar('new') + create_metas('new') + create_footer('new') print(' │') print(' ├──────────────────────────────────────┐') @@ -536,42 +538,51 @@ def create_sidebar(option): 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 appelé par "tyto sidebar"\n' + \ - '# (Liste d\'articles)\n' + \ - '# Fichier : %s\n'%db.sidebar_load + \ - '# Comment : 1 URI de l\'article par ligne\n' + \ - '# (depuis articles/)\n' + \ - '# Ne commence pas par "/"\n' + \ - '# L\'ordre définit la position\n' + \ - '\n# %s\n'%(15 * "-") +\ - '# Exemples :\n' + \ - '# index.tyto\n' + \ - '# dir1/index.tyto\n' + \ - '# %s\n\n'%(15 * "-") + 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'%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' + \ + '\n# %s\n'%(15 * "-") +\ + '# Exemples :\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: file called with "tyto sidebar"\n' + \ - '# (articles\'s list)\n' + \ - '# File: %s\n'%db.sidebar_load + \ - '# Comment: 1 article URI per line\n' + \ - '# (from articles/)\n' + \ - '# not begining with "/"\n' + \ - '# Order in sidebar position\n' + \ - '\n# %s\n'%(15 * "-") +\ - '# Examples :\n' + \ - '# index.tyto\n' + \ - '# dir1/index.tyto\n' + \ - '# %s\n\n'%(15 * "-") - + 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'%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' + \ + '\n# %s\n'%(15 * "-") +\ + '# Examples :\n' + \ + '# 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) + tyto.create_db_load(db.sidebar_load, db.sidebar_load_db) print(log) @@ -652,6 +663,7 @@ def create_navbar(option): elif tyto.n == 1: nvb_load = nav_load_en tyto.set_file(db.navbar_load, 'new', nvb_load) + tyto.create_db_load(db.navbar_load, db.navbar_load_db) print(log) @@ -669,7 +681,7 @@ def create_metas(option): '\n' + \ + '' + + # Create new default file, or ask if exists + ask = ' ├ Reset footer configuration file ? ' + log = ' ├ Create source file: %s'%db.footer_load + 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 + + tyto.set_file(db.footer_load, 'new', footer) + tyto.create_db_load(db.footer_load, db.footer_load_db) + print(log) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 5ccda05..768835b 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -206,24 +206,6 @@ def create_html_infos_section(process): ) -#========================================================# -# Create DB file with hash from [type]_load file content # -#--------------------------------------------------------# -def create_db_load(file_load, file_db): - hash_load = tyto.get_filesum(file_load, True) - if not os.path.exists(file_db): - set_f = 'file_load_hash = "%s"'%hash_load - tyto.set_file(file_db, True, set_f) - return - - global file_load_hash - file_load_hash = '' - exec(open(file_db, 'r').read(), globals()) - if not file_load_hash == hash_load: - set_f = 'file_load_hash = "%s"'%hash_load - tyto.set_file(file_db, True, set_f) - - #============================================# # Create HTML sidebar from file tyto.sidebar # #--------------------------------------------# @@ -512,113 +494,32 @@ def create_user_metas(option): # Create generic footer from domain datas # #-----------------------------------------# def create_user_footer(option): - if not db.domain_exists: return + # Check if can process + domain.domain_needed() - create_load = False # file in _configs - create_html = False # file in template/ + if option == 'wip': target = db.wip_footer + elif option == 'www': target = db.www_footer + + ask_load = ' ├ Replace HTML footer: %s ? '%target + log_load = ' ├ Create file: %s'%target + res = '' + if os.path.exists(target): + try: + res = input(ask_load) + except KeyboardInterrupt: + print('') + logs.out("255", '', True) + if not res in ['y', 'Y']: return - # Get sidebar_load hash or create sidebar db file if not exists - #-------------------------------------------------------------- - if os.path.exists(db.footer_load): - create_db_load(db.footer_load, db.footer_load_db) - - # Manage option - #-------------- - if not os.path.exists(db.footer_load): - create_load = True - elif option == 'Force': - create_load = True - create_html = True - elif option == 'Create': - create_html = True - elif option == 'Edit': - hash_load_old = tyto.get_filesum(db.footer_load, True) - tyto.edit_file(db.footer_load) - hash_load_new = tyto.get_filesum(db.footer_load, True) - if not hash_load_old == hash_load_new: - create_db_load(db.footer_load, db.footer_load_db) - create_html = True + user_footer = '' + user_file = open(db.footer_load, 'r').read() + for line in user_file.rsplit('\n'): + if not line: continue + if user_footer: user_footer = "%s\n %s"%(user_footer, line) + else: user_footer = ' %s'%line - - # Default footer contents - Tytosrc = '(%s)'%tyto.trans[3][tyto.n] - - footer = \ - '\n'%tyto.Tyto + \ - '' - - - # Create new default footer_load, or ask if exists - #------------------------------------------------- - if create_load: - ask_load = ' ├ Reset footer configuration file ? ' - log_load = ' ├ Create file: %s'%db.footer_load - res = '' - if os.path.exists(db.footer_load): - try: - res = input(ask_load) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - - if not res in ['y', 'Y']: return - - create_html = True - tyto.set_file(db.footer_load, True, footer) - create_db_load(db.footer_load, db.footer_load_db) - print(log_load) - - - if create_html: - ask_load = ' ├ Replace HTML footer: %s ? '%db.wip_footer - log_load = ' ├ Create file: %s'%db.wip_footer - res = '' - if os.path.exists(db.wip_footer): - try: - res = input(ask_load) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - if not res in ['y', 'Y']: return - - user_footer = '' - user_file = open(db.footer_load, 'r').read() - for line in user_file.rsplit('\n'): - if not line: continue - if user_footer: user_footer = "%s\n %s"%(user_footer, line) - else: user_footer = ' %s'%line - - tyto.set_file(db.wip_footer, True, user_footer) - print(log_load) + tyto.set_file(target, True, user_footer) + print(log_load) diff --git a/src/var/lib/tyto/program/new.py b/src/var/lib/tyto/program/new.py index 3ecc0fd..f6cab67 100644 --- a/src/var/lib/tyto/program/new.py +++ b/src/var/lib/tyto/program/new.py @@ -26,13 +26,19 @@ import logs, args, db, domain, html # - domain: target becomes 3rd command argument # #-----------------------------------------------# def manage_new(target): + # Generic option, except for domain + option = 'new' if target == "domain": - try: URL = sys.argv[3] - except: URL = '' - domain.manage_domain(URL) + try: option = sys.argv[3] + except: option = '' - elif target == 'sidebar': - domain.create_sidebar('new') - - elif target == 'navbar': - domain.create_navbar('new') + if target in args.pass_targets: + actions = { + 'domain' : domain.manage_domain, + 'sidebar' : domain.create_sidebar, + 'navbar' : domain.create_navbar, + 'metas' : domain.create_metas, + 'footer' : domain.create_footer + } + + actions[target](option) diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 211ca0b..9d007a1 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -199,6 +199,24 @@ def set_file(path, new, text): logs.out("4", path, True) +#========================================================# +# Create DB file with hash from [type]_load file content # +#--------------------------------------------------------# +def create_db_load(file_load, file_db): + hash_load = get_filesum(file_load, True) + if not os.path.exists(file_db): + line = 'file_load_hash = "%s"'%hash_load + set_file(file_db, True, line) + return + + global file_load_hash + file_load_hash = '' + exec(open(file_db, 'r').read(), globals()) + if not file_load_hash == hash_load: + line = 'file_load_hash = "%s"'%hash_load + set_file(file_db, True, line) + + #==========================# # Get CSS from line if set # #--------------------------#