working on publish template command

This commit is contained in:
Cyrille L 2023-03-03 15:57:54 +01:00
parent d866e0f34f
commit 60d4b1489a
5 changed files with 94 additions and 85 deletions

View File

@ -44,6 +44,7 @@ target = args.set_target()
# Command start argument # Command start argument
import check, domain, html, new, publish, show, wip, infos import check, domain, html, new, publish, show, wip, infos
actions = { actions = {
'all' : wip.manage_wip,
'check' : check.manage_check, 'check' : check.manage_check,
'help' : infos.tyto, 'help' : infos.tyto,
'edit' : show.manage_show, 'edit' : show.manage_show,
@ -56,8 +57,8 @@ actions = {
'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,
'template' : publish.manage_publish,
'wip' : wip.manage_wip, 'wip' : wip.manage_wip,
'all' : wip.manage_wip
} }

View File

@ -66,7 +66,8 @@ pass_targets = \
'footer', 'footer',
'metas', 'metas',
'navbar', 'navbar',
'sidebar' 'sidebar',
'template'
) )
action = '' action = ''

View File

@ -209,11 +209,7 @@ def create_html_infos_section(process):
# Create HTML sidebar from file tyto.sidebar # # Create HTML sidebar from file tyto.sidebar #
#--------------------------------------------# #--------------------------------------------#
def create_sidebar(option): def create_sidebar(option):
# Check if can process domain.domain_needed
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
try: try:
db.sidebar_load db.sidebar_load
@ -314,10 +310,12 @@ def create_sidebar(option):
if not sidebar_new: if not sidebar_new:
# Empty file # Empty file
if not sidebar_has: if not sidebar_has:
logs.out('29', '(sidebar): %s'%db.sidebar_load, True) logs.out('29', '(sidebar): %s'%db.sidebar_load, False)
return
# Some items, but no one is valid # Some items, but no one is valid
else: else:
logs.out('28', '(sidebar)', True) logs.out('28', '(sidebar)', False)
return
# Create HTML complete sidebar # Create HTML complete sidebar
sidebar_temp = sidebar_html%(sidebar_title, sidebar_list) sidebar_temp = sidebar_html%(sidebar_title, sidebar_list)
@ -331,9 +329,11 @@ def create_sidebar(option):
if sidebar_new: if sidebar_new:
ask_html = ' ├ Replace %s ? '%target ask_html = ' ├ Replace %s ? '%target
res = '' res = ''
if os.path.exists(target): 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']:
logs.out("255", '', True)n
tyto.set_file(target, True, sidebar_content) tyto.set_file(target, True, sidebar_content)
logs.out("33", target, False) logs.out("33", target, False)
@ -343,7 +343,6 @@ def create_sidebar(option):
# Create HTML menu from root folders # # Create HTML menu from root folders #
#------------------------------------# #------------------------------------#
def create_navbar(option): def create_navbar(option):
# Check if can process
domain.domain_needed() domain.domain_needed()
try: try:
@ -396,12 +395,14 @@ def create_navbar(option):
wip_index = '%s%s/index.html'%(db.srv_wip, direc) wip_index = '%s%s/index.html'%(db.srv_wip, direc)
if not os.path.exists(wip_index): if not os.path.exists(wip_index):
logs.out('26', 'in "%s": %s'%(direc, wip_index), False) logs.out('26', 'in "%s": %s'%(direc, wip_index), False)
continue
else: else:
index_wip = True index_wip = True
elif option == 'www': elif option == 'www':
www_index = '%s%s/index.html'%(db.srv_www, direc) www_index = '%s%s/index.html'%(db.srv_www, direc)
if not os.path.exists(www_index): if not os.path.exists(www_index):
logs.out('26', 'in "%s": %s'%(direc, www_index), False) logs.out('26', 'in "%s": %s'%(direc, www_index), False)
continue
else: else:
index_www = True index_www = True
else: else:
@ -411,9 +412,6 @@ def create_navbar(option):
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 and option == 'wip': 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
menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \ menu_item = '\n%s<li class="site_menu_item">\n'%(10 * ' ') + \
@ -425,30 +423,32 @@ def create_navbar(option):
'%s</li>'%(10 * ' ') '%s</li>'%(10 * ' ')
menu_html = '%s%s'%(menu_html, menu_item) menu_html = '%s%s'%(menu_html, menu_item)
# Close HTML tags # Nothing to do
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
if not navbar_new: if not navbar_new:
if not navbar_has: if not navbar_has:
logs.out('29', '(navbar): %s'%db.navbar_load, True) logs.out('29', '(navbar): %s'%db.navbar_load, False)
return
else: else:
logs.out('28', '(navbar)', True) logs.out('28', '(navbar)', False)
return
# Create file if sidebar has content # Create file if sidebar has content
if navbar_new: ask_html = ' ├ Replace %s ? '%target
ask_html = ' ├ Replace %s ? '%target res = ''
res = ''
if os.path.exists(target): if os.path.exists(target):
try: try:
res = input(ask_html) res = input(ask_html)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if not res in ['y', 'Y']:
logs.out("255", '', True)
if not res in ['y', 'Y']: return # Close HTML tags
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
tyto.set_file(target, True, menu_html) tyto.set_file(target, True, menu_html)
print(' ├ Create file: %s'%target) print(' ├ Create file: %s'%target)
#========================================================# #========================================================#
@ -458,7 +458,6 @@ def create_navbar(option):
# To manage new creation if changes # # To manage new creation if changes #
#--------------------------------------------------------# #--------------------------------------------------------#
def create_user_metas(option): def create_user_metas(option):
# Check if can process
domain.domain_needed() domain.domain_needed()
if option == 'wip': target = db.wip_navbar if option == 'wip': target = db.wip_navbar
@ -471,13 +470,15 @@ def create_user_metas(option):
user_metas = '' user_metas = ''
metas_used = ('<meta ', '<link ') metas_used = ('<meta ', '<link ')
res = '' res = ''
if os.path.exists(target): if os.path.exists(target):
try: try:
res = input(ask_html) res = input(ask_html)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']:
logs.out("255", '', True)
user_file = open(db.metas_load, 'r').read() user_file = open(db.metas_load, 'r').read()
@ -494,7 +495,6 @@ def create_user_metas(option):
# Create generic footer from domain datas # # Create generic footer from domain datas #
#-----------------------------------------# #-----------------------------------------#
def create_user_footer(option): def create_user_footer(option):
# Check if can process
domain.domain_needed() domain.domain_needed()
if option == 'wip': target = db.wip_footer if option == 'wip': target = db.wip_footer
@ -503,13 +503,15 @@ def create_user_footer(option):
ask_load = ' ├ Replace HTML footer: %s ? '%target ask_load = ' ├ Replace HTML footer: %s ? '%target
log_load = ' ├ Create file: %s'%target log_load = ' ├ Create file: %s'%target
res = '' res = ''
if os.path.exists(target): if os.path.exists(target):
try: try:
res = input(ask_load) res = input(ask_load)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']:
logs.out("255", '', True)
user_footer = '' user_footer = ''
user_file = open(db.footer_load, 'r').read() user_file = open(db.footer_load, 'r').read()

