Updated code for actions, targets. New help

This commit is contained in:
Cyrille L 2023-02-28 11:21:24 +01:00
parent 6eec2a7d90
commit 2aaa644d0a
7 changed files with 179 additions and 140 deletions

View File

@ -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)

View File

@ -18,12 +18,13 @@
#********************************************************************** #**********************************************************************
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', 'check',
'edit', 'edit',
'edit-db', 'edit-db',
@ -44,7 +45,23 @@ pass_actions = (
) )
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', 'domain',
'footer', 'footer',
'metas', 'metas',
@ -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

View File

@ -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,7 +45,8 @@ 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_dir',
'domain_conf', 'domain_conf',
'domain_articles', 'domain_articles',
@ -100,7 +101,13 @@ domain_values = (
) )
# 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
@ -151,23 +158,26 @@ 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 \
and args.action in args.pass_db \
and not args.target in args.pass_targets:
uri_file = '%s/%s'%(in_dir, args.target) uri_file = '%s/%s'%(in_dir, args.target)
if not os.path.exists(uri_file): if not os.path.exists(uri_file): logs.out("1", uri_file, True)
logs.out("1", uri_file, True)
# Get hash for uri and content file # Get hash for uri and content file
post_exists = True post_exists = True
uri_id = tyto.get_filesum(uri_file, False) uri_id = tyto.get_filesum(uri_file, False)
hash_post = tyto.get_filesum(uri_file, True) 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 # Set DB file for this post
post_db = '%s%s.conf'%(articles_db, uri_id) post_db = '%s%s.conf'%(articles_db, uri_id)
if not os.path.exists(post_db): if not os.path.exists(post_db):

View File

@ -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'
) )

View File

@ -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),

View File

@ -42,3 +42,5 @@ def manage_new(target):
} }
actions[target](option) actions[target](option)
else:
logs.out("11", '"%s" with "%s"'%(target, option), True)

View File

@ -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')
@ -90,7 +91,6 @@ def manage_show(target):
"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])