Some works to do on command arguments. New help with tyto command
This commit is contained in:
parent
601f56d7af
commit
a0c6366113
|
@ -38,21 +38,25 @@ import args
|
|||
action = args.set_action()
|
||||
target = args.set_target()
|
||||
|
||||
import check, domain, html, new, publish, show, wip
|
||||
import check, domain, html, new, publish, show, wip, infos
|
||||
|
||||
# Command start argument
|
||||
actions = {
|
||||
'check' : check.manage_check,
|
||||
'domain' : domain.manage_domain,
|
||||
'help' : infos.tyto,
|
||||
'edit' : show.manage_show,
|
||||
'editdb' : 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,
|
||||
'showdb' : 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
|
||||
}
|
||||
|
|
|
@ -18,24 +18,30 @@
|
|||
#**********************************************************************
|
||||
|
||||
import sys
|
||||
import infos
|
||||
|
||||
# Arguments from command line
|
||||
# tyto [action] [target]
|
||||
#----------------------------
|
||||
# Dict for Actions
|
||||
actions = (
|
||||
'check',
|
||||
'domain',
|
||||
'edit',
|
||||
'editdb',
|
||||
'edit-db',
|
||||
'edit-wip',
|
||||
'edit-www',
|
||||
'help',
|
||||
'new',
|
||||
'show',
|
||||
'showdb',
|
||||
'show-db',
|
||||
'show-wip',
|
||||
'show-www',
|
||||
'wip',
|
||||
'publish'
|
||||
)
|
||||
|
||||
pass_actions = (
|
||||
'new'
|
||||
|
||||
)
|
||||
|
||||
pass_targets = (
|
||||
|
@ -48,28 +54,28 @@ pass_targets = (
|
|||
|
||||
action = ''
|
||||
target = ''
|
||||
noaction = False
|
||||
|
||||
# action
|
||||
#-------
|
||||
try:
|
||||
sys.argv[1]
|
||||
action = sys.argv[1]
|
||||
except:
|
||||
print(':< Needed [action] argument')
|
||||
sys.exit(1)
|
||||
try: action = sys.argv[1]
|
||||
except: noaction = True
|
||||
|
||||
if noaction:
|
||||
infos.tyto(target)
|
||||
sys.exit(0)
|
||||
|
||||
if not action in actions:
|
||||
print(':< Unused [action] argument: "%s"'%sys.argv[1])
|
||||
print(':< Unused [action] argument: "%s"'%action)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# target
|
||||
#-------
|
||||
try:
|
||||
sys.argv[2]
|
||||
target = sys.argv[2]
|
||||
except:
|
||||
target = ''
|
||||
try: target = sys.argv[2]
|
||||
except: target = ''
|
||||
|
||||
# Set action and target for binary
|
||||
def set_action():
|
||||
return(action)
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ domain_values = (
|
|||
)
|
||||
|
||||
# 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
|
||||
|
|
|
@ -503,38 +503,32 @@ def create_domain(target):
|
|||
# sidebar load file translated #
|
||||
#------------------------------#
|
||||
def create_sidebar(option):
|
||||
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
|
||||
|
||||
# Create an empty html file if not exists
|
||||
try:
|
||||
if not os.path.exists(db.wip_sidebar):
|
||||
tyto.set_file(db.wip_sidebar, 'new', '')
|
||||
print(' ├ Create file: %s'%db.wip_sidebar)
|
||||
print(' ├ Create empty file: %s'%db.wip_sidebar)
|
||||
return
|
||||
except:
|
||||
logs.out("4", db.wip_sidebar, True)
|
||||
|
||||
create_load = False # file in _configs
|
||||
create_html = False # file in template/
|
||||
|
||||
# Get metas_load hash or create metas db file if not exists
|
||||
#----------------------------------------------------------
|
||||
# Create new file, or ask if exists
|
||||
ask = ' ├ Reset sidebar configuration file ? '
|
||||
log = ' ├ Create source file: %s'%db.sidebar_load
|
||||
res = ''
|
||||
if os.path.exists(db.sidebar_load):
|
||||
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
|
||||
|
||||
# Manage option
|
||||
#--------------
|
||||
if not os.path.exists(db.sidebar_load):
|
||||
create_load = True
|
||||
elif option == 'New':
|
||||
create_load = True
|
||||
elif option == 'Create':
|
||||
create_html = True
|
||||
elif option == 'Edit':
|
||||
hash_load_old = tyto.get_filesum(db.sidebar_load, True)
|
||||
tyto.edit_file(db.sidebar_load)
|
||||
hash_load_new = tyto.get_filesum(db.sidebar_load, True)
|
||||
if not hash_load_old == hash_load_new:
|
||||
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
|
||||
create_html = True
|
||||
elif option == 'Force':
|
||||
create_load = True
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
# French sidebar_load content
|
||||
sdb_load_fr = '# Pour : Tyto - Littérateur\n' + \
|
||||
|
@ -572,13 +566,30 @@ def create_sidebar(option):
|
|||
if tyto.n == 0: sdb_load = sdb_load_fr
|
||||
elif tyto.n == 1: sdb_load = sdb_load_en
|
||||
|
||||
# Create sidebar_load
|
||||
if create_load:
|
||||
tyto.set_file(db.sidebar_load, 'new', sdb_load)
|
||||
print(log)
|
||||
|
||||
|
||||
#=============================#
|
||||
# navbar load file translated #
|
||||
#-----------------------------#
|
||||
def create_navbar(option):
|
||||
# Check if can process
|
||||
if not db.domain_exists \
|
||||
or db.incomplete_domain \
|
||||
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 new file, or ask if exists
|
||||
ask = ' ├ Reset sidebar configuration file ? '
|
||||
log = ' ├ Create file: %s'%db.sidebar_load
|
||||
ask = ' ├ Reset navbar configuration file ? '
|
||||
log = ' ├ Create source file: %s'%db.navbar_load
|
||||
res = ''
|
||||
if os.path.exists(db.sidebar_load):
|
||||
if os.path.exists(db.navbar_load):
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
|
@ -586,52 +597,8 @@ def create_sidebar(option):
|
|||
logs.out("255", '', True)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
tyto.set_file(db.sidebar_load, 'new', sdb_load)
|
||||
print(log)
|
||||
html.create_db_load(db.sidebar_load, db.sidebar_load_db)
|
||||
|
||||
# Create wip/template/sidebar.html
|
||||
if create_html:
|
||||
html.create_sidebar(db.wip_sidebar)
|
||||
|
||||
|
||||
#=============================#
|
||||
# navbar load file translated #
|
||||
#-----------------------------#
|
||||
def create_navbar(option):
|
||||
if 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 file: %s'%db.wip_navbar)
|
||||
|
||||
create_load = False # file in _configs
|
||||
create_html = False # file in template/
|
||||
|
||||
# Get metas_load hash or create metas db file if not exists
|
||||
#----------------------------------------------------------
|
||||
if os.path.exists(db.navbar_load):
|
||||
html.create_db_load(db.navbar_load, db.navbar_load_db)
|
||||
|
||||
# Manage option
|
||||
#--------------
|
||||
if not os.path.exists(db.navbar_load):
|
||||
create_load = True
|
||||
elif option == 'New':
|
||||
create_load = True
|
||||
elif option == 'Create':
|
||||
create_html = True
|
||||
elif option == 'Edit':
|
||||
hash_load_old = tyto.get_filesum(db.navbar_load, True)
|
||||
tyto.edit_file(db.navbar_load)
|
||||
hash_load_new = tyto.get_filesum(db.navbar_load, True)
|
||||
if not hash_load_old == hash_load_new:
|
||||
html.create_db_load(db.navbar_load, db.navbar_load_db)
|
||||
create_html = True
|
||||
elif option == 'Force':
|
||||
create_load = True
|
||||
|
||||
# French navbar_load content
|
||||
nav_load_fr = '# Pour : Tyto - Littérateur\n' + \
|
||||
'# Type : fichier texte\n' + \
|
||||
'# Description : Fichier utilisé par "tyto wip"\n' + \
|
||||
|
@ -653,6 +620,7 @@ def create_navbar(option):
|
|||
'# a-propos # Informations concernant ce site\n' + \
|
||||
'# %s\n\n'%(15 * "-")
|
||||
|
||||
# English navbar_load content
|
||||
nav_load_en = '# For: Tyto - Littérateur\n' + \
|
||||
'# Type: Text file\n' + \
|
||||
'# Description: file used with "tyto wip"\n' + \
|
||||
|
@ -678,24 +646,5 @@ def create_navbar(option):
|
|||
if tyto.n == 0: nvb_load = nav_load_fr
|
||||
elif tyto.n == 1: nvb_load = nav_load_en
|
||||
|
||||
# Create sidebar_load
|
||||
if create_load:
|
||||
# Create new file, or ask if exists
|
||||
ask = ' ├ Reset navbar configuration file ? '
|
||||
log = ' ├ Create file: %s'%db.navbar_load
|
||||
res = ''
|
||||
if os.path.exists(db.navbar_load):
|
||||
try:
|
||||
res = input(ask)
|
||||
except KeyboardInterrupt:
|
||||
print('')
|
||||
logs.out("255", '', True)
|
||||
if not res in ['y', 'Y']: return
|
||||
|
||||
tyto.set_file(db.navbar_load, 'new', nvb_load)
|
||||
print(log)
|
||||
html.create_db_load(db.navbar_load, db.navbar_load_db)
|
||||
|
||||
# Create wip/template/sidebar.html
|
||||
if create_html:
|
||||
html.create_navbar(db.wip_navbar)
|
||||
|
|
|
@ -249,7 +249,17 @@ def create_db_load(file_load, file_db):
|
|||
# Create HTML sidebar from file tyto.sidebar #
|
||||
#--------------------------------------------#
|
||||
def create_sidebar(target):
|
||||
if not db.domain_exists: return
|
||||
# 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)
|
||||
|
||||
# If content in sidebar, go True
|
||||
sidebar_new = False
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/env python3
|
||||
# Name: Tyto - Littérateur
|
||||
# Type: Show infos about Tyto
|
||||
# Description: Show informations about Tyto - Littérateur
|
||||
# file: infos.py
|
||||
# Folder: /var/lib/tyto/program/
|
||||
# By echolib (XMPP: im@echolib.re)
|
||||
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||||
|
||||
#------------
|
||||
# funny stats
|
||||
#------------
|
||||
# lines:
|
||||
# functions:
|
||||
# comments:
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#**********************************************************************
|
||||
|
||||
import os
|
||||
|
||||
def tyto(target):
|
||||
noinfos = False
|
||||
|
||||
# Show Version
|
||||
try:
|
||||
if os.path.exists('/usr/bin/tyto'):
|
||||
tytobin = open('/usr/bin/tyto').read()
|
||||
for line in tytobin.rsplit('\n'):
|
||||
if line.startswith('# Version:'):
|
||||
print(line)
|
||||
break
|
||||
except:
|
||||
noinfo = True
|
||||
print(':< No /usr/bin/tyto')
|
||||
|
||||
# Show domains list
|
||||
try:
|
||||
db_domains = '%s/.local/tyto'%os.path.expanduser('~')
|
||||
user = os.environ.get('USER')
|
||||
hashdomain = False
|
||||
for folder in os.listdir(db_domains):
|
||||
if os.path.isdir('%s/%s'%(db_domains, folder)):
|
||||
if hashdomain:
|
||||
hasdomain = False
|
||||
hashdomain = True
|
||||
print('# Registred domains for', user)
|
||||
print('-', folder)
|
||||
|
||||
except:
|
||||
noinfo = True
|
||||
print(':< No .../.local/tyto')
|
||||
|
||||
# Show Usage
|
||||
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'
|
||||
'- [action] according to [target]:\n'
|
||||
' edit : Edit article\'s source file\n'
|
||||
' edit-db : Edit post or domain database\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'
|
||||
' 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 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'
|
||||
)
|
|
@ -61,7 +61,7 @@ def out(nbr, value, out):
|
|||
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),
|
||||
'42' : ':D %sActive%s domain "%s"'%(CG, CS, value),
|
||||
'43' : ':? %sNo domain%s configured here: %s'%(CY, CS, value),
|
||||
'51' : ':< %sIncomplete data%s: %s'%(CY, CS, value),
|
||||
'51' : ':? %sIncomplete data%s: %s'%(CY, CS, value),
|
||||
'255' : ';) Maybe later...'
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,13 @@ import logs, args, db, domain
|
|||
#-----------------------------------------------#
|
||||
def manage_new(target):
|
||||
if target == "domain":
|
||||
try: target = sys.argv[3]
|
||||
except: target = ''
|
||||
domain.manage_domain(target)
|
||||
try: URL = sys.argv[3]
|
||||
except: URL = ''
|
||||
domain.manage_domain(URL)
|
||||
|
||||
elif target == 'sidebar':
|
||||
domain.create_sidebar(target)
|
||||
|
||||
elif target == 'navbar':
|
||||
domain.create_navbar(target)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#**********************************************************************
|
||||
|
||||
import importlib
|
||||
import os, importlib
|
||||
import args, db, logs, tyto, check
|
||||
|
||||
|
||||
|
@ -32,52 +32,57 @@ def manage_show(target):
|
|||
# Domain configuration must exists
|
||||
if not db.domain_exists: sys.exit(43)
|
||||
|
||||
# Conditions to filter processes show, or edit
|
||||
actions_target_ct = ('show', 'edit')
|
||||
actions_target_db = ('showdb', 'editdb')
|
||||
actions_read = ('show', 'showdb')
|
||||
actions_edit = ('edit', 'editdb')
|
||||
do = False
|
||||
actions_read = ('show', 'show-db', 'show-wip', 'show-www')
|
||||
actions_edit = ('edit', 'edit-db', 'edit-wip', 'edit-www')
|
||||
|
||||
# target in command is an uri file
|
||||
if args.action in actions_target_ct and db.post_exists:
|
||||
target = "post"
|
||||
do = {"post" : db.uri_file}
|
||||
actions_wip = ('show-wip', 'edit-wip')
|
||||
actions_www = ('show-www', 'edit-www')
|
||||
|
||||
actions_post = ('show', 'edit')
|
||||
actions_db = ('show-db', 'edit-db')
|
||||
|
||||
# Target is not a post uri (sidebar, navbar, metas, footer)
|
||||
#----------------------------------------------------------
|
||||
if target in args.pass_targets:
|
||||
if args.action in actions_post:
|
||||
do = {
|
||||
"domain" : db.domain_conf,
|
||||
"footer" : db.footer_load,
|
||||
"metas" : db.metas_load,
|
||||
"navbar" : db.navbar_load,
|
||||
"sidebar" : db.sidebar_load
|
||||
}
|
||||
|
||||
# Target is a post uri
|
||||
#---------------------
|
||||
elif db.uri_file:
|
||||
|
||||
# Get hash when edit to ask to check again if change
|
||||
if args.action == "edit":
|
||||
curr_hash = tyto.get_filesum(db.uri_file, True)
|
||||
|
||||
# Set DB from article
|
||||
elif args.action in actions_target_db and db.db_exists:
|
||||
if args.action in actions_post:
|
||||
target = "post"
|
||||
do = {"post" : db.post_db}
|
||||
do = {"post" : db.uri_file}
|
||||
|
||||
# Target is a registred name to access file
|
||||
elif target in args.pass_targets:
|
||||
try:
|
||||
# File is a "db" from showdb, editdb
|
||||
if args.action in actions_target_db:
|
||||
do = {
|
||||
'domain' : db.domain_conf,
|
||||
'footer' : db.footer_load,
|
||||
'metas' : db.metas_load,
|
||||
'navbar' : db.navbar_load,
|
||||
'sidebar' : db.sidebar_load,
|
||||
}
|
||||
# Post has database
|
||||
elif db.db_exists:
|
||||
if args.action in actions_wip:
|
||||
target = "wip"
|
||||
do = {"wip" : db.post_wip}
|
||||
|
||||
# File is a source, or final file from show, edit
|
||||
elif args.action in actions_target_ct:
|
||||
do = {
|
||||
'domain' : db.domain_conf,
|
||||
'footer' : db.wip_footer,
|
||||
'metas' : db.wip_metas,
|
||||
'navbar' : db.wip_navbar,
|
||||
'sidebar' : db.wip_sidebar,
|
||||
}
|
||||
except:
|
||||
logs.out("41", '%s configuration'%target, True)
|
||||
else:
|
||||
return
|
||||
elif args.action in actions_www:
|
||||
target = "www"
|
||||
do = {"www" : db.post_www}
|
||||
|
||||
elif args.action in actions_db:
|
||||
target = "db"
|
||||
do = {"db" : db.post_db}
|
||||
|
||||
#print('> show: target', target)
|
||||
|
||||
if not do: logs.out("28", 'yet', True)
|
||||
|
||||
# Read lines of, or edit file
|
||||
if args.action in actions_read: read_lines(do[target])
|
||||
|
@ -106,6 +111,7 @@ def manage_show(target):
|
|||
#--------------------------------------------#
|
||||
def read_lines(f):
|
||||
if not f: return # Maybe
|
||||
if not os.path.exists(f): logs.out("1", f, True)
|
||||
|
||||
datas = open(f).read()
|
||||
for line in datas.rsplit('\n'):
|
||||
|
|
Loading…
Reference in New Issue