From 50baaf14f2c6f98521b661e5ac1a88bdbd6062ab Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Wed, 15 Feb 2023 23:47:14 +0100 Subject: [PATCH] added metas manager files (load, wip, publish) --- src/var/lib/tyto/program/domain.py | 136 ++++++++++++++++++++++------ src/var/lib/tyto/program/html.py | 121 ++++--------------------- src/var/lib/tyto/program/publish.py | 3 +- src/var/lib/tyto/program/tyto.py | 2 +- src/var/lib/tyto/program/wip.py | 3 +- 5 files changed, 130 insertions(+), 135 deletions(-) diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 27467f9..8ee2cff 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -38,6 +38,17 @@ def manage_domain(target): else: logs.out("255", '', True) +#==============================================# +# When an active and complete domain is needed # +#----------------------------------------------# +def domain_needed(): + # Check if can process + if not db.domain_exists \ + or db.incomplete_domain \ + or not db.domain_active: + sys.exit(1) + + #=====================# # Create a new domain # #---------------------# @@ -502,22 +513,16 @@ def create_domain(target): #------------------------------# def create_sidebar(option): # Check if can process - if not db.domain_exists \ - or db.incomplete_domain \ - or not db.domain_active: - return + domain_needed() - # Create an empty html file in wip server if not exists - try: - if not os.path.exists(db.wip_sidebar): - tyto.set_file(db.wip_sidebar, 'new', '') - print(' ├ Create empty file: %s'%db.wip_sidebar) - if not os.path.exists(db.www_sidebar): - tyto.set_file(db.www_sidebar, 'new', '') - print(' ├ Create empty file: %s'%db.www_sidebar) - except: - logs.out("4", db.wip_sidebar, True) - + # 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) + if not os.path.exists(db.www_sidebar): + tyto.set_file(db.www_sidebar, 'new', '') + print(' ├ Create empty file: %s'%db.www_sidebar) + # Create new file, or ask if exists with option = 'reset' ask = ' ├ Reset sidebar configuration file ? ' log = ' ├ Create source file: %s'%db.sidebar_load @@ -575,21 +580,15 @@ def create_sidebar(option): #-----------------------------# def create_navbar(option): # Check if can process - if not db.domain_exists \ - or db.incomplete_domain \ - or not db.domain_active: - return + domain_needed() - # Create an empty html file in wip server if not exists - try: - if not os.path.exists(db.wip_navbar): - tyto.set_file(db.wip_navbar, 'new', '') - print(' ├ Create empty file: %s'%db.wip_navbar) - if not os.path.exists(db.www_navbar): - tyto.set_file(db.www_navbar, 'new', '') - print(' ├ Create empty file: %s'%db.www_navbar) - except: - logs.out("4", db.wip_navbar, True) + # 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) + if not os.path.exists(db.www_navbar): + tyto.set_file(db.www_navbar, 'new', '') + print(' ├ Create empty file: %s'%db.www_navbar) # Create new file, or ask if exists ask = ' ├ Reset navbar configuration file ? ' @@ -654,3 +653,82 @@ def create_navbar(option): tyto.set_file(db.navbar_load, 'new', nvb_load) print(log) + + +#========================# +# metas_load source file # +#------------------------# +def create_metas(option): + # Check if can process + domain_needed() + + + # Set metas_load default content + #------------------------------- + metas_tags = \ + '\n' + \ + '\n' + \ + '\n' + \ + '' + + metas_srvs = \ + ' \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) + if not os.path.exists(db.www_metas): + tyto.set_file(db.www_metas, 'new', metas_srvs) + print(' ├ Create empty file: %s'%db.www_metas) + + # Create new file, or ask if exists + ask = ' ├ Reset metas configuration file ? ' + log = ' ├ Create source file: %s'%db.metas_load + 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) + print(log) + + + diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index f9bd9f9..5ccda05 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -475,112 +475,27 @@ def create_navbar(option): # Create DB file with hash from _configs/tyto.metas.html # # To manage new creation if changes # #--------------------------------------------------------# -def create_user_metas(option): - if not db.domain_exists: return +def create_user_metas(option): + # Check if can process + domain.domain_needed() - create_load = False # file in _configs - create_html = False # file in template/ - - # Get metas_load hash or create metas db file if not exists - #---------------------------------------------------------- - if os.path.exists(db.metas_load): - create_db_load(db.metas_load, db.metas_load_db) + if option == 'wip': target = db.wip_navbar + elif option == 'www': target = db.www_navbar - # Manage option - #-------------- - if not os.path.exists(db.metas_load): - create_load = True - elif option == 'New': - create_load = True - create_html = True - elif option == 'Create': - create_html = True - elif option == 'Edit': - hash_load_old = tyto.get_filesum(db.metas_load, True) - tyto.edit_file(db.metas_load) - hash_load_new = tyto.get_filesum(db.metas_load, True) - if not hash_load_old == hash_load_new: - create_db_load(db.metas_load, db.metas_load_db) - create_html = True - elif option == 'Force': - create_load = True - create_html = True - - # Set metas_load default content - #------------------------------- - metas_tags = \ - '\n' + \ - '\n' + \ - '\n' + \ - '' - - # Create metas_load file according to option - #------------------------------------------- - if create_load: - ask_load = ' ├ Reset metas configuration file ? ' - log_load = ' ├ Create file: %s'%db.metas_load - res = '' - if os.path.exists(db.metas_load): - try: - res = input(ask_load) - except KeyboardInterrupt: - print('') - logs.out("255", '', True) - if not res in ['y', 'Y']: return - - - tyto.set_file(db.metas_load, True, metas_tags) - create_html = True - create_db_load(db.metas_load, db.metas_load_db) - print(log_load) - # Create wip metas.html file according to option #----------------------------------------------- - if create_html: - ask_html = ' ├ Replace %s ? '%db.wip_metas - log_html = ' ├ Create file: %s'%db.wip_metas - user_metas = '' - metas_used = ('