sidebar/navbar managing ; options new, edit, wip, publish
This commit is contained in:
parent
6f141b6c30
commit
c95cf9dc67
|
@ -42,22 +42,18 @@ import check, domain, html, new, publish, show, wip, infos
|
|||
|
||||
# Command start argument
|
||||
actions = {
|
||||
'check' : check.manage_check,
|
||||
'check' : check.manage_check,
|
||||
'help' : infos.tyto,
|
||||
'edit' : show.manage_show,
|
||||
'edit-db' : show.manage_show,
|
||||
'edit-wip' : show.manage_show,
|
||||
'edit-www' : show.manage_show,
|
||||
'footer' : html.manage_configs,
|
||||
'metas' : html.manage_configs,
|
||||
'navbar' : html.manage_configs,
|
||||
'new' : new.manage_new,
|
||||
'publish' : publish.manage_publish,
|
||||
'show' : show.manage_show,
|
||||
'show-db' : show.manage_show,
|
||||
'show-wip' : show.manage_show,
|
||||
'show-www' : show.manage_show,
|
||||
'sidebar' : html.manage_configs,
|
||||
'wip' : wip.manage_wip
|
||||
}
|
||||
|
||||
|
|
|
@ -488,11 +488,9 @@ def create_domain(target):
|
|||
# Create in _configs files
|
||||
# Force will ask to create in template
|
||||
print(' │')
|
||||
html.manage_configs('sidebar', 'Force')
|
||||
html.manage_configs('navbar', 'Force')
|
||||
html.manage_configs('metas', 'Force')
|
||||
html.manage_configs('footer', 'Force')
|
||||
|
||||
create_sidebar('new')
|
||||
create_navbar('new')
|
||||
|
||||
print(' │')
|
||||
print(' ├──────────────────────────────────────┐')
|
||||
print(' │ Domain is ready. Have fun, writers ! │')
|
||||
|
@ -509,20 +507,22 @@ def create_sidebar(option):
|
|||
or not db.domain_active:
|
||||
return
|
||||
|
||||
# Create an empty html file if not exists
|
||||
# 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)
|
||||
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:
|
||||
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 ? '
|
||||
log = ' ├ Create source file: %s'%db.sidebar_load
|
||||
res = ''
|
||||
if os.path.exists(db.sidebar_load):
|
||||
if os.path.exists(db.sidebar_load):
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
|
@ -580,16 +580,22 @@ def create_navbar(option):
|
|||
or not db.domain_active:
|
||||
return
|
||||
|
||||
# Create an empty html file 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)
|
||||
# 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 new file, or ask if exists
|
||||
ask = ' ├ Reset navbar configuration file ? '
|
||||
log = ' ├ Create source file: %s'%db.navbar_load
|
||||
res = ''
|
||||
if os.path.exists(db.navbar_load):
|
||||
if os.path.exists(db.navbar_load):
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
@ -21,32 +21,6 @@ import os, sys
|
|||
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 #
|
||||
# Start HTML page sections #
|
||||
|
@ -253,18 +227,22 @@ def create_db_load(file_load, file_db):
|
|||
#============================================#
|
||||
# Create HTML sidebar from file tyto.sidebar #
|
||||
#--------------------------------------------#
|
||||
def create_sidebar(target):
|
||||
def create_sidebar(option):
|
||||
# Check if can process
|
||||
if not db.domain_exists \
|
||||
or db.incomplete_domain \
|
||||
or not db.domain_active:
|
||||
return
|
||||
|
||||
try:
|
||||
db.sidebar_load
|
||||
if not os.path.exists(db.sidebar_load):
|
||||
logs.out("1", db.sidebar_load, True)
|
||||
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
|
||||
sidebar_new = False
|
||||
|
@ -282,6 +260,7 @@ def create_sidebar(target):
|
|||
counter = 0
|
||||
nolines = ('#', '/')
|
||||
|
||||
sidebar_title = db.sidebar_title
|
||||
sidebar_lines = open(db.sidebar_load, 'r').read()
|
||||
for line in sidebar_lines.rsplit('\n'):
|
||||
if not line or line.startswith(nolines): continue
|
||||
|
@ -299,7 +278,7 @@ def create_sidebar(target):
|
|||
|
||||
# Get Hash from uri to get db file
|
||||
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):
|
||||
logs.out('25', 'No Database', False)
|
||||
continue
|
||||
|
@ -358,9 +337,9 @@ def create_sidebar(target):
|
|||
|
||||
# Create file if sidebar has content
|
||||
if sidebar_new:
|
||||
ask_html = ' ├ Replace %s ? '%db.wip_sidebar
|
||||
ask_html = ' ├ Replace %s ? '%target
|
||||
res = ''
|
||||
if os.path.exists(db.wip_sidebar):
|
||||
if os.path.exists(target):
|
||||
res = input(ask_html)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
|
@ -371,8 +350,22 @@ def create_sidebar(target):
|
|||
#====================================#
|
||||
# Create HTML menu from root folders #
|
||||
#------------------------------------#
|
||||
def create_navbar(target):
|
||||
if not db.domain_exists: return
|
||||
def create_navbar(option):
|
||||
# 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
|
||||
navbar_new = False
|
||||
|
@ -404,20 +397,29 @@ def create_navbar(target):
|
|||
# Check if an index.[ext] and index.html exist and log
|
||||
index_src = False
|
||||
index_wip = False
|
||||
index_www = False
|
||||
for f in os.listdir(dir_uri):
|
||||
if f.startswith("index."):
|
||||
index_src = True
|
||||
wip_index = '%s%s/index.html'%(db.srv_wip, direc)
|
||||
if not os.path.exists(wip_index):
|
||||
logs.out('26', 'in "%s": %s'%(direc, wip_index), False)
|
||||
else:
|
||||
index_wip = True
|
||||
if option == 'wip':
|
||||
wip_index = '%s%s/index.html'%(db.srv_wip, direc)
|
||||
if not os.path.exists(wip_index):
|
||||
logs.out('26', 'in "%s": %s'%(direc, wip_index), False)
|
||||
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
|
||||
if not index_src:
|
||||
logs.out("26", 'in "%s": %s'%(direc, dir_uri), False)
|
||||
continue
|
||||
if not index_wip:
|
||||
continue
|
||||
if not index_wip and option == 'wip': continue
|
||||
if not index_www and option == 'www': continue
|
||||
|
||||
# Add link to HTML structure
|
||||
navbar_new = True
|
||||
|
@ -441,9 +443,9 @@ def create_navbar(target):
|
|||
|
||||
# Create file if sidebar has content
|
||||
if navbar_new:
|
||||
ask_html = ' ├ Replace %s ? '%db.wip_navbar
|
||||
ask_html = ' ├ Replace %s ? '%target
|
||||
res = ''
|
||||
if os.path.exists(db.wip_navbar):
|
||||
if os.path.exists(target):
|
||||
try:
|
||||
res = input(ask_html)
|
||||
except KeyboardInterrupt:
|
||||
|
@ -452,8 +454,8 @@ def create_navbar(target):
|
|||
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
tyto.set_file(navbar_file, True, menu_html)
|
||||
print(' ├ Create file: %s'%navbar_file)
|
||||
tyto.set_file(target, True, menu_html)
|
||||
print(' ├ Create file: %s'%target)
|
||||
|
||||
|
||||
#========================================================#
|
||||
|
|
|
@ -78,7 +78,7 @@ def tyto(target):
|
|||
' sidebar : Create sidebar config/HTML code file\n\n'
|
||||
'# Examples:\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-wip navbar: edit file: /wip/template/navbar.html\n'
|
||||
' tyto edit navbar: edit /_configs/tyto.navbar\n'
|
||||
' tyto edit navbar: edit file: /_configs/tyto.navbar\n'
|
||||
' tyto wip sidebar: create sidebar.html in wip server\n'
|
||||
' tyto publish navbar: create navbar.html in www server'
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
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)
|
||||
|
||||
elif target == 'sidebar':
|
||||
domain.create_sidebar(target)
|
||||
domain.create_sidebar('new')
|
||||
|
||||
elif target == 'navbar':
|
||||
domain.create_navbar(target)
|
||||
|
||||
domain.create_navbar('new')
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
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 #
|
||||
#------------------------------#
|
||||
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:
|
||||
logs.out("25", db.uri_file, True)
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ def manage_show(target):
|
|||
elif args.action in actions_edit: tyto.edit_file(do[target])
|
||||
|
||||
# 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)
|
||||
if curr_hash != new_hash:
|
||||
ask = ''
|
||||
|
|
|
@ -18,14 +18,30 @@
|
|||
#**********************************************************************
|
||||
|
||||
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):
|
||||
global post_db, hash_post
|
||||
|
||||
# Domain configuration must exist and active
|
||||
if not db.domain_exists: return
|
||||
if not db.domain_active: return
|
||||
# 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]('wip')
|
||||
return
|
||||
|
||||
#-----------------------------------------
|
||||
# Option 'Again' to wip again, based on DB
|
||||
|
|
Loading…
Reference in New Issue