View File

@ -18,7 +18,7 @@
#********************************************************************** #**********************************************************************
import os, sys, shutil, importlib import os, sys, shutil, importlib
import logs, args, db, html, tyto import logs, args, db, html, tyto, domain
#==============================# #==============================#
@ -26,23 +26,28 @@ import logs, args, db, html, tyto
# check if publish can be done # # check if publish can be done #
#------------------------------# #------------------------------#
def manage_publish(target): def manage_publish(target):
# Check if can process domain.domain_needed
if not db.domain_exists \
or db.incomplete_domain \
or not db.domain_active:
return
# Target is footer, sidebar, navbar, metas # Target is footer, sidebar, navbar, metas
# template: create/copy template/ files
# all: publish all wip article
#-----------------------------------------
if target in args.pass_targets: if target in args.pass_targets:
do = { do = {
'sidebar' : html.create_sidebar, 'all' : create_all,
'navbar' : html.create_navbar, 'sidebar' : html.create_sidebar,
'metas' : html.create_user_metas 'navbar' : html.create_navbar,
'metas' : html.create_user_metas,
'footer' : html.create_user_footer,
'template' : create_template
} }
do[target]('www') do[target]('www')
return return
# Publish in www server an article
#---------------------------------
err_pub = False # Default (error to publish) 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)
@ -88,6 +93,9 @@ def manage_publish(target):
replace_line_pub() replace_line_pub()
#=================================================#
# Replace line in article containing publish date #
#-------------------------------------------------#
def replace_line_pub(): def replace_line_pub():
# Load config # Load config
importlib.reload(db) importlib.reload(db)
@ -107,3 +115,40 @@ def replace_line_pub():
tyto.set_file(db.post_www, 'new', newfile) tyto.set_file(db.post_www, 'new', newfile)
logs.out("34", '(date: %s): %s'%(db.date_www, db.post_www), False) logs.out("34", '(date: %s): %s'%(db.date_www, db.post_www), False)
#================================#
# Publish template in www server #
#--------------------------------#
def create_template(option):
print( \
'! Note:\n',
' - footer, sidebar, metas, navbar\n',
' will be generated from configuration files\n',
' in %s\n'%db.navbars_dir,
' - ALL other files will be copied\n',
' from %s\n'%db.srv_wip_tpl,
' to %s\n'%db.srv_www_tpl
)
ask = ' ├ Update template ? '
res = ''
try:
res = input(ask)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']:
logs.out("255", '', True)
html.create_sidebar('www')
html.create_navbar('www')
html.create_user_metas('www')
html.create_user_footer('www')
#================================#
# Publish template in www server #
#--------------------------------#
def create_all(option):
print('> argument all', option)

