Lots of updated codes ; not yet all checked

This commit is contained in:
Cyrille L 2023-02-10 10:40:00 +01:00
parent 6a9ef0ed67
commit 601f56d7af
10 changed files with 461 additions and 352 deletions

View File

@ -35,20 +35,24 @@ if not __name__ == "__main__":
sys.exit(1) sys.exit(1)
import args import args
import check, domain, wip, html, publish action = args.set_action()
target = args.set_target()
noarg = False import check, domain, html, new, publish, show, wip
target = ''
option = ''
# Command start argument # Command start argument
actions = { actions = {
'check' : check.manage_check, 'check' : check.manage_check,
'domain' : domain.manage_domain, 'domain' : domain.manage_domain,
'edit' : show.manage_show,
'editdb' : show.manage_show,
'footer' : html.manage_configs, 'footer' : html.manage_configs,
'metas' : html.manage_configs, 'metas' : html.manage_configs,
'navbar' : html.manage_configs, 'navbar' : html.manage_configs,
'new' : new.manage_new,
'publish' : publish.manage_publish, 'publish' : publish.manage_publish,
'show' : show.manage_show,
'showdb' : show.manage_show,
'sidebar' : html.manage_configs, 'sidebar' : html.manage_configs,
'wip' : wip.manage_wip 'wip' : wip.manage_wip
} }
@ -57,7 +61,7 @@ actions = {
# Argument 1 # Argument 1
#----------- #-----------
try: try:
actions[sys.argv[1]](args.target, args.option) actions[action](target)
except KeyError: except KeyError:
print(':< No action for', sys.argv[1]) print(':< No action for "%s", with "%s"'%(action, target))
sys.exit(1) sys.exit(1)

View File

@ -24,68 +24,54 @@ import sys
# Dict for Actions # Dict for Actions
actions = ( actions = (
'check', 'check',
'domain',
'edit',
'editdb',
'new',
'show',
'showdb',
'wip',
'publish'
)
pass_actions = (
'new'
)
pass_targets = (
'domain', 'domain',
'footer', 'footer',
'metas', 'metas',
'navbar', 'navbar',
'wip',
'publish',
'sidebar' 'sidebar'
) )
# Dict for Options action = ''
options = {
'-a' : 'Add', 'add' : 'Add',
'-c' : 'Create', 'create' : 'Create',
'-d' : 'DB', 'db' : 'DB',
'-e' : "Edit", 'edit' : "Edit",
'-F' : "Force", 'force' : "Force",
'-n' : "New", 'new' : "New",
'-R' : "Remove", 'remove' : "Remove",
'-s' : "Show", 'show' : 'Show',
'again' : 'Again'
}
# Second argument in command
#---------------------------
arguments = (
'-a', 'add',
'-c', 'create',
'-d', 'db',
'-e', 'edit',
'-F', 'force',
'-n', 'new',
'-R', 'remove',
'-s', 'show',
'again'
)
pass_actions = (
'domain'
)
option = ''
target = '' target = ''
# action
#-------
try: try:
sys.argv[1] sys.argv[1]
action = sys.argv[1]
except: except:
print(':< Needed [action] argument') print(':< Needed [action] argument')
sys.exit(1) sys.exit(1)
if not sys.argv[1] in actions: if not action in actions:
print(':< Unused [action] argument: "%s"'%sys.argv[1]) print(':< Unused [action] argument: "%s"'%sys.argv[1])
sys.exit(1) sys.exit(1)
# Check and set arguments from command line # target
#------------------------------------------ #-------
for i in range(2,4):
try: try:
sys.argv[i] sys.argv[2]
if sys.argv[i] in arguments: target = sys.argv[2]
option = options[sys.argv[i]]
else:
target = sys.argv[i]
except: except:
continue target = ''
def set_action():
return(action)
def set_target():
return(target)

View File

@ -31,43 +31,12 @@ post_err = False
# Manage Argument 'check' # # Manage Argument 'check' #
# Start checking article # # Start checking article #
#-------------------------#-------------------------------------------- #-------------------------#--------------------------------------------
def manage_check(target, option): def manage_check(target):
# target needed # target needed
if not target: logs.out("5", '', True) if not target: logs.out("5", '', True)
# Manage option global date_wip, hash_wip, date_www, hash_www
#-------------- date_wip = hash_wip = date_www = hash_www = ''
if option == 'Edit':
curr_hash = tyto.get_filesum(db.uri_file, True)
tyto.edit_file(db.uri_file)
new_hash = tyto.get_filesum(db.uri_file, True)
if curr_hash != new_hash:
ask = ''
try:
ask = input('-> Check your changes ? ')
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in ['y', 'Y']:
logs.out("255", '', True)
else:
option = 'Force'
elif option == 'Show':
article_raw = open(db.uri_file).read()
for line in article_raw.rsplit('\n'):
print(line)
return
# Just read the DB from command
elif option == 'DB':
if db.db_exists:
article_db = open(db.post_db).read()
for line in article_db.rsplit('\n'):
print(line)
return
else:
logs.out("25", db.uri_file, True)
# Article has DB # Article has DB
if db.db_exists: if db.db_exists:
@ -76,13 +45,10 @@ def manage_check(target, option):
if db.incomplete_domain: sys.exit(1) if db.incomplete_domain: sys.exit(1)
# ... was already check and not changed # ... was already check and not changed
if db.hash_chk == db.hash_post and not option == 'Force': if db.hash_chk == db.hash_post:
logs.out("20", db.date_chk, True) logs.out("20", db.date_chk, True)
# ... Set values for wip and www from DB # ... Set values for wip and www from DB
global date_wip, hash_wip, date_www, hash_www
date_wip = hash_wip = date_www = hash_www = ''
date_wip = db.date_wip date_wip = db.date_wip
hash_wip = db.hash_wip hash_wip = db.hash_wip
date_www = db.date_www date_www = db.date_www
@ -140,7 +106,6 @@ def manage_check(target, option):
# Count words in article. Quotes, block-codes, icode = 1 per each # Count words in article. Quotes, block-codes, icode = 1 per each
post_words = len(article_bottom.strip().split(" ")) post_words = len(article_bottom.strip().split(" "))
# Check for valid contents # Check for valid contents
check_content(post_bottom) check_content(post_bottom)
post_bottom = article_bottom.rsplit('\n') post_bottom = article_bottom.rsplit('\n')
@ -148,7 +113,10 @@ def manage_check(target, option):
check_headers(post_header) check_headers(post_header)
# Exit if unused needed tags # Exit if unused needed tags
if post_err: logs.out("7", '', True) if post_err:
if db.db_exists and os.path.exists(db.post_db):
os.remove(db.post_db)
logs.out("7", '', True)
# No error # No error
create_database() create_database()
@ -307,6 +275,7 @@ def check_headers(post_header):
for tag in need_headers: for tag in need_headers:
if not need_headers[tag]: if not need_headers[tag]:
logs_out("6", tag, False) logs_out("6", tag, False)
post_err = True
### ###
@ -316,10 +285,8 @@ def check_headers(post_header):
for ln, line in enumerate(post_header, 1): for ln, line in enumerate(post_header, 1):
if line.startswith('-----'): break if line.startswith('-----'): break
# Set each optional tags # Set each optional tags
#----------------------- #-----------------------
# ABBR # ABBR
#----- #-----
tag = tyto.headers[8] # abbr: tag = tyto.headers[8] # abbr:
@ -406,7 +373,7 @@ def check_headers(post_header):
logs.out("2", "Line %s (Name, %s)"%(ln, tag), False) logs.out("2", "Line %s (Name, %s)"%(ln, tag), False)
post_err = True post_err = True
if not isin(r'\b_%s%s\b'%(tag, image_name), post_bottom): if not isin(r'\b_%s%s\b'%(tag, image_name), post_bottom):
logs.out("6", "_%s%s"%(tag, image_name), False) logs.out("6", '_%s%s'%(tag, image_name), False)
post_err = True post_err = True
image_uri = post_header[ln].lstrip() image_uri = post_header[ln].lstrip()
@ -514,6 +481,7 @@ def check_headers(post_header):
# snpic (set image to share to social networks) # snpic (set image to share to social networks)
#---------------------------------------------- #----------------------------------------------
if snpic_name: continue if snpic_name: continue
snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo) snpic_url = '%s/template/%s'%(db.domain_www_url, db.domain_logo)
tag = tyto.headers[11] # snpic: tag = tyto.headers[11] # snpic:
if line.startswith(tag): if line.startswith(tag):
@ -527,11 +495,8 @@ def check_headers(post_header):
snpic_url = '%s%s'%(db.domain_www_url, web_uri) snpic_url = '%s%s'%(db.domain_www_url, web_uri)
break break
if not snshare: if not snshare:
logs.out("12", '%s %s'%(tyto.headers[6], snpic_name), True) logs.out("12", '%s %s'%(tyto.headers[6], snpic_name), False)
post_err = True
# Exit if error in optional tags
#-------------------------------
if post_err: logs.out("7", '', True)
#================================# #================================#
@ -675,7 +640,9 @@ def check_content(post_bottom):
set_tags = (ptag_set) set_tags = (ptag_set)
if match: continue if match: continue
else: logs.out("12", "%s %s"%(htag, ptag_set), True) else:
logs.out("12", "%s %s"%(htag, ptag_set), False)
post_err = True
# Template Tags (warning for not paired symbols) # Template Tags (warning for not paired symbols)
@ -686,7 +653,7 @@ def check_content(post_bottom):
if tpl1 != tpl2: if tpl1 != tpl2:
logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False) logs.out("22", '"%s", "%s"'%(tag[0], tag[1]), False)
post_err = True
#===============================================# #===============================================#

