sidebar/navbar managing ; options new, edit, wip, publish

This commit is contained in:
Cyrille L 2023-02-15 12:26:32 +01:00
parent 6f141b6c30
commit c95cf9dc67
8 changed files with 112 additions and 77 deletions

View File

@ -42,22 +42,18 @@ import check, domain, html, new, publish, show, wip, infos
# Command start argument # Command start argument
actions = { actions = {
'check' : check.manage_check, 'check' : check.manage_check,
'help' : infos.tyto, 'help' : infos.tyto,
'edit' : show.manage_show, 'edit' : show.manage_show,
'edit-db' : show.manage_show, 'edit-db' : show.manage_show,
'edit-wip' : show.manage_show, 'edit-wip' : show.manage_show,
'edit-www' : show.manage_show, 'edit-www' : show.manage_show,
'footer' : html.manage_configs,
'metas' : html.manage_configs,
'navbar' : html.manage_configs,
'new' : new.manage_new, 'new' : new.manage_new,
'publish' : publish.manage_publish, 'publish' : publish.manage_publish,
'show' : show.manage_show, 'show' : show.manage_show,
'show-db' : show.manage_show, 'show-db' : show.manage_show,
'show-wip' : show.manage_show, 'show-wip' : show.manage_show,
'show-www' : show.manage_show, 'show-www' : show.manage_show,
'sidebar' : html.manage_configs,
'wip' : wip.manage_wip 'wip' : wip.manage_wip
} }

View File

