Updated code for actions, targets. New help
This commit is contained in:
parent
6eec2a7d90
commit
2aaa644d0a
|
@ -30,17 +30,19 @@ sys.path.insert(0, '/var/lib/tyto/program')
|
||||||
# MAIN #
|
# MAIN #
|
||||||
# Treat Arguments #
|
# Treat Arguments #
|
||||||
#--------------------#-------------------------------------------------
|
#--------------------#-------------------------------------------------
|
||||||
|
import logs
|
||||||
if not __name__ == "__main__":
|
if not __name__ == "__main__":
|
||||||
print(':< Mismatch program start')
|
logs.out("14", '', True)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
|
# Check arguments
|
||||||
import args
|
import args
|
||||||
action = args.set_action()
|
action = args.set_action()
|
||||||
target = args.set_target()
|
target = args.set_target()
|
||||||
|
|
||||||
import check, domain, html, new, publish, show, wip, infos
|
|
||||||
|
|
||||||
# Command start argument
|
# Command start argument
|
||||||
|
import check, domain, html, new, publish, show, wip, infos
|
||||||
actions = {
|
actions = {
|
||||||
'check' : check.manage_check,
|
'check' : check.manage_check,
|
||||||
'help' : infos.tyto,
|
'help' : infos.tyto,
|
||||||
|
@ -58,10 +60,8 @@ actions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Argument 1
|
# Start action
|
||||||
#-----------
|
# Argument's Check done in args.py
|
||||||
try:
|
#---------------------------------
|
||||||
actions[action](target)
|
actions[action](target)
|
||||||
except KeyError:
|
|
||||||
print(':< No action for "%s", with "%s"'%(action, target))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
|
@ -18,39 +18,56 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import infos
|
import infos, logs
|
||||||
|
|
||||||
# Arguments from command line
|
# Arguments from command line
|
||||||
# tyto [action] [target]
|
# tyto [action] [target]
|
||||||
#----------------------------
|
#----------------------------
|
||||||
actions = (
|
actions = \
|
||||||
'check',
|
(
|
||||||
'edit',
|
'check',
|
||||||
'edit-db',
|
'edit',
|
||||||
'edit-wip',
|
'edit-db',
|
||||||
'edit-www',
|
'edit-wip',
|
||||||
'help',
|
'edit-www',
|
||||||
'new',
|
'help',
|
||||||
'show',
|
'new',
|
||||||
'show-db',
|
'show',
|
||||||
'show-wip',
|
'show-db',
|
||||||
'show-www',
|
'show-wip',
|
||||||
'wip',
|
'show-www',
|
||||||
'publish'
|
'wip',
|
||||||
)
|
'publish'
|
||||||
|
)
|
||||||
|
|
||||||
pass_actions = (
|
pass_actions = (
|
||||||
'new'
|
'new'
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pass_targets = (
|
# Actions that needs to check for article's database
|
||||||
'domain',
|
pass_db = \
|
||||||
'footer',
|
(
|
||||||
'metas',
|
'check',
|
||||||
'navbar',
|
'edit-db',
|
||||||
'sidebar'
|
'edit-wip',
|
||||||
)
|
'edit-www',
|
||||||
|
'publish',
|
||||||
|
'show-db',
|
||||||
|
'show-wip',
|
||||||
|
'show-www',
|
||||||
|
'wip',
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
pass_targets = \
|
||||||
|
(
|
||||||
|
'domain',
|
||||||
|
'footer',
|
||||||
|
'metas',
|
||||||
|
'navbar',
|
||||||
|
'sidebar'
|
||||||
|
)
|
||||||
|
|
||||||
action = ''
|
action = ''
|
||||||
target = ''
|
target = ''
|
||||||
|
@ -61,13 +78,14 @@ noaction = False
|
||||||
try: action = sys.argv[1]
|
try: action = sys.argv[1]
|
||||||
except: noaction = True
|
except: noaction = True
|
||||||
|
|
||||||
|
# With no argument, show help
|
||||||
if noaction:
|
if noaction:
|
||||||
infos.tyto(target)
|
infos.tyto(target)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Unused argument [action]
|
||||||
if not action in actions:
|
if not action in actions:
|
||||||
print(':< Unused [action] argument: "%s"'%action)
|
logs.out("11", action, True)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# target
|
# target
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
import args, logs, tyto
|
import args, logs, tyto, domain
|
||||||
|
|
||||||
action = args.action
|
action = args.action
|
||||||
target = args.target
|
target = args.target
|
||||||
|
@ -45,62 +45,69 @@ domain_conf = in_dir
|
||||||
|
|
||||||
|
|
||||||
# Settings for domain, check if db is not corrupted
|
# Settings for domain, check if db is not corrupted
|
||||||
domain_values = (
|
domain_values = \
|
||||||
'domain_dir',
|
(
|
||||||
'domain_conf',
|
'domain_dir',
|
||||||
'domain_articles',
|
'domain_conf',
|
||||||
'domain_files',
|
'domain_articles',
|
||||||
'domain_images',
|
'domain_files',
|
||||||
'articles_db',
|
'domain_images',
|
||||||
'html_db',
|
'articles_db',
|
||||||
'navbars_dir',
|
'html_db',
|
||||||
'navbar_load',
|
'navbars_dir',
|
||||||
'navbar_load_db',
|
'navbar_load',
|
||||||
'sidebar_load',
|
'navbar_load_db',
|
||||||
'sidebar_load_db',
|
'sidebar_load',
|
||||||
'metas_load',
|
'sidebar_load_db',
|
||||||
'metas_load_db',
|
'metas_load',
|
||||||
'footer_load',
|
'metas_load_db',
|
||||||
'footer_load_db',
|
'footer_load',
|
||||||
'domain_short',
|
'footer_load_db',
|
||||||
'domain_www_url',
|
'domain_short',
|
||||||
'domain_wip_url',
|
'domain_www_url',
|
||||||
'domain_title',
|
'domain_wip_url',
|
||||||
'domain_about',
|
'domain_title',
|
||||||
'domain_lang',
|
'domain_about',
|
||||||
'domain_mail',
|
'domain_lang',
|
||||||
'domain_tags',
|
'domain_mail',
|
||||||
'domain_logo',
|
'domain_tags',
|
||||||
'domain_license',
|
'domain_logo',
|
||||||
'domain_licurl',
|
'domain_license',
|
||||||
'domain_css',
|
'domain_licurl',
|
||||||
'domain_sep',
|
'domain_css',
|
||||||
'domain_relme',
|
'domain_sep',
|
||||||
'sidebar_title',
|
'domain_relme',
|
||||||
'sidebar_items',
|
'sidebar_title',
|
||||||
'srv_root',
|
'sidebar_items',
|
||||||
'srv_domain',
|
'srv_root',
|
||||||
'srv_wip',
|
'srv_domain',
|
||||||
'srv_wip_tpl',
|
'srv_wip',
|
||||||
'srv_wip_images',
|
'srv_wip_tpl',
|
||||||
'srv_wip_files',
|
'srv_wip_images',
|
||||||
'srv_www',
|
'srv_wip_files',
|
||||||
'srv_www_tpl',
|
'srv_www',
|
||||||
'srv_www_images',
|
'srv_www_tpl',
|
||||||
'srv_www_files',
|
'srv_www_images',
|
||||||
'wip_navbar',
|
'srv_www_files',
|
||||||
'wip_sidebar',
|
'wip_navbar',
|
||||||
'wip_metas',
|
'wip_sidebar',
|
||||||
'wip_footer',
|
'wip_metas',
|
||||||
'www_navbar',
|
'wip_footer',
|
||||||
'www_sidebar',
|
'www_navbar',
|
||||||
'www_metas',
|
'www_sidebar',
|
||||||
'www_footer',
|
'www_metas',
|
||||||
'domain_active',
|
'www_footer',
|
||||||
)
|
'domain_active',
|
||||||
|
)
|
||||||
|
|
||||||
# If error in DB, continue process for these options
|
# If error in DB, continue process for these options
|
||||||
domain_pass_args = ('new', 'edit', 'show', '')
|
domain_pass_args = \
|
||||||
|
(
|
||||||
|
'new',
|
||||||
|
'edit',
|
||||||
|
'show',
|
||||||
|
''
|
||||||
|
)
|
||||||
|
|
||||||
# Search and set domain conf file
|
# Search and set domain conf file
|
||||||
# from current directory or from argument
|
# from current directory or from argument
|
||||||
|
@ -138,9 +145,9 @@ if domain_exists:
|
||||||
try:
|
try:
|
||||||
domain_show
|
domain_show
|
||||||
except:
|
except:
|
||||||
if incomplete_domain: logs.out("41", domain_short, False)
|
if incomplete_domain: logs.out("41", domain_short, False)
|
||||||
elif domain_active: logs.out("42", domain_short, False)
|
elif domain_active: logs.out("42", domain_short, False)
|
||||||
else: logs.out("40", domain_short, False)
|
else: logs.out("40", domain_short, False)
|
||||||
domain_show = True
|
domain_show = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -151,34 +158,37 @@ else:
|
||||||
#------------------#
|
#------------------#
|
||||||
# ARTICLE DATABASE #
|
# ARTICLE DATABASE #
|
||||||
#------------------#
|
#------------------#
|
||||||
#==================#
|
#================================#
|
||||||
# Get post DB from target #
|
# Get post DB from target #
|
||||||
# Get some post settings fom uri #
|
# Get some post settings fom uri #
|
||||||
#--------------------------------#
|
#--------------------------------#
|
||||||
if args.target and not args.target in args.pass_targets:
|
# Conditions from command line
|
||||||
if not action in args.pass_actions:
|
if args.target \
|
||||||
uri_file = '%s/%s'%(in_dir, args.target)
|
and args.action in args.pass_db \
|
||||||
if not os.path.exists(uri_file):
|
and not args.target in args.pass_targets:
|
||||||
logs.out("1", uri_file, True)
|
|
||||||
|
|
||||||
# Get hash for uri and content file
|
uri_file = '%s/%s'%(in_dir, args.target)
|
||||||
post_exists = True
|
if not os.path.exists(uri_file): logs.out("1", uri_file, True)
|
||||||
uri_id = tyto.get_filesum(uri_file, False)
|
|
||||||
hash_post = tyto.get_filesum(uri_file, True)
|
|
||||||
|
|
||||||
|
# Get hash for uri and content file
|
||||||
|
post_exists = True
|
||||||
|
uri_id = tyto.get_filesum(uri_file, False)
|
||||||
|
hash_post = tyto.get_filesum(uri_file, True)
|
||||||
|
|
||||||
if domain_exists and not incomplete_domain:
|
# Domain must be valid
|
||||||
# Set DB file for this post
|
domain.domain_needed()
|
||||||
post_db = '%s%s.conf'%(articles_db, uri_id)
|
|
||||||
if not os.path.exists(post_db):
|
# Set DB file for this post
|
||||||
db_exists = False
|
post_db = '%s%s.conf'%(articles_db, uri_id)
|
||||||
else:
|
if not os.path.exists(post_db):
|
||||||
if os.stat(post_db).st_size < 1000:
|
db_exists = False
|
||||||
os.remove(post_db)
|
else:
|
||||||
logs.out('23', post_db, False)
|
if os.stat(post_db).st_size < 1000:
|
||||||
db_exists = False
|
os.remove(post_db)
|
||||||
else:
|
logs.out('23', post_db, False)
|
||||||
db_exists = True
|
db_exists = False
|
||||||
|
else:
|
||||||
|
db_exists = True
|
||||||
|
|
||||||
# Load post database
|
# Load post database
|
||||||
if db_exists:
|
if db_exists:
|
||||||
|
|
|
@ -55,30 +55,37 @@ def tyto(target):
|
||||||
print(
|
print(
|
||||||
'\nUsage: tyto [action] [target] \n'
|
'\nUsage: tyto [action] [target] \n'
|
||||||
' After created domain (tyto new domain [URL]),\n'
|
' After created domain (tyto new domain [URL]),\n'
|
||||||
' create article\'s file in articles/ directory,\n'
|
' create article\'s file in articles/ directory.\n'
|
||||||
' do in this order on [target] file: Check > wip > publish\n\n'
|
' Use this actions on article\'s file: Check > wip > publish\n'
|
||||||
|
' Config\'s files are in _configs/ directory,\n'
|
||||||
|
' and used to create HTML file in your template.\n\n'
|
||||||
'- [action] according to [target]:\n'
|
'- [action] according to [target]:\n'
|
||||||
' edit : Edit article\'s source file\n'
|
' edit : Edit article\'s file\n'
|
||||||
' edit-db : Edit post or domain database\n'
|
' edit-db : Edit article\'s database (TAKE CARE !)\n'
|
||||||
' edit-wip: Edit html file in wip server\n'
|
' edit-wip: Edit html file in wip server\n'
|
||||||
' edit_www: Edit html file in www server\n'
|
' edit_www: Edit html file in www server\n'
|
||||||
' new : Create new (domain, sidebar/footer... config file)\n'
|
' new : Create new (domain, sidebar/footer... config\'s file)\n'
|
||||||
' show : Show content of source file\n'
|
' show : Show content of config\'s file\n'
|
||||||
' show-db : Show content of post or domain database\n'
|
' show-db : Show content of article\'s database\n'
|
||||||
' show-wip: Show html file in wip server\n'
|
' show-wip: Show HTML file in wip server\n'
|
||||||
' show-www: Show html file in www server\n\n'
|
' show-www: Show HTML file in www server\n\n'
|
||||||
' check : Check if article is valid\n'
|
' check : Check if article is valid\n'
|
||||||
' wip : Create page in wip server\n'
|
' wip : Create page in wip server\n'
|
||||||
' publish : Create page in www server\n\n'
|
' publish : Create page in www server\n\n'
|
||||||
'- [target] according to [action]\n' + \
|
'- [target] according to [action]\n'
|
||||||
' [file] : File uri of an article\n'
|
' domain : Create/Show config file\n'
|
||||||
' footer : Create footer config/HTML code file\n'
|
' [file] : URI of an article\'s file (autocompletion is your friend)\n'
|
||||||
' metas : Create metas config/HTML code file\n'
|
' footer : Create/Show footer HTML config\'s file\n'
|
||||||
' navbar : Create navbar config/HTML code file\n'
|
' metas : Create/Show metas HTML config\'s file\n'
|
||||||
' sidebar : Create sidebar config/HTML code file\n\n'
|
' navbar : Create/Show navbar config\'s file\n'
|
||||||
'# Examples:\n'
|
' sidebar : Create/Show sidebar config\'s file\n\n'
|
||||||
' tyto new sidebar: create default source file /_configs/tyto.sidebar\n'
|
'Examples:\n'
|
||||||
' tyto edit navbar: edit file: /_configs/tyto.navbar\n'
|
'- Check article\'s syntax: tyto check mysubdir/index.tyto\n'
|
||||||
' tyto wip sidebar: create sidebar.html in wip server\n'
|
'- Create default _configs/tyto.sidebar: tyto new sidebar\n'
|
||||||
' tyto publish navbar: create navbar.html in www server'
|
'- Edit _configs/tyto.navbar: tyto edit navbar\n'
|
||||||
|
'- Edit index.html in www server: tyto edit-www index.tyto\n'
|
||||||
|
'- Create sidebar.html in wip server: tyto wip sidebar\n'
|
||||||
|
'- Show sidebar.html in wip server: tyto show-wip sidebar\n'
|
||||||
|
'- Create navbar.html in www server: tyto publish navbar\n'
|
||||||
|
'- Show navbar.html in www server: tyto show-www navbar\n'
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,6 +43,7 @@ def out(nbr, value, out):
|
||||||
'11' : ':< %sUnused argument%s: %s'%(CR, CS, value),
|
'11' : ':< %sUnused argument%s: %s'%(CR, CS, value),
|
||||||
'12' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, CS),
|
'12' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, CS),
|
||||||
'13' : ':< %sNo file or directory%s here (deleted ?)'%(CR, CS),
|
'13' : ':< %sNo file or directory%s here (deleted ?)'%(CR, CS),
|
||||||
|
'14' : ':< %sMismatch%s program start'%(CR, CS),
|
||||||
'19' : ':D Article %swip%s on: %s'%(CG, CS, value),
|
'19' : ':D Article %swip%s on: %s'%(CG, CS, value),
|
||||||
'20' : ':D Article %scheck%s on: %s'%(CG, CS, value),
|
'20' : ':D Article %scheck%s on: %s'%(CG, CS, value),
|
||||||
'21' : ':D %sValid%s article. Ready to wip'%(CG, CS),
|
'21' : ':D %sValid%s article. Ready to wip'%(CG, CS),
|
||||||
|
|
|
@ -42,3 +42,5 @@ def manage_new(target):
|
||||||
}
|
}
|
||||||
|
|
||||||
actions[target](option)
|
actions[target](option)
|
||||||
|
else:
|
||||||
|
logs.out("11", '"%s" with "%s"'%(target, option), True)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#**********************************************************************
|
#**********************************************************************
|
||||||
|
|
||||||
import os, importlib
|
import os, importlib
|
||||||
import args, db, logs, tyto, check
|
import args, db, logs, domain, tyto, check
|
||||||
|
|
||||||
|
|
||||||
#======================#
|
#======================#
|
||||||
|
@ -30,7 +30,8 @@ import args, db, logs, tyto, check
|
||||||
#----------------------#
|
#----------------------#
|
||||||
def manage_show(target):
|
def manage_show(target):
|
||||||
# Domain configuration must exists
|
# Domain configuration must exists
|
||||||
if not db.domain_exists: sys.exit(43)
|
#if not db.domain_exists: sys.exit(43)
|
||||||
|
domain.domain_needed()
|
||||||
|
|
||||||
do = False
|
do = False
|
||||||
actions_read = ('show', 'show-db', 'show-wip', 'show-www')
|
actions_read = ('show', 'show-db', 'show-wip', 'show-www')
|
||||||
|
@ -87,10 +88,9 @@ def manage_show(target):
|
||||||
# Post has database
|
# Post has database
|
||||||
elif db.db_exists:
|
elif db.db_exists:
|
||||||
do = {
|
do = {
|
||||||
"db" : db.post_db,
|
"db" : db.post_db,
|
||||||
"wip" : db.post_wip,
|
"wip" : db.post_wip,
|
||||||
"www" : db.post_www
|
"www" : db.post_www
|
||||||
|
|
||||||
}
|
}
|
||||||
if args.action in actions_wip: target = "wip"
|
if args.action in actions_wip: target = "wip"
|
||||||
elif args.action in actions_www: target = "www"
|
elif args.action in actions_www: target = "www"
|
||||||
|
@ -98,7 +98,8 @@ def manage_show(target):
|
||||||
|
|
||||||
#print('> show: target', target)
|
#print('> show: target', target)
|
||||||
|
|
||||||
if not do: logs.out("28", 'yet', True)
|
if not do:
|
||||||
|
logs.out("11", '"%s" with "%s"'%(args.target, args.action), True)
|
||||||
|
|
||||||
# Read lines of, or edit file
|
# Read lines of, or edit file
|
||||||
if args.action in actions_read: read_lines(do[target])
|
if args.action in actions_read: read_lines(do[target])
|
||||||
|
|
Loading…
Reference in New Issue