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 #
|
||||
# Treat Arguments #
|
||||
#--------------------#-------------------------------------------------
|
||||
import logs
|
||||
if not __name__ == "__main__":
|
||||
print(':< Mismatch program start')
|
||||
sys.exit(1)
|
||||
logs.out("14", '', True)
|
||||
|
||||
|
||||
# Check arguments
|
||||
import args
|
||||
action = args.set_action()
|
||||
target = args.set_target()
|
||||
|
||||
import check, domain, html, new, publish, show, wip, infos
|
||||
|
||||
# Command start argument
|
||||
import check, domain, html, new, publish, show, wip, infos
|
||||
actions = {
|
||||
'check' : check.manage_check,
|
||||
'help' : infos.tyto,
|
||||
|
@ -58,10 +60,8 @@ actions = {
|
|||
}
|
||||
|
||||
|
||||
# Argument 1
|
||||
#-----------
|
||||
try:
|
||||
actions[action](target)
|
||||
except KeyError:
|
||||
print(':< No action for "%s", with "%s"'%(action, target))
|
||||
sys.exit(1)
|
||||
# Start action
|
||||
# Argument's Check done in args.py
|
||||
#---------------------------------
|
||||
actions[action](target)
|
||||
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
#**********************************************************************
|
||||
|
||||
import sys
|
||||
import infos
|
||||
import infos, logs
|
||||
|
||||
# Arguments from command line
|
||||
# tyto [action] [target]
|
||||
#----------------------------
|
||||
actions = (
|
||||
actions = \
|
||||
(
|
||||
'check',
|
||||
'edit',
|
||||
'edit-db',
|
||||
|
@ -37,20 +38,36 @@ actions = (
|
|||
'show-www',
|
||||
'wip',
|
||||
'publish'
|
||||
)
|
||||
)
|
||||
|
||||
pass_actions = (
|
||||
'new'
|
||||
|
||||
)
|
||||
|
||||
pass_targets = (
|
||||
# Actions that needs to check for article's database
|
||||
pass_db = \
|
||||
(
|
||||
'check',
|
||||
'edit-db',
|
||||
'edit-wip',
|
||||
'edit-www',
|
||||
'publish',
|
||||
'show-db',
|
||||
'show-wip',
|
||||
'show-www',
|
||||
'wip',
|
||||
|
||||
)
|
||||
|
||||
pass_targets = \
|
||||
(
|
||||
'domain',
|
||||
'footer',
|
||||
'metas',
|
||||
'navbar',
|
||||
'sidebar'
|
||||
)
|
||||
)
|
||||
|
||||
action = ''
|
||||
target = ''
|
||||
|
@ -61,13 +78,14 @@ noaction = False
|
|||
try: action = sys.argv[1]
|
||||
except: noaction = True
|
||||
|
||||
# With no argument, show help
|
||||
if noaction:
|
||||
infos.tyto(target)
|
||||
sys.exit(0)
|
||||
|
||||
# Unused argument [action]
|
||||
if not action in actions:
|
||||
print(':< Unused [action] argument: "%s"'%action)
|
||||
sys.exit(1)
|
||||
logs.out("11", action, True)
|
||||
|
||||
|
||||
# target
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
import os, sys
|
||||
import args, logs, tyto
|
||||
import args, logs, tyto, domain
|
||||
|
||||
action = args.action
|
||||
target = args.target
|
||||
|
@ -45,7 +45,8 @@ domain_conf = in_dir
|
|||
|
||||
|
||||
# Settings for domain, check if db is not corrupted
|
||||
domain_values = (
|
||||
domain_values = \
|
||||
(
|
||||
'domain_dir',
|
||||
'domain_conf',
|
||||
'domain_articles',
|
||||
|
@ -97,10 +98,16 @@ domain_values = (
|
|||
'www_metas',
|
||||
'www_footer',
|
||||
'domain_active',
|
||||
)
|
||||
)
|
||||
|
||||
# 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
|
||||
# from current directory or from argument
|
||||
|
@ -151,23 +158,26 @@ else:
|
|||
#------------------#
|
||||
# ARTICLE DATABASE #
|
||||
#------------------#
|
||||
#==================#
|
||||
#================================#
|
||||
# Get post DB from target #
|
||||
# Get some post settings fom uri #
|
||||
#--------------------------------#
|
||||
if args.target and not args.target in args.pass_targets:
|
||||
if not action in args.pass_actions:
|
||||
# Conditions from command line
|
||||
if args.target \
|
||||
and args.action in args.pass_db \
|
||||
and not args.target in args.pass_targets:
|
||||
|
||||
uri_file = '%s/%s'%(in_dir, args.target)
|
||||
if not os.path.exists(uri_file):
|
||||
logs.out("1", uri_file, True)
|
||||
if not os.path.exists(uri_file): logs.out("1", 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)
|
||||
|
||||
# Domain must be valid
|
||||
domain.domain_needed()
|
||||
|
||||
if domain_exists and not incomplete_domain:
|
||||
# Set DB file for this post
|
||||
post_db = '%s%s.conf'%(articles_db, uri_id)
|
||||
if not os.path.exists(post_db):
|
||||
|
|
|
@ -55,30 +55,37 @@ def tyto(target):
|
|||
print(
|
||||
'\nUsage: tyto [action] [target] \n'
|
||||
' After created domain (tyto new domain [URL]),\n'
|
||||
' create article\'s file in articles/ directory,\n'
|
||||
' do in this order on [target] file: Check > wip > publish\n\n'
|
||||
' create article\'s file in articles/ directory.\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'
|
||||
' edit : Edit article\'s source file\n'
|
||||
' edit-db : Edit post or domain database\n'
|
||||
' edit : Edit article\'s file\n'
|
||||
' edit-db : Edit article\'s database (TAKE CARE !)\n'
|
||||
' edit-wip: Edit html file in wip server\n'
|
||||
' edit_www: Edit html file in www server\n'
|
||||
' new : Create new (domain, sidebar/footer... config file)\n'
|
||||
' show : Show content of source file\n'
|
||||
' show-db : Show content of post or domain database\n'
|
||||
' show-wip: Show html file in wip server\n'
|
||||
' show-www: Show html file in www server\n\n'
|
||||
' new : Create new (domain, sidebar/footer... config\'s file)\n'
|
||||
' show : Show content of config\'s file\n'
|
||||
' show-db : Show content of article\'s database\n'
|
||||
' show-wip: Show HTML file in wip server\n'
|
||||
' show-www: Show HTML file in www server\n\n'
|
||||
' check : Check if article is valid\n'
|
||||
' wip : Create page in wip server\n'
|
||||
' publish : Create page in www server\n\n'
|
||||
'- [target] according to [action]\n' + \
|
||||
' [file] : File uri of an article\n'
|
||||
' footer : Create footer config/HTML code file\n'
|
||||
' metas : Create metas config/HTML code file\n'
|
||||
' navbar : Create navbar config/HTML code file\n'
|
||||
' sidebar : Create sidebar config/HTML code file\n\n'
|
||||
'# Examples:\n'
|
||||
' tyto new sidebar: create default source file /_configs/tyto.sidebar\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'
|
||||
'- [target] according to [action]\n'
|
||||
' domain : Create/Show config file\n'
|
||||
' [file] : URI of an article\'s file (autocompletion is your friend)\n'
|
||||
' footer : Create/Show footer HTML config\'s file\n'
|
||||
' metas : Create/Show metas HTML config\'s file\n'
|
||||
' navbar : Create/Show navbar config\'s file\n'
|
||||
' sidebar : Create/Show sidebar config\'s file\n\n'
|
||||
'Examples:\n'
|
||||
'- Check article\'s syntax: tyto check mysubdir/index.tyto\n'
|
||||
'- Create default _configs/tyto.sidebar: tyto new sidebar\n'
|
||||
'- 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),
|
||||
'12' : ':< %sUnused "%s"%s in article\'s header'%(CR, value, 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),
|
||||
'20' : ':D Article %scheck%s on: %s'%(CG, CS, value),
|
||||
'21' : ':D %sValid%s article. Ready to wip'%(CG, CS),
|
||||
|
|
|
@ -42,3 +42,5 @@ def manage_new(target):
|
|||
}
|
||||
|
||||
actions[target](option)
|
||||
else:
|
||||
logs.out("11", '"%s" with "%s"'%(target, option), True)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#**********************************************************************
|
||||
|
||||
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):
|
||||
# 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
|
||||
actions_read = ('show', 'show-db', 'show-wip', 'show-www')
|
||||
|
@ -90,7 +91,6 @@ def manage_show(target):
|
|||
"db" : db.post_db,
|
||||
"wip" : db.post_wip,
|
||||
"www" : db.post_www
|
||||
|
||||
}
|
||||
if args.action in actions_wip: target = "wip"
|
||||
elif args.action in actions_www: target = "www"
|
||||
|
@ -98,7 +98,8 @@ def manage_show(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
|
||||
if args.action in actions_read: read_lines(do[target])
|
||||
|
|
Loading…
Reference in New Issue