View File

@ -20,17 +20,29 @@
import os, sys import os, sys
import args, logs, tyto import args, logs, tyto
action = args.action
target = args.target
#======================#
#----------------------#
# DOMAIN Configuration #
#----------------------#
#======================#
# Settings # Settings
#--------- #---------
domain_active = False domain_active = False
incomplete_domain = False
db_exists = False
post_exists = False
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
try:
in_dir = os.getcwd() try: in_dir = os.getcwd()
except: except: logs.out("13", '', False)
logs.out("13", '', False)
domain_conf = in_dir domain_conf = in_dir
incomplete_domain = False
# Settings for domain, check if db is not corrupted # Settings for domain, check if db is not corrupted
domain_values = ( domain_values = (
@ -93,15 +105,8 @@ 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
#---------------------------------------- #----------------------------------------
if '/articles' in in_dir: if '/articles' in in_dir: domain_conf = in_dir.rsplit('/articles')[0]
domain_conf = in_dir.rsplit('/articles')[0] else: domain_conf = in_dir
else:
try:
args.target
if 'articles/' in args.arguments:
domain_conf = in_dir.rsplit('articles/')[0]
except:
domain_conf = in_dir
conf_dir = domain_conf + "/" conf_dir = domain_conf + "/"
domain_conf = '%s/tyto_domain.conf'%domain_conf domain_conf = '%s/tyto_domain.conf'%domain_conf
@ -109,52 +114,55 @@ domain_conf = '%s/tyto_domain.conf'%domain_conf
if os.path.exists(domain_conf): domain_exists = True if os.path.exists(domain_conf): domain_exists = True
else: domain_exists = False else: domain_exists = False
#======================================================================
#------------------------#
# Check if domain is set #
#------------------------#
#======================================================================
stdout = '%s %s domain "%s" in %s' # Show domain status stdout = '%s %s domain "%s" in %s' # Show domain status
if domain_exists: if domain_exists:
exec(open(domain_conf).read()) exec(open(domain_conf).read())
# Check if domain conf is valid
for conf in domain_values: for conf in domain_values:
try: try:
eval(str(conf)) eval(str(conf))
except: except:
incomplete_domain = True incomplete_domain = True
logs.out('10', conf, False) logs.out("10", conf, False)
# Stop process if error, continue if '-n' # Stop process if error, continue if 'new'
if not args.option in domain_pass_args: if not action in args.pass_actions:
if incomplete_domain: if incomplete_domain: sys.exit(1)
sys.exit(1)
try: domain_active try: domain_active
except: domain_active = False except: domain_active = False
# Internal process. No need to show when import reloaded
try:
domain_show
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
else: else:
logs.out("43", domain_conf, False) logs.out("43", domain_conf, False)
domain_show = True
#==================#
#====================================================================== #------------------#
#--------------------------------# # 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:
if args.target: if not action in args.pass_actions:
if not sys.argv[1] in args.pass_actions:
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
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)

View File

@ -17,63 +17,42 @@
#********************************************************************** #**********************************************************************
import os, sys, locale import os, sys, locale, importlib
import logs, db, tyto, html import logs, db, tyto, html
#==========================# #==========================#
# Manage Argument 'domain' # # Manage Argument 'domain' #
# target: 3rd argument #
#--------------------------# #--------------------------#
def manage_domain(target, option): def manage_domain(target):
if option == 'Edit': if not db.domain_exists or db.incomplete_domain:
if db.domain_exists: create_domain(target)
print(":D Edit domain configuration file:", db.domain_conf)
tyto.edit_file(db.domain_conf)
else: else:
sys.exit(1) try:
elif option == 'New':
if not db.domain_exists:
create_domain(target, option)
else:
if not db.incomplete_domain:
ask = input(' ├ Edit the domain configuration with the form ? ') ask = input(' ├ Edit the domain configuration with the form ? ')
if ask in ['y', 'Y']: create_domain(target, option) except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask in ['y', 'Y']: create_domain(target)
else: logs.out("255", '', True) else: logs.out("255", '', True)
else:
create_domain(target, option)
elif option == 'Show':
if db.domain_exists:
domain_db = open(db.domain_conf).read()
for line in domain_db.rsplit('\n'):
print(line)
else:
sys.exit(1)
#=====================#
# Check target if URL #
#---------------------#
def isurl(target):
global url
if target.startswith('http'): url = target
else: logs.out("2", target, True)
#=====================# #=====================#
# Create a new domain # # Create a new domain #
#---------------------# #---------------------#
def create_domain(target, option): def create_domain(target):
if target: isurl(target) if target and not target.startswith('http'):
logs.out("51", '"%s" -> http(s)://...'%target, False)
target = ''
print('\n' print('\n'
' ┌──────────────────────────────────────────────┐\n' ' ┌──────────────────────────────────────────────┐\n'
' │ Configure a new domain for current directory │\n' ' │ Configure a new domain for current directory │\n'
' │ Answer Y = yes. Default value = (default)\n' ' │ Answer Y/y = yes. Enter to set {default}\n'
' │ Empty Answer cancel process, except for │\n' ' │ Empty Answer cancel process, except for │\n'
' │ - "Optional"\n' ' │ - [Optional] │\n'
' │ - "(default) value │\n' ' │ - {default} value │\n'
' ├──────────────────────────────────────────────┘' ' ├──────────────────────────────────────────────┘'
) )
@ -89,50 +68,61 @@ def create_domain(target, option):
valid_url = ('http://', 'https://') valid_url = ('http://', 'https://')
ask = '' ask = ''
try: try:
ask = input(' ├ [http(s)://...] URL to website ? ("%s") '%domain_www_url) ask = input(' ├ [http(s)://...] URL to website ? {%s} '%domain_www_url)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if ask: if ask:
if not ask.startswith(valid_url): if not ask.startswith(valid_url):
logs.out("2", 'http(s)://...', True) logs.out("2", '"%s" -> http(s)://...'%ask, True)
isurl(ask) domain_www_url = ask
domain_www_url = url if not domain_www_url:
elif not domain_www_url:
logs.out("255", '', True) logs.out("255", '', True)
# Remove unused last / if exists
if domain_www_url[-1] == "/":
domain_www_url = domain_www_url[:-1]
domain_proto = domain_www_url.rsplit('://')[0]
domain_short = domain_www_url.rsplit('://')[1] domain_short = domain_www_url.rsplit('://')[1]
# Prefix wip # Prefix wip
#----------- #-----------
domain_wip_url = ''
# Set domain with www-wip.
try: try:
try_wip_url = target.rsplit('.') domain_wip_url = db.domain_wip_url
try_wip_url = 'https://www-wip.%s.%s'%(
try_wip_url[1], try_wip_url[2]
)
except: except:
try_wip_url = 'https://www-wip.%s'%domain_short wip_url = domain_short.rsplit('.', 2)
wip_url[0] = '%s://www-wip'%domain_proto
try: domain_wip_url = db.domain_wip_url for t in wip_url:
except: domain_wip_url = try_wip_url if domain_wip_url:
domain_wip_url = '%s.%s'%(domain_wip_url, t)
else:
domain_wip_url = t
ask = '' ask = ''
try: try:
ask = input(' ├ URL to wip ? ("%s") '%domain_wip_url) ask = input(' ├ URL to wip ? {%s} '%domain_wip_url)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if ask: if ask:
isurl(ask) if not ask.startswith(valid_url):
logs.out("2", '"%s" -> http(s)://...'%ask, True)
domain_wip_url = ask domain_wip_url = ask
# Remove unused last / if exists
if domain_wip_url[-1] == "/":
domain_wip_url = domain_wip_url[:-1]
# Register variables in domain database
global navbars_conf global navbars_conf
db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short) db_dir = '%s/.local/tyto/%s/'%(db.home_dir, domain_short)
db_dir_html = '%shtml/'%db_dir db_dir_html = '%shtml/'%db_dir
navbars_conf = '%sarticles/_configs/'%db.conf_dir navbars_conf = '%sarticles/_configs/'%db.conf_dir
conf_domain = \ set_f = 'domain_dir = "%s"\n'%db.conf_dir + \
'domain_dir = "%s"\n'%db.conf_dir + \
'domain_conf = "%s"\n'%db.domain_conf + \ 'domain_conf = "%s"\n'%db.domain_conf + \
'domain_articles = "%sarticles/"\n'%db.conf_dir + \ 'domain_articles = "%sarticles/"\n'%db.conf_dir + \
'domain_files = "%sarticles/files/"\n'%db.conf_dir + \ 'domain_files = "%sarticles/files/"\n'%db.conf_dir + \
@ -151,9 +141,8 @@ def create_domain(target, option):
'\ndomain_short = "%s"\n'%domain_short + \ '\ndomain_short = "%s"\n'%domain_short + \
'domain_www_url = "%s"\n'%domain_www_url + \ 'domain_www_url = "%s"\n'%domain_www_url + \
'domain_wip_url = "%s"\n'%domain_wip_url 'domain_wip_url = "%s"\n'%domain_wip_url
tyto.set_file(db.domain_conf, True, set_f)
tyto.set_file(db.domain_conf, True, conf_domain) print(' ├ Created new database')
# Get srv root # Get srv root
#------------- #-------------
@ -162,7 +151,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ System server ? ("%s") '%domain_srv) ask = input(' ├ System server ? {%s} '%domain_srv)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -173,7 +162,7 @@ def create_domain(target, option):
root_srv_dom = '%s/%s'%(domain_srv, domain_short) root_srv_dom = '%s/%s'%(domain_srv, domain_short)
srv_wip_tpl = "%s/wip/template/"%root_srv_dom srv_wip_tpl = "%s/wip/template/"%root_srv_dom
srv_www_tpl = "%s/www/template/"%root_srv_dom srv_www_tpl = "%s/www/template/"%root_srv_dom
srvs = '# Servers directories\n' + \ set_f = '# Servers directories\n' + \
'srv_root = "%s/"\n'%domain_srv + \ 'srv_root = "%s/"\n'%domain_srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \ 'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \ 'srv_wip = "%s/wip/"\n'%root_srv_dom + \
@ -194,7 +183,7 @@ def create_domain(target, option):
'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \ 'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas = "%smetas.html"\n'%srv_www_tpl + \ 'www_metas = "%smetas.html"\n'%srv_www_tpl + \
'www_footer = "%sfooter.html"\n'%srv_www_tpl 'www_footer = "%sfooter.html"\n'%srv_www_tpl
tyto.set_file(db.domain_conf, False, srvs) tyto.set_file(db.domain_conf, False, set_f)
# Get title domain # Get title domain
@ -204,7 +193,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ Domain title ? ("%s") '%domain_title) ask = input(' ├ Domain title ? {%s} '%domain_title)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -213,10 +202,9 @@ def create_domain(target, option):
if '"' in domain_title: if '"' in domain_title:
domain_title = domain_title.replace('"', '') domain_title = domain_title.replace('"', '')
tyto.set_file(db.domain_conf, False, set_f = '# Domain user\'s settings\n' + \
'# Domain user\'s settings\n' + \
'domain_title = "%s"'%domain_title 'domain_title = "%s"'%domain_title
) tyto.set_file(db.domain_conf, False, set_f)
# Get Description domain # Get Description domain
@ -226,7 +214,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ Domain Description ? ("%s") '%domain_about) ask = input(' ├ Domain Description ? {%s} '%domain_about)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -235,10 +223,8 @@ def create_domain(target, option):
if '"' in domain_about: if '"' in domain_about:
domain_about = domain_about.replace('"', '') domain_about = domain_about.replace('"', '')
tyto.set_file(db.domain_conf, False, set_f = 'domain_about = "%s"'%domain_about
'domain_about = "%s"'%domain_about tyto.set_file(db.domain_conf, False, set_f)
)
# Get Lang domain # Get Lang domain
#---------------- #----------------
@ -247,7 +233,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ [2 characters] Website language ? ("%s") '%domain_lang) ask = input(' ├ [2 char] Website language ? {%s} '%domain_lang)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -256,9 +242,8 @@ def create_domain(target, option):
else: logs.out("3", ask, True) else: logs.out("3", ask, True)
elif not domain_lang: logs.out("255", '', True) elif not domain_lang: logs.out("255", '', True)
tyto.set_file(db.domain_conf, False, set_f = 'domain_lang = "%s"'%domain_lang
'domain_lang = "%s"'%domain_lang tyto.set_file(db.domain_conf, False, set_f)
)
# Get mail domain # Get mail domain
@ -268,7 +253,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ Webmaster\'s mail ? ("%s") '%domain_mail) ask = input(' ├ Webmaster\'s mail ? {%s} '%domain_mail)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -277,9 +262,8 @@ def create_domain(target, option):
domain_mail = ask domain_mail = ask
elif not domain_mail: logs.out("255", '', True) elif not domain_mail: logs.out("255", '', True)
tyto.set_file(db.domain_conf, False, set_f = 'domain_mail = "%s"'%domain_mail
'domain_mail = "%s"'%domain_mail tyto.set_file(db.domain_conf, False, set_f)
)
# Get Tags domain # Get Tags domain
@ -289,16 +273,15 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ [comma separated] Domain tags ? ("%s") '%domain_tags) ask = input(' ├ [comma separated] Domain tags ? {%s} '%domain_tags)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if ask: domain_tags = ask if ask: domain_tags = ask
elif not domain_tags: logs.out("255", '', True) elif not domain_tags: logs.out("255", '', True)
tyto.set_file(db.domain_conf, False, set_f = 'domain_tags = "%s"'%domain_tags
'domain_tags = "%s"'%domain_tags tyto.set_file(db.domain_conf, False, set_f)
)
# Get logo's website # Get logo's website
@ -308,17 +291,17 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ logo filename ? ("%s") '%domain_logo) ask = input(' ├ logo filename ? {%s} '%domain_logo)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
if ask: domain_logo = ask if ask: domain_logo = ask
tyto.set_file(db.domain_conf, False, set_f = 'domain_logo = "%s"\n'%domain_logo + \
'domain_logo = "%s"\n'%domain_logo + \
'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \ 'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \
'www_logo = "%s%s"\n'%(srv_www_tpl, domain_logo) 'www_logo = "%s%s"\n'%(srv_www_tpl, domain_logo)
) tyto.set_file(db.domain_conf, False, set_f)
# Get License domain # Get License domain
@ -328,7 +311,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ Domain License ? ("%s") '%domain_license) ask = input(' ├ Domain License ? {%s} '%domain_license)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -337,9 +320,8 @@ def create_domain(target, option):
if '"' in domain_license: if '"' in domain_license:
domain_license = domain_license.replace('"', '') domain_license = domain_license.replace('"', '')
tyto.set_file(db.domain_conf, False, set_f = 'domain_license = "%s"'%domain_license
'domain_license = "%s"'%domain_license tyto.set_file(db.domain_conf, False, set_f)
)
# Get License URL (optionnal) # Get License URL (optionnal)
@ -349,7 +331,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input('Optional. License URL ? ("%s") '%domain_licurl) ask = input('[Optional] License URL ? {%s} '%domain_licurl)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -357,9 +339,8 @@ def create_domain(target, option):
if not ask.startswith('http'): logs.out("3", ask, True) if not ask.startswith('http'): logs.out("3", ask, True)
domain_licurl = ask domain_licurl = ask
tyto.set_file(db.domain_conf, False, set_f = 'domain_licurl = "%s"'%domain_licurl
'domain_licurl = "%s"'%domain_licurl tyto.set_file(db.domain_conf, False, set_f)
)
# CSS Prefix # CSS Prefix
@ -369,7 +350,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ [alnum] Prefix CSS ? ("%s") '%domain_css) ask = input(' ├ [alnum] Prefix CSS ? {%s} '%domain_css)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -377,9 +358,8 @@ def create_domain(target, option):
if not ask.isalnum(): logs.out("3", ask, True) if not ask.isalnum(): logs.out("3", ask, True)
domain_css = ask.lower() domain_css = ask.lower()
tyto.set_file(db.domain_conf, False, set_f = 'domain_css = "%s"'%domain_css
'domain_css = "%s"'%domain_css tyto.set_file(db.domain_conf, False, set_f)
)
# Titles webpage separator # Titles webpage separator
@ -389,7 +369,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ [1 character] Pages titles separator ? ("%s") '%domain_sep) ask = input(' ├ [1 char] Pages titles separator ? {%s} '%domain_sep)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -397,9 +377,8 @@ def create_domain(target, option):
if not len(ask) == 1: logs.out("3", ask, True) if not len(ask) == 1: logs.out("3", ask, True)
domain_sep = ask domain_sep = ask
tyto.set_file(db.domain_conf, False, set_f = 'domain_sep = "%s"'%domain_sep
'domain_sep = "%s"'%domain_sep tyto.set_file(db.domain_conf, False, set_f)
)
# Profile for rel="me" (optionnal) # Profile for rel="me" (optionnal)
@ -409,7 +388,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input('Optional. Profile URL ? ("%s") '%domain_relme) ask = input('[Optional] rel="me" URL ? {%s} '%domain_relme)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -417,9 +396,8 @@ def create_domain(target, option):
if not ask.startswith('http'): logs.out("3", ask, True) if not ask.startswith('http'): logs.out("3", ask, True)
domain_relme = ask domain_relme = ask
tyto.set_file(db.domain_conf, False, set_f = 'domain_relme = "%s"'%domain_relme
'domain_relme = "%s"'%domain_relme tyto.set_file(db.domain_conf, False, set_f)
)
# Sidebar Title # Sidebar Title
@ -429,7 +407,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ Sidebar title ? ("%s") '%sidebar_title) ask = input(' ├ Sidebar title ? {%s} '%sidebar_title)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -437,9 +415,8 @@ def create_domain(target, option):
if '"' in sidebar_title: if '"' in sidebar_title:
sidebar_title = sidebar_title.replace('"', '') sidebar_title = sidebar_title.replace('"', '')
tyto.set_file(db.domain_conf, False, set_f = 'sidebar_title = "%s"'%sidebar_title
'sidebar_title = "%s"'%(sidebar_title) tyto.set_file(db.domain_conf, False, set_f)
)
# Sidebar Items # Sidebar Items
@ -449,7 +426,7 @@ def create_domain(target, option):
ask = '' ask = ''
try: try:
ask = input(' ├ [max=16] Sidebar Items ? ("%s") '%sidebar_items) ask = input(' ├ [max=16] Sidebar Items ? {%s} '%sidebar_items)
except KeyboardInterrupt: except KeyboardInterrupt:
print('') print('')
logs.out("255", '', True) logs.out("255", '', True)
@ -457,9 +434,8 @@ def create_domain(target, option):
if not ask.isdigit(): logs.out("3", ask, True) if not ask.isdigit(): logs.out("3", ask, True)
elif int(ask) in range(1,17): sidebar_items = int(ask) elif int(ask) in range(1,17): sidebar_items = int(ask)
tyto.set_file(db.domain_conf, False, set_f = 'sidebar_items = %d'%sidebar_items
'sidebar_items = %s'%(sidebar_items) tyto.set_file(db.domain_conf, False, set_f)
)
# Activate Domain after Resumed configuration ? # Activate Domain after Resumed configuration ?
@ -492,14 +468,14 @@ def create_domain(target, option):
tyto.set_file(db.domain_conf, False, '\ndomain_active = True') tyto.set_file(db.domain_conf, False, '\ndomain_active = True')
# Load config # Load config
exec(open(db.domain_conf).read(),globals()) importlib.reload(db)
# Create folders from configuration file # Create folders from configuration file
folders = ( folders = (
srv_wip_tpl, srv_wip_images, srv_wip_files, db.srv_wip_tpl, db.srv_wip_images, db.srv_wip_files,
srv_www_tpl, srv_www_images, srv_www_files, db.srv_www_tpl, db.srv_www_images, db.srv_www_files,
domain_files, domain_images, navbars_dir, db.domain_files, db.domain_images, db.navbars_dir,
domain_db, html_db db.articles_db, db.html_db
) )
print('') print('')
@ -599,7 +575,7 @@ def create_sidebar(option):
# Create sidebar_load # Create sidebar_load
if create_load: if create_load:
# Create new file, or ask if exists # Create new file, or ask if exists
ask = 'Use default (empty) sidebar configuration ? ' ask = 'Reset sidebar configuration file ? '
log = ' ├ Create file: %s'%db.sidebar_load log = ' ├ Create file: %s'%db.sidebar_load
res = '' res = ''
if os.path.exists(db.sidebar_load): if os.path.exists(db.sidebar_load):
@ -705,7 +681,7 @@ def create_navbar(option):
# Create sidebar_load # Create sidebar_load
if create_load: if create_load:
# Create new file, or ask if exists # Create new file, or ask if exists
ask = 'Use default (empty) navbar configuration ? ' ask = 'Reset navbar configuration file ? '
log = ' ├ Create file: %s'%db.navbar_load log = ' ├ Create file: %s'%db.navbar_load
res = '' res = ''
if os.path.exists(db.navbar_load): if os.path.exists(db.navbar_load):