@ -488,10 +488,8 @@ def create_domain(target):
# Create in _configs files # Create in _configs files
# Force will ask to create in template # Force will ask to create in template
print('') print('')
html.manage_configs('sidebar', 'Force') create_sidebar('new')
html.manage_configs('navbar', 'Force') create_navbar('new')
html.manage_configs('metas', 'Force')
html.manage_configs('footer', 'Force')
print('') print('')
print(' ├──────────────────────────────────────┐') print(' ├──────────────────────────────────────┐')
@ -509,16 +507,18 @@ def create_sidebar(option):
or not db.domain_active: or not db.domain_active:
return return
# Create an empty html file if not exists # Create an empty html file in wip server if not exists
try: try:
if not os.path.exists(db.wip_sidebar): if not os.path.exists(db.wip_sidebar):
tyto.set_file(db.wip_sidebar, 'new', '') tyto.set_file(db.wip_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.wip_sidebar) print(' ├ Create empty file: %s'%db.wip_sidebar)
return if not os.path.exists(db.www_sidebar):
tyto.set_file(db.www_sidebar, 'new', '')
print(' ├ Create empty file: %s'%db.www_sidebar)
except: except:
logs.out("4", db.wip_sidebar, True) logs.out("4", db.wip_sidebar, True)
# Create new file, or ask if exists # Create new file, or ask if exists with option = 'reset'
ask = ' ├ Reset sidebar configuration file ? ' ask = ' ├ Reset sidebar configuration file ? '
log = ' ├ Create source file: %s'%db.sidebar_load log = ' ├ Create source file: %s'%db.sidebar_load
res = '' res = ''
@ -580,10 +580,16 @@ def create_navbar(option):
or not db.domain_active: or not db.domain_active:
return return
# Create an empty html file if not exists # Create an empty html file in wip server if not exists
if not os.path.exists(db.wip_navbar): try:
tyto.set_file(db.wip_navbar, 'new', '') if not os.path.exists(db.wip_navbar):
print(' ├ Create empty file: %s'%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 new file, or ask if exists # Create new file, or ask if exists
ask = ' ├ Reset navbar configuration file ? ' ask = ' ├ Reset navbar configuration file ? '

View File

@ -21,32 +21,6 @@ import os, sys
import logs, db, tyto, domain import logs, db, tyto, domain
#==================================#
# Manage HTML files for user #
# (sidebar, metas, footer, navbar) #
#----------------------------------#
def manage_configs(target, option):
# Arguments
args1 = ('metas', 'sidebar', 'footer', 'navbar')
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: logs.out('11', '%s'%str(args1), True)
if not option in opts and not option == '-i' and not option in args2:
logs.out('11', '%s'%str(args2), True)
actions = {
'sidebar' : domain.create_sidebar,
'navbar' : domain.create_navbar,
'metas' : create_user_metas,
'footer' : create_user_footer
}
actions[sys.argv[1]](option)
#==========================# #==========================#
# Load article DB # # Load article DB #
# Start HTML page sections # # Start HTML page sections #
@ -253,18 +227,22 @@ def create_db_load(file_load, file_db):
#============================================# #============================================#
# Create HTML sidebar from file tyto.sidebar # # Create HTML sidebar from file tyto.sidebar #
#--------------------------------------------# #--------------------------------------------#
def create_sidebar(target): def create_sidebar(option):
# Check if can process # Check if can process
if not db.domain_exists \ if not db.domain_exists \
or db.incomplete_domain \ or db.incomplete_domain \
or not db.domain_active: or not db.domain_active:
return return
try: try:
db.sidebar_load db.sidebar_load
if not os.path.exists(db.sidebar_load): if not os.path.exists(db.sidebar_load):
logs.out("1", db.sidebar_load, True) logs.out("1", db.sidebar_load, True)
except: except:
logs.out("1", 'Sidebar source file', True) logs.out("1", 'Sidebar load file', True)
if option == 'wip': target = db.wip_sidebar
elif option == 'www': target = db.www_sidebar
# If content in sidebar, go True # If content in sidebar, go True
sidebar_new = False sidebar_new = False
@ -282,6 +260,7 @@ def create_sidebar(target):
counter = 0 counter = 0
nolines = ('#', '/') nolines = ('#', '/')
sidebar_title = db.sidebar_title
sidebar_lines = open(db.sidebar_load, 'r').read() sidebar_lines = open(db.sidebar_load, 'r').read()
for line in sidebar_lines.rsplit('\n'): for line in sidebar_lines.rsplit('\n'):
if not line or line.startswith(nolines): continue if not line or line.startswith(nolines): continue
@ -299,7 +278,7 @@ def create_sidebar(target):
# Get Hash from uri to get db file # Get Hash from uri to get db file
hash_uri = tyto.get_filesum(f_uri, False) hash_uri = tyto.get_filesum(f_uri, False)
db_uri = '%s%s.conf'%(db.domain_db, hash_uri) db_uri = '%s%s.conf'%(db.articles_db, hash_uri)
if not os.path.exists(db_uri): if not os.path.exists(db_uri):
logs.out('25', 'No Database', False) logs.out('25', 'No Database', False)
continue continue
@ -358,9 +337,9 @@ def create_sidebar(target):
# Create file if sidebar has content # Create file if sidebar has content
if sidebar_new: if sidebar_new:
ask_html = ' ├ Replace %s ? '%db.wip_sidebar ask_html = ' ├ Replace %s ? '%target
res = '' res = ''
if os.path.exists(db.wip_sidebar): if os.path.exists(target):
res = input(ask_html) res = input(ask_html)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
@ -371,8 +350,22 @@ def create_sidebar(target):
#====================================# #====================================#
# Create HTML menu from root folders # # Create HTML menu from root folders #
#------------------------------------# #------------------------------------#
def create_navbar(target): def create_navbar(option):
if not db.domain_exists: return # Check if can process
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
try:
db.navbar_load
if not os.path.exists(db.navbar_load):
logs.out("1", db.navbar_load, True)
except:
logs.out("1", 'Navbar load file', True)
if option == 'wip': target = db.wip_navbar
elif option == 'www': target = db.www_navbar
# If content in sidebar, go True # If content in sidebar, go True
navbar_new = False navbar_new = False
@ -404,20 +397,29 @@ def create_navbar(target):
# Check if an index.[ext] and index.html exist and log # Check if an index.[ext] and index.html exist and log
index_src = False index_src = False
index_wip = False index_wip = False
index_www = False
for f in os.listdir(dir_uri): for f in os.listdir(dir_uri):
if f.startswith("index."): if f.startswith("index."):
index_src = True index_src = True
wip_index = '%s%s/index.html'%(db.srv_wip, direc) if option == 'wip':
if not os.path.exists(wip_index): wip_index = '%s%s/index.html'%(db.srv_wip, direc)
logs.out('26', 'in "%s": %s'%(direc, wip_index), False) if not os.path.exists(wip_index):
else: logs.out('26', 'in "%s": %s'%(direc, wip_index), False)
index_wip = True else:
index_wip = True
elif option == 'www':
www_index = '%s%s/index.html'%(db.srv_www, direc)
if not os.path.exists(www_index):
logs.out('26', 'in "%s": %s'%(direc, www_index), False)
else:
index_www = True
else:
break break
if not index_src: if not index_src:
logs.out("26", 'in "%s": %s'%(direc, dir_uri), False) logs.out("26", 'in "%s": %s'%(direc, dir_uri), False)
continue continue
if not index_wip: if not index_wip and option == 'wip': continue
continue if not index_www and option == 'www': continue
# Add link to HTML structure # Add link to HTML structure
navbar_new = True navbar_new = True
@ -441,9 +443,9 @@ def create_navbar(target):
# Create file if sidebar has content # Create file if sidebar has content
if navbar_new: if navbar_new:
ask_html = ' ├ Replace %s ? '%db.wip_navbar ask_html = ' ├ Replace %s ? '%target
res = '' res = ''
if os.path.exists(db.wip_navbar): if os.path.exists(target):
try: try:
res = input(ask_html) res = input(ask_html)
except KeyboardInterrupt: except KeyboardInterrupt:
@ -452,8 +454,8 @@ def create_navbar(target):
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(navbar_file, True, menu_html) tyto.set_file(target, True, menu_html)
print(' ├ Create file: %s'%navbar_file) print(' ├ Create file: %s'%target)
#========================================================# #========================================================#

View File

@ -78,7 +78,7 @@ def tyto(target):
' sidebar : Create sidebar config/HTML code file\n\n' ' sidebar : Create sidebar config/HTML code file\n\n'
'# Examples:\n' '# Examples:\n'
' tyto new sidebar: create default source file /_configs/tyto.sidebar\n' ' tyto new sidebar: create default source file /_configs/tyto.sidebar\n'
' tyto publish sidebar: create code file in www server for pages\n' ' tyto edit navbar: edit file: /_configs/tyto.navbar\n'
' tyto edit-wip navbar: edit file: /wip/template/navbar.html\n' ' tyto wip sidebar: create sidebar.html in wip server\n'
' tyto edit navbar: edit /_configs/tyto.navbar\n' ' tyto publish navbar: create navbar.html in www server'
) )

View File

@ -18,7 +18,7 @@
#********************************************************************** #**********************************************************************
import sys import sys
import logs, args, db, domain import logs, args, db, domain, html
#===============================================# #===============================================#
@ -32,8 +32,7 @@ def manage_new(target):
domain.manage_domain(URL) domain.manage_domain(URL)
elif target == 'sidebar': elif target == 'sidebar':
domain.create_sidebar(target) domain.create_sidebar('new')
elif target == 'navbar': elif target == 'navbar':
domain.create_navbar(target) domain.create_navbar('new')

View File

@ -18,7 +18,7 @@
#********************************************************************** #**********************************************************************
import os, sys, shutil, importlib import os, sys, shutil, importlib
import db, logs, html, tyto import logs, args, db, html, tyto
#==============================# #==============================#
@ -26,7 +26,23 @@ import db, logs, html, tyto
# check if publish can be done # # check if publish can be done #
#------------------------------# #------------------------------#
def manage_publish(target): def manage_publish(target):
err_pub = False # Default (publish) # Check if can process
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
# Target is footer, sidebar, navbar, metas
if target in args.pass_targets:
do = {
'sidebar' : html.create_sidebar,
'navbar' : html.create_navbar
}
do[target]('www')
return
err_pub = False # Default (error to publish)
if not db.db_exists: if not db.db_exists:
logs.out("25", db.uri_file, True) logs.out("25", db.uri_file, True)

View File

@ -105,7 +105,7 @@ def manage_show(target):
elif args.action in actions_edit: tyto.edit_file(do[target]) elif args.action in actions_edit: tyto.edit_file(do[target])
# After editing article, if change, ask to check again # After editing article, if change, ask to check again
if args.action == "edit": if args.action == "edit" and not args.pass_targets:
new_hash = tyto.get_filesum(db.uri_file, True) new_hash = tyto.get_filesum(db.uri_file, True)
if curr_hash != new_hash: if curr_hash != new_hash:
ask = '' ask = ''

View File

@ -18,14 +18,30 @@
#********************************************************************** #**********************************************************************
import os, re, shutil import os, re, shutil
import logs, db, tyto, html import logs, args, db, tyto, html
#=========================================#
# Manage wip action with option as target #
#-----------------------------------------#
def manage_wip(target): def manage_wip(target):
global post_db, hash_post global post_db, hash_post
# Domain configuration must exist and active # Check if can process
if not db.domain_exists: return if not db.domain_exists \
if not db.domain_active: return or db.incomplete_domain \
or not db.domain_active:
return
# Target is footer, sidebar, navbar, metas
if target in args.pass_targets:
do = {
'sidebar' : html.create_sidebar,
'navbar' : html.create_navbar
}
do[target]('wip')
return
#----------------------------------------- #-----------------------------------------
# Option 'Again' to wip again, based on DB # Option 'Again' to wip again, based on DB