View File

@ -422,43 +422,3 @@ def replace_in_db(post_db, process, hash_post):
file = open(post_db, 'w') file = open(post_db, 'w')
file.write(new_file) file.write(new_file)
file.close() file.close()
#================================#
# Exit from program with message #
#--------------------------------#
def exiting(nbr, value, out):
nbrs = {
'1' : ':< %sUnused ressource%s: %s'%(CR, CS, value),
'2' : ':< %sIncomplete data%s: "%s"'%(CR, CS, value),
'3' : ':< %sInvalid data%s: "%s"'%(CR, CS, value),
'4' : ':< %sNo database yet%s. Check article first.'%(CR, CS),
'5' : ':< %sUnused argument%s: [file]'%(CR, CS),
'6' : ':< %sUnused "%s"%s in article'%(CR, CS, value),
'7' : ':< Article is %snot valid yet%s'%(CR, CS),
'8' : ':< %sNot paired%s: %s'%(CR, CS, value),
'9' : ':< Article %shas changed%s. Check it first'%(CR, CS),
'10' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, CS),
'11' : ':< %sUnused argument%s: %s'%(CR, CS, value),
'20' : ':D %sUp-to-date%s article on: %s'%(CG, CS, value),
'21' : ':D %sValid%s article. Ready to wip'%(CG, CS),
'22' : ':? %sNot paired%s symbols: %s'%(CY, CS, value),
'23' : ':? %sCorrupted database%s: %s'%(CY, CS, value),
'24' : ':? %sfile missing%s %s'%(CY, CS, value),
'25' : ':D Add contents %s'%value,
'26' : ':? %sDeactivated%s "%s" in domain conf'%(CY, CS, value),
'27' : ':? %sDeleted%s %s'%(CY, CS, value),
'28' : ':? %sUnused directory%s: %s'%(CY, CS, value),
'29' : ':? %sEmpty configuration%s %s'%(CY, CS, value),
'30' : ':? %sArticle is not wip%s: %s'%(CY, CS, value),
'31' : ':? %sMax items reached%s %s'%(CY, CS, value),
'32' : ':? %sNo changes%s in: %s'%(CY, CS, value),
'33' : ':D %sCreated file%s: %s'%(CG, CS, value),
'255' : ':| Maybe later...'
}
msg = nbrs[nbr]
print(msg)
if int(nbr) >= 20: nbr = 0
if out: sys.exit(int(nbr))