View File

@ -28,7 +28,6 @@ import logs, db, tyto, domain
def manage_configs(target, option): def manage_configs(target, option):
# Arguments # Arguments
args1 = ('metas', 'sidebar', 'footer', 'navbar') args1 = ('metas', 'sidebar', 'footer', 'navbar')
args2 = ('-n', '-e', '-F', '-c')
opts = ('New', 'Edit', 'Force', 'Create') opts = ('New', 'Edit', 'Force', 'Create')
# Check arguments (from form domain) # Check arguments (from form domain)
@ -234,20 +233,16 @@ def create_html_infos_section(process):
def create_db_load(file_load, file_db): def create_db_load(file_load, file_db):
hash_load = tyto.get_filesum(file_load, True) hash_load = tyto.get_filesum(file_load, True)
if not os.path.exists(file_db): if not os.path.exists(file_db):
tyto.set_file(file_db, set_f = 'file_load_hash = "%s"'%hash_load
'New', tyto.set_file(file_db, True, set_f)
'file_load_hash = "%s"'%hash_load
)
return return
global file_load_hash global file_load_hash
file_load_hash = '' file_load_hash = ''
exec(open(file_db, 'r').read(), globals()) exec(open(file_db, 'r').read(), globals())
if not file_load_hash == hash_load: if not file_load_hash == hash_load:
tyto.set_file(file_db, set_f = 'file_load_hash = "%s"'%hash_load
'New', tyto.set_file(file_db, True, set_f)
'file_load_hash = "%s"'%hash_load
)
#============================================# #============================================#
@ -354,7 +349,7 @@ def create_sidebar(target):
res = input(ask_html) res = input(ask_html)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(target, "w", sidebar_content) tyto.set_file(target, True, sidebar_content)
logs.out("33", target, False) logs.out("33", target, False)
@ -434,10 +429,15 @@ def create_navbar(target):
ask_html = ' ├ Replace %s ? '%db.wip_navbar ask_html = ' ├ Replace %s ? '%db.wip_navbar
res = '' res = ''
if os.path.exists(db.wip_navbar): if os.path.exists(db.wip_navbar):
try:
res = input(ask_html) res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(navbar_file, 'new', menu_html) tyto.set_file(navbar_file, True, menu_html)
print(' ├ Create file: %s'%navbar_file) print(' ├ Create file: %s'%navbar_file)
@ -520,15 +520,19 @@ def create_user_metas(option):
# Create metas_load file according to option # Create metas_load file according to option
#------------------------------------------- #-------------------------------------------
if create_load: if create_load:
ask_load = 'Use default HTML metas configuration ? ' ask_load = 'Reset metas configuration file ? '
log_load = ' ├ Create file: %s'%db.metas_load log_load = ' ├ Create file: %s'%db.metas_load
res = '' res = ''
if os.path.exists(db.metas_load): if os.path.exists(db.metas_load):
try:
res = input(ask_load) res = input(ask_load)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
tyto.set_file(db.metas_load, 'new', metas_tags) tyto.set_file(db.metas_load, True, metas_tags)
create_html = True create_html = True
create_db_load(db.metas_load, db.metas_load_db) create_db_load(db.metas_load, db.metas_load_db)
print(log_load) print(log_load)
@ -543,7 +547,11 @@ def create_user_metas(option):
res = '' res = ''
if os.path.exists(db.wip_metas): if os.path.exists(db.wip_metas):
try:
res = input(ask_html) res = input(ask_html)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
user_file = open(db.metas_load, 'r').read() user_file = open(db.metas_load, 'r').read()
@ -553,7 +561,7 @@ def create_user_metas(option):
if user_metas: user_metas = "%s\n %s"%(user_metas, line) if user_metas: user_metas = "%s\n %s"%(user_metas, line)
else: user_metas = ' %s'%line else: user_metas = ' %s'%line
tyto.set_file(db.wip_metas, 'new', user_metas) tyto.set_file(db.wip_metas, True, user_metas)
print(log_html) print(log_html)
@ -629,15 +637,20 @@ def create_user_footer(option):
# Create new default footer_load, or ask if exists # Create new default footer_load, or ask if exists
#------------------------------------------------- #-------------------------------------------------
if create_load: if create_load:
ask_load = ' ├ Replace default footer configuration ? ' ask_load = ' ├ Reset footer configuration file ? '
log_load = ' ├ Create file: %s'%db.footer_load log_load = ' ├ Create file: %s'%db.footer_load
res = '' res = ''
if os.path.exists(db.footer_load): if os.path.exists(db.footer_load):
try:
res = input(ask_load) res = input(ask_load)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
create_html = True create_html = True
tyto.set_file(db.footer_load, 'new', footer) tyto.set_file(db.footer_load, True, footer)
create_db_load(db.footer_load, db.footer_load_db) create_db_load(db.footer_load, db.footer_load_db)
print(log_load) print(log_load)
@ -647,7 +660,11 @@ def create_user_footer(option):
log_load = ' ├ Create file: %s'%db.wip_footer log_load = ' ├ Create file: %s'%db.wip_footer
res = '' res = ''
if os.path.exists(db.wip_footer): if os.path.exists(db.wip_footer):
try:
res = input(ask_load) res = input(ask_load)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not res in ['y', 'Y']: return if not res in ['y', 'Y']: return
user_footer = '' user_footer = ''
@ -657,7 +674,7 @@ def create_user_footer(option):
if user_footer: user_footer = "%s\n %s"%(user_footer, line) if user_footer: user_footer = "%s\n %s"%(user_footer, line)
else: user_footer = ' %s'%line else: user_footer = ' %s'%line
tyto.set_file(db.wip_footer, 'new', user_footer) tyto.set_file(db.wip_footer, True, user_footer)
print(log_load) print(log_load)

View File

@ -31,10 +31,11 @@ CG = '\033[1;32m'
def out(nbr, value, out): def out(nbr, value, out):
logs = { logs = {
'1' : ':< %sUnused resource%s: %s'%(CR, CS, value), '1' : ':< %sUnused resource%s: %s'%(CR, CS, value),
'2' : ':< %sIncomplete data%s: "%s"'%(CR, CS, value), '2' : ':< %sIncomplete data%s: %s'%(CR, CS, value),
'3' : ':< %sInvalid data%s: "%s"'%(CR, CS, value), '3' : ':< %sInvalid data%s: "%s"'%(CR, CS, value),
'4' : ':< %sCannot create file%s: %s'%(CR, CS, value),
'5' : ':< %sUnused argument%s: [file]'%(CR, CS), '5' : ':< %sUnused argument%s: [file]'%(CR, CS),
'6' : ':< %sUnused "%s"%s in article'%(CR, CS, value), '6' : ':< %sUnused "%s"%s in article'%(CR, value, CS),
'7' : ':< Article is %snot valid yet%s'%(CR, CS), '7' : ':< Article is %snot valid yet%s'%(CR, CS),
'8' : ':< %sNot paired%s: %s'%(CR, CS, value), '8' : ':< %sNot paired%s: %s'%(CR, CS, value),
'9' : ':< Article %shas changed%s. Check it first'%(CR, CS), '9' : ':< Article %shas changed%s. Check it first'%(CR, CS),
@ -60,6 +61,7 @@ def out(nbr, value, out):
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value), '41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),
'42' : ':D %sActive%s domain "%s"'%(CG, CS, value), '42' : ':D %sActive%s domain "%s"'%(CG, CS, value),
'43' : ':? %sNo domain%s configured here: %s'%(CY, CS, value), '43' : ':? %sNo domain%s configured here: %s'%(CY, CS, value),
'51' : ':< %sIncomplete data%s: %s'%(CY, CS, value),
'255' : ';) Maybe later...' '255' : ';) Maybe later...'
} }

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Command arguments 'new' manager
# Description: manage all 'new' from command action argument
# file: new.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 sys
import logs, args, db, domain
#===============================================#
# manage argument new for #
# - domain: target becomes 3rd command argument #
#-----------------------------------------------#
def manage_new(target):
if target == "domain":
try: target = sys.argv[3]
except: target = ''
domain.manage_domain(target)

View File

@ -0,0 +1,112 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: Command arguments 'show', 'showdb' manager
# Description: manage 'show' and 'showdb' from command action argument
# file: show.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 importlib
import args, db, logs, tyto, check
#======================#
# From command line: #
# - 'showdb' / 'show' #
# - 'editdb' / 'edit' #
# Show or edit files #
# final html, db, load #
#----------------------#
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')
# 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}
# 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:
target = "post"
do = {"post" : db.post_db}
# 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,
}
# 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
# Read lines of, or edit file
if args.action in actions_read: read_lines(do[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":
new_hash = tyto.get_filesum(db.uri_file, True)
if curr_hash != new_hash:
ask = ''
try: ask = input('-> Check your changes ? ')
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if not ask in ['y', 'Y']:
logs.out("255", '', True)
# Reload post DB (if edited article, and check it if ask "y")
importlib.reload(db)
check.manage_check(db.uri_file)
#============================================#
# Generic function to read lines from a file #
#--------------------------------------------#
def read_lines(f):
if not f: return # Maybe
datas = open(f).read()
for line in datas.rsplit('\n'):
print(line)

View File

@ -182,17 +182,21 @@ def edit_file(edit_file):
) )
#================# #=================#
# Create a file # # Create a file #
# Or append text # # Or append text #
#----------------# # new: True/false #
#-----------------#
def set_file(path, new, text): def set_file(path, new, text):
if new: opt = "w" if new: opt = "w"
else: opt = "a" else: opt = "a"
try:
file = open(path, opt) file = open(path, opt)
file.write(text + '\n') file.write(text + '\n')
file.close() file.close()
except:
logs.out("4", db.domain_conf, True)
#==========================# #==========================#