[1.9.21] - 3 lines tags supported, cleaner code, see changelog

This commit is contained in:
Cyrille L 2023-10-08 11:28:16 +02:00
parent afa2546abb
commit ff4ecf7d6f
29 changed files with 1502 additions and 1386 deletions

View File

@ -9,6 +9,16 @@ Tyto - Littérateur
# CURRENTLY IN DEV !
## [1.9.21]
- new indentation (3 spaces)
- added 'raw:' marker
- (for wip process):
- - added html titles to post database
- - added html comments to post database (default: ';; a comment')
- - added val3 tag as html comment to content, and convert content to base64
- - - added values to post database
- cleaner code
## [1.9.20]
- working on 'check' process
- - updated 'logo:' process

View File

@ -9,6 +9,11 @@ tyto
## ToDo next (working on)
- 'check' action processes
- create template post database
- - support for words tags (bolds...)
- - support lists, anchors
- - thinking about creating an auto top article menu from titles
- - stats for article words
- manage template post database
- - check valid database
- Translate logs in english !

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Version: 1.9.20
# Updated: 2023-10-06 1696580458
# Version: 1.9.21
# Updated: 2023-10-08 1696756865
# Tyto - Littérateur
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
@ -48,27 +48,27 @@ import os
# Error message #
#---------------#
def error_message(path):
print("! Installation error, unused:", path)
sys.exit(1)
print("! Installation error, unused:", path)
sys.exit(1)
#======================================================#
# A little checker to be sure, all files are installed #
#------------------------------------------------------#
def check_install():
if not os.path.exists(libs): error_message(libs)
if not os.path.exists(trfs): error_message(trfs)
if not os.path.exists(libs): error_message(libs)
if not os.path.exists(trfs): error_message(trfs)
for f in prog_files:
f = os.path.join(libs, f + ".py")
if not os.path.exists(f):
error_message(f)
for f in prog_files:
f = os.path.join(libs, f + ".py")
if not os.path.exists(f):
error_message(f)
# Only default lang files
for f in lang_files:
f = os.path.join(trfs, f + ".py")
if not os.path.exists(f):
error_message(f)
# Only default lang files
for f in lang_files:
f = os.path.join(trfs, f + ".py")
if not os.path.exists(f):
error_message(f)
@ -77,8 +77,8 @@ def check_install():
#======#
import sys
if not __name__ == "__main__":
print("! Error: '%s' not '%s'"%(__name__, "__main__"))
sys.exit(1)
print("! Error: '%s' not '%s'"%(__name__, "__main__"))
sys.exit(1)
# files list in /program/
prog_files = {

View File

@ -40,59 +40,59 @@ import langs, tyto, debug, help, new, check, userset, show
# Action Arguments #
#------------------#
def get_action():
global action
try: action = sys.argv[1]
except: action = ""
global action
try: action = sys.argv[1]
except: action = ""
#==================#
# Target arguments #
#------------------#
def get_target():
global target, targets
try: target = sys.argv[2]
except: target = ""
global target, targets
try: target = sys.argv[2]
except: target = ""
targets = False
if target == "all": targets = True
targets = False
if target == "all": targets = True
#================================#
# Searching options in arguments #
#--------------------------------#
def get_options():
global dlogs, force, erron
global dlogs, force, erron
dlogs = force = erron = False
for arg in range(1, len(sys.argv)):
dlogs = sys.argv[arg] in tyto.debug_options
force = sys.argv[arg] in tyto.force_options
erron = sys.argv[arg] in tyto.debug_errors
dlogs = force = erron = False
for arg in range(1, len(sys.argv)):
dlogs = sys.argv[arg] in tyto.debug_options
force = sys.argv[arg] in tyto.force_options
erron = sys.argv[arg] in tyto.debug_errors
#===========#
# Show logs #
#-----------#
def valid_action():
global action
if not action in tyto.actions:
debug.out(1, "[action]", action, False, 2, False)
action = "help"
global action
if not action in tyto.actions:
debug.out(1, "[action]", action, False, 2, False)
action = "help"
#==============#
# Start action #
#--------------#
def start_process():
# Set Lang logs
langs.load_logs_lang()
# Set Lang logs
langs.load_logs_lang()
get_options()
get_action()
get_target()
valid_action()
get_options()
get_action()
get_target()
valid_action()
do = {
do = {
"help" : help.show,
"check" : check.manage,
"new" : new.manage,
@ -102,5 +102,5 @@ def start_process():
"show" : show.manage,
}
do[action](action, target)
do[action](action, target)

View File

@ -35,7 +35,7 @@
import sys, os
from dateutil.parser import parse
import args, domain, langs, debug, post, tools
import args, domain, langs, debug, post, tools, tyto
#=====================================#
@ -56,14 +56,14 @@ def ready():
# Create user work domain directories #
#-------------------------------------------#
def manage(action, target):
# target is "all"
if args.targets:
multiple_targets
return
# target is "all"
if args.targets:
multiple_targets
return
# target is not "all"
ready()
target.endswith(".tyto") and is_article(target)
# target is not "all"
ready()
target.endswith(".tyto") and is_article(target)
#================================#
@ -71,19 +71,19 @@ def manage(action, target):
# Also used with multiple (loop) #
#--------------------------------#
def is_article(target):
valid(target)
valid(target)
# When all is OK
# Will create post database, but now, show some values
print("chk_date", chk_date)
print()
print("Final text_contents string")
for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines):
print(">", ln, line)
# When all is OK
# Will create post database, but now, show some values
print("chk_date", chk_date)
print()
print("Final text_contents string")
for ln, line in enumerate(post.text_contents.rsplit("\n"), post.head_lines):
print(">", ln, line)
print()
# Write to post database
cf_update_values()
print()
# Write to post database
cf_update_values()
#===========================================#
@ -91,45 +91,45 @@ def is_article(target):
# In error case, exit or return if targetS #
#-------------------------------------------#
def valid(target):
targets = args.targets
targets = args.targets
# Target is a tyto article format
post.is_article(target) or tools.exit(targets, post.error)
# Target is a tyto article format
post.is_article(target) or tools.exit(targets, post.error)
global css
css = domain.cf.get("WEBSITE", "css")
global css
css = domain.cf.get("WEBSITE", "css")
global headers, texts
headers = post.head_contents.rsplit("\n")
texts = post.text_contents.rsplit("\n")
global headers, texts
headers = post.head_contents.rsplit("\n")
texts = post.text_contents.rsplit("\n")
# =============
# Head contents
# =============
# =============
# Head contents
# =============
# One Line targs in head_contents
post.error == 0 and ol_tags() or tools.exit(targets, post.error)
#Multiple and optional Tags on 3 linges
post.error == 0 and ml_tags() or tools.exit(targets, post.error)
# One Line targs in head_contents
post.error == 0 and ol_tags() or tools.exit(targets, post.error)
#Multiple and optional Tags on 3 linges
post.error == 0 and ml_tags() or tools.exit(targets, post.error)
# ============
# Text article
# ============
# Start Lines
# -----------
# Paired tags.
post.error == 0 and sl_paired("bcodes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("quotes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("parags") or tools.exit(targets, post.error)
# Single tags
post.error == 0 and titles() or tools.exit(targets, post.error)
# ============
# Text article
# ============
# Start Lines
# -----------
# Paired tags.
post.error == 0 and sl_paired("bcodes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("quotes") or tools.exit(targets, post.error)
post.error == 0 and sl_paired("parags") or tools.exit(targets, post.error)
# Single tags
post.error == 0 and titles() or tools.exit(targets, post.error)
#===========================================#
# Create a loop to get all .tyto articles #
#-------------------------------------------#
def multiple_targets():
ready()
ready()
#=====================#
@ -139,65 +139,65 @@ def multiple_targets():
# One Line needed tags #
#----------------------#
def ol_tags():
global sitemap, src_uri
global sitemap, src_uri
sitemap = "True"
for ln, line in enumerate(headers, 1):
sitemap = "True"
for ln, line in enumerate(headers, 1):
if not line or line.isspace(): continue
if line.startswith("#"):
post.stats_tyto_head_coms += 1
continue
if not line or line.isspace(): continue
if line.startswith("#"):
post.stats_tyto_head_coms += 1
continue
# One Line tags (Must be set)
# ===========================
if not post.title[1] and line.startswith(post.title[0]):
post.title = (post.title[0], ol_tag_value(line, False))
# One Line tags (Must be set)
# ===========================
if not post.title[1] and line.startswith(post.title[0]):
post.title = (post.title[0], ol_tag_value(line, False))
elif not post.about[1] and line.startswith(post.about[0]):
post.about = (post.about[0], ol_tag_value(line, False))
elif not post.about[1] and line.startswith(post.about[0]):
post.about = (post.about[0], ol_tag_value(line, False))
elif not post.date[1] and line.startswith(post.date[0]):
post.date = (post.date[0], ol_tag_value(line, False))
elif not post.date[1] and line.startswith(post.date[0]):
post.date = (post.date[0], ol_tag_value(line, False))
elif not post.author[1] and line.startswith(post.author[0]):
post.author = (post.author[0], ol_tag_value(line, True))
elif not post.author[1] and line.startswith(post.author[0]):
post.author = (post.author[0], ol_tag_value(line, True))
elif not post.tags[1] and line.startswith(post.tags[0]):
post.tags = (post.tags[0], ol_tag_value(line, True))
elif not post.tags[1] and line.startswith(post.tags[0]):
post.tags = (post.tags[0], ol_tag_value(line, True))
# Optional tags
# -------------
elif not post.logo[1] and line.startswith(post.logo[0]):
post.logo = (post.logo[0], ol_tag_value(line, False))
logo_ln = ln
# Optional tags
# -------------
elif not post.logo[1] and line.startswith(post.logo[0]):
post.logo = (post.logo[0], ol_tag_value(line, False))
logo_ln = ln
elif line.startswith(post.nositemap):
sitemap = "False"
elif line.startswith(post.nositemap):
sitemap = "False"
# Sets are done from loop
# Check if tag value exists
# =========================
if not is_ol_tag(post.date[0], post.date[1]): return False
if not is_valid_date(post.date[1]): return False
if not is_ol_tag(post.title[0], post.title[1]): return False
if not is_ol_tag(post.about[0], post.about[1]): return False
if not is_ol_tag(post.author[0], post.author[1]): return False
if not is_ol_tag(post.tags[0], post.tags[1]): return False
# Sets are done from loop
# Check if tag value exists
# =========================
if not is_ol_tag(post.date[0], post.date[1]): return False
if not is_valid_date(post.date[1]): return False
if not is_ol_tag(post.title[0], post.title[1]): return False
if not is_ol_tag(post.about[0], post.about[1]): return False
if not is_ol_tag(post.author[0], post.author[1]): return False
if not is_ol_tag(post.tags[0], post.tags[1]): return False
# Default domain logo for this post
src_uri = "%stemplate/%s"%(domain.www_url, domain.logo)
# logo is set with specific uri
if is_value2_file_exists(logo_ln, "logo:", post.logo[1]):
src_uri = "%s%s"%(domain.www_url, src_uri)
else:
return False
post.logo = (post.logo[0], src_uri)
post.cf.set("HEADERS", "logo", src_uri)
# Default domain logo for this post
src_uri = "%stemplate/%s"%(domain.www_url, domain.logo)
# logo is set with specific uri
if is_value2_file_exists(logo_ln, "logo:", post.logo[1]):
src_uri = "%s%s"%(domain.www_url, src_uri)
else:
return False
post.logo = (post.logo[0], src_uri)
post.cf.set("HEADERS", "logo", src_uri)
return True
return True
#===========================================#
@ -206,18 +206,18 @@ def ol_tags():
# set new value, removing spaces (strip) #
#-------------------------------------------#
def ol_tag_value(line, commas):
value = line.rsplit(":")[1].lstrip()
value = line.rsplit(":")[1].lstrip()
# reformat comma separated items, removing first spaces
if commas:
tuple_values = value.rsplit(",")
value = ""
for i, item in enumerate(tuple_values):
# reformat comma separated items, removing first spaces
if commas:
tuple_values = value.rsplit(",")
value = ""
for i, item in enumerate(tuple_values):
value = value + item.strip()
if i != len(tuple_values) - 1:
value = value + ","
return value
return value
#===========================#
@ -225,11 +225,11 @@ def ol_tag_value(line, commas):
# Return True/False #
#---------------------------#
def is_ol_tag(tag, value):
if not value:
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
return False
if not value:
post.error = debug.out(51, "%s ?"%tag, post.uri, True, 2, False)
return False
return True
return True
#======================================#
@ -238,162 +238,180 @@ def is_ol_tag(tag, value):
# Return True/False #
#--------------------------------------#
def is_valid_date(date):
global chk_date
global chk_date
try:
parse(date)
chk_date = tools.nowdate()
return True
except:
post.error = debug.out(50, "%s"%date, post.uri, True, 2, False)
return False
try:
parse(date)
chk_date = tools.nowdate()
return True
except:
post.error = debug.out(50, "%s"%date, post.uri, True, 2, False)
return False
#============================#
# multiple and optional Tags #
# Written using 3 lines #
# Tags are stric start line #
#----------------------------#
def ml_tags():
global value1
#global value1
value1 = ""
R_tag = post.ml_tags[3] # raw:
C_tag = post.ml_tags[4] # code:
c = 0 # Continue for next x lines, as tags are 3 lines values
c = 0 # Continue for next x lines, as tags are 3 lines values
for ln, line in enumerate(headers):
for ln, line in enumerate(headers):
if c != 0:
c -= 1
continue
if not line or line.isspace() or line.startswith("#"): continue
if line.startswith(post.ml_tags):
tag = line.rsplit(":")[0] + ":"
post.ml_tags_stats[tag] = post.ml_tags_stats[tag] + 1
# link:
if line.startswith(post.ml_tags[0]):
post.stats_links += 1
if not ml_tag_values(ln, post.ml_tags[0], post.stats_links):
return False # value errors
if not ml_tag_values(ln, tag, post.ml_tags_stats[tag]):
return False
c = 2 ; continue
c = 2
continue
# file:
elif line.startswith(post.ml_tags[2]):
post.stats_files += 1
if not ml_tag_values(ln, post.ml_tags[2], post.stats_files):
return False # value errors
c = 2 ; continue
# image:
elif line.startswith(post.ml_tags[1]):
post.stats_images += 1
if not ml_tag_values(ln, post.ml_tags[1], post.stats_images):
return False # value errors
# image: logo is reserved for post logo
if value1 == "logo":
debug.out(56, "%s) 'logo'"%(ln+1), post.uri, True, 2, False)
return False
c = 2 ; continue
# ABBRS:
elif line.startswith(post.ml_tags[5]):
post.stats_abbrs += 1
if not ml_tag_values(ln, post.ml_tags[5], post.stats_abbrs):
return False # value errors
c = 2 ; continue
# value1 must not starts with "_", as used by Tyto
if value1.startswith("_"):
debug.out(56, "%s) '_...'"%(ln+1), post.uri, True, 2, False)
return False
return True
return True
#========================================#
# Get tag 3 lines values #
# Check if 2nd, 3rd lines starts with a: #
# Check if 2nd, 3rd lines starts with: #
# - tag, comment or are empty #
# Set globals value #
# Create var and val for post database #
# Return True/False (if no value) #
#----------------------------------------#
def ml_tag_values(ln, tag, stats):
global value1, value2
global value1, value2
# Get 3 lines values
value1 = headers[ln].rsplit(":")[1].lstrip()
value2 = headers[ln+1].lstrip()
value3 = headers[ln+2].lstrip()
# Get 3 lines values
value1 = headers[ln].rsplit(":")[1].lstrip()
value2 = headers[ln+1].lstrip()
value3 = headers[ln+2].lstrip()
# Check values (not empty or begins with a tag)
if not value1:
post.error = \
debug.out(51, "%s) %s 1/3"%(ln+1, tag), post.uri, True, 2, False)
return False
# Check values (not empty or begins with a tag)
# value1
# ------
if not value1:
post.error = \
debug.out(51, "%s) %s 1/3"%(ln+1, tag), post.uri, True, 2, False)
return False
if not value2 or value2.startswith(post.ml_tags):
post.error = \
debug.out(51, "%s) %s 2/3"%(ln+2, tag), post.uri, True, 2, False)
return False
# value1 must not starts or contains:o
elif value1.startswith("_"):
debug.out(56, "%s) '_...'"%(ln+1), post.uri, True, 2, False)
return False
if not value3 or value3.startswith(post.ml_tags):
post.error = \
debug.out(51, "%s) %s 3/3"%(ln+3, tag), post.uri, True, 2, False)
return False
# Specific for image: logo name is reserved
elif tag == post.ml_tags[1] and value1 == "logo":
debug.out(56, "%s) 'logo'"%(ln+1), post.uri, True, 2, False)
return False
# Convert value1 in header with tyto_value1 in text
tyto_value = post.ml_marks[tag] + value1
# value2
# ------
if not value2 or value2.startswith(post.ml_tags):
post.error = \
debug.out(51, "%s) %s 2/3"%(ln+2, tag), post.uri, True, 2, False)
return False
# CHeck if value is in text and to stats or return error
if post.text_contents.find(tyto_value) == -1:
post_error = debug.out(51, tyto_value, post.uri, True, 2, False)
return False
# value3
# ------
if not value3 or value3.startswith(post.ml_tags):
post.error = \
debug.out(51, "%s) %s 3/3"%(ln+3, tag), post.uri, True, 2, False)
return False
# Check value2 link for some tags (file, image...)
if tag in post.value2s_uri \
and not value2.startswith(post.value2s_ext_uris):
if not is_value2_file_exists(ln+2, tag, value2):
return False
# No error with values
# Convert value1 in header with tyto_value1 in text
tyto_value = post.ml_tags_marks[tag] + value1
# Convert values to HTML (put in post database)
link_var = "%s_%s"%(tag.replace(":", ""), stats)
html_var = "html_%s"%stats
# CHeck if value is in text and to stats or return error
if post.text_contents.find(tyto_value) == -1:
post_error = debug.out(51, tyto_value, post.uri, True, 2, False)
return False
if tag == post.ml_tags[0]:
section = "LINKS"
post.stats_text_links += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
# Check value2 link for some tags (file, image...)
if tag in post.value2s_uri \
and not value2.startswith(post.value2s_ext_uris) \
and not is_value2_file_exists(ln+2, tag, value2):
return False
elif tag == post.ml_tags[2]:
section = "FILES"
post.stats_text_files += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_file" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
elif tag == post.ml_tags[1]:
section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, "%%s", "%%s", value3, "%%s"
)
#-----------------------------------------------#
# Convert values to HTML (put in post database) #
#-----------------------------------------------#
link_var = "%s_%s"%(tag.replace(":", ""), stats)
html_var = "html_%s"%stats
elif tag == post.ml_tags[5]:
section = "ABBRS"
post.stats_text_abbrs += post.text_contents.count(tyto_value)
html_value = '<abbr class="%s" title="%s">%s</abbr>'%(
domain.css, value2, value3
)
# link:
if tag == post.ml_tags[0]:
section = "LINKS"
post.stats_text_links += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
post.cf.set(section, link_var, tyto_value)
post.cf.set(section, html_var, html_value)
# file:
elif tag == post.ml_tags[2]:
section = "FILES"
post.stats_text_files += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s_file" target="%s" alt="%s">%s</a>'%(
value2, css, "%%s", value3, value1
)
return True
# image:
elif tag == post.ml_tags[1]:
section = "IMAGES"
post.stats_text_images += post.text_contents.count(tyto_value)
html_value = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
value2, "%%s", "%%s", value3, "%%s"
)
# raw: (content file converted to base64)
elif tag == post.ml_tags[3]:
section = "RAWS"
post.stats_text_raws += post.text_contents.count(tyto_value)
html_value = "<!-- %s -->"%value3
with open(value2_uri, "r") as f:
html_value = "%s\n%s"%(html_value, f.read())
html_value = tools.b64_convert("encode", html_value)
# code: (content file converted to HTML + base64)
elif tag == post.ml_tags[4]:
section = "CODES"
post.stats_text_codes += post.text_contents.count(tyto_value)
htmlbcode = "<!-- %s -->"%value3
with open(value2_uri, "r") as f:
for line in f.read().rsplit("\n"):
line = tools.convert_html_signs(line)
line = '<li class="%s_blockcode">%s</li>'%(domain.css, line)
htmlbcode = "%s\n%s"%(htmlbcode, line)
html_value = tyto.pre_bcode%(
domain.css, domain.css, domain.css,
htmlbcode
)
print()
print(html_value)
print()
html_value = tools.b64_convert("encode", html_value)
# abbr:
elif tag == post.ml_tags[5]:
section = "ABBRS"
post.stats_text_abbrs += post.text_contents.count(tyto_value)
html_value = '<abbr class="%s" title="%s">%s</abbr>'%(
domain.css, value2, value3
)
post.cf.set(section, link_var, tyto_value)
post.cf.set(section, html_var, html_value)
return True
#================================#
@ -404,45 +422,45 @@ def ml_tag_values(ln, tag, stats):
# - ... for post directory #
#--------------------------------#
def is_value2_file_exists(ln, tag, val2):
global value2, src_uri
global value2, src_uri, value2_uri
# uri "@..." means generic folders
if val2[0].startswith("@"):
if val2[1] == "/": val2 = val2[2:]
else: val2 = val2[1:]
# uri "@..." means generic folders
if val2[0].startswith("@"):
if val2[1] == "/": val2 = val2[2:]
else: val2 = val2[1:]
#Set directory for files
test_uri = os.path.join(domain.wrk_files + val2)
value2 = src_uri = os.path.join("/files", val2)
#Set directory for files
value2_uri = os.path.join(domain.wrk_files + val2)
value2 = src_uri = os.path.join("/files", val2)
# Set directory for images in /images
if tag == post.ml_tags[1] or tag == post.logo[0]: # image:
test_uri = os.path.join(domain.wrk_images, val2)
value2 = src_uri = os.path.join("/images", val2)
# Set directory for images in /images
if tag == post.ml_tags[1] or tag == post.logo[0]: # image:
value2_uri = os.path.join(domain.wrk_images, val2)
value2 = src_uri = os.path.join("/images", val2)
# uri "/..." means from wrk root folder
elif val2[0].startswith("/"):
val2 = val2[1:]
test_uri = os.path.join(domain.wrk_articles, val2)
src_uri = val2
# uri "/..." means from wrk root folder
elif val2[0].startswith("/"):
val2 = val2[1:]
value2_uri = os.path.join(domain.wrk_articles, val2)
src_uri = val2
# uri "..." means from legacy post folder
else:
test_uri = os.path.dirname(post.uri) + "/" + val2
value2 = "./" + val2
src_uri = test_uri.rsplit("articles/")[1]
# uri "..." means from legacy post folder
else:
value2_uri = os.path.dirname(post.uri) + "/" + val2
value2 = "./" + val2
src_uri = value2_uri.rsplit("articles/")[1]
# Check if file exists
if not os.path.exists(test_uri):
post.error = \
debug.out(5, "%s) %s"%(ln, tag), test_uri, True, 2, False)
return False
# Check if file exists
if not os.path.exists(value2_uri):
post.error = \
debug.out(5, "%s) %s"%(ln, tag), value2_uri, True, 2, False)
return False
# Add file to [SOURCE_FILES] post database
post.stats_total_files += 1
post.cf.set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri)
# Add file to [SOURCE_FILES] post database
post.stats_total_files += 1
post.cf.set("SOURCE_FILES", "file_%s"%post.stats_total_files, src_uri)
return True
return True
#=====================#
@ -459,101 +477,99 @@ def is_value2_file_exists(ln, tag, val2):
# Return True/False #
#----------------------------------------#
def sl_paired(markers):
global texts
global texts
new_text_contents = ""
opened = closed = in_tag = False
stats_opened = stats_closed = 0
tags = ()
new_text_contents = ""
opened = closed = in_tag = False
stats_opened = stats_closed = 0
tags = ()
if markers == "bcodes" : tags = post.bcodes
elif markers == "quotes" : tags = post.quotes
elif markers == "parags" : tags = post.parags
if markers == "bcodes" : tags = post.bcodes
elif markers == "quotes" : tags = post.quotes
elif markers == "parags" : tags = post.parags
# loop lines in text_contents
for ln, line in enumerate(texts, post.head_lines + 1):
# loop lines in text_contents
for ln, line in enumerate(texts, post.head_lines + 1):
# Tag was closed, but not in_tag content line
if closed and in_tag:
in_tag = False
# Tag was closed, but not in_tag content line
if closed and in_tag:
in_tag = False
# Tag is opened
if line.startswith(tags[0]):
# Tag was already opened
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# Tag is opened
if line.startswith(tags[0]):
# Tag was already opened
if opened:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
# check next line if exists or is a closed tag
try:
next_line = post.contents.rsplit("\n")[ln]
if next_line.startswith(tags[1]):
# check next line if exists or is a closed tag
try:
next_line = post.contents.rsplit("\n")[ln]
if next_line.startswith(tags[1]):
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
except:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
except:
post.error = \
debug.out(55, "%s) '%s'"%(ln, tags[0]), post.uri, True, 2, False)
return False
opened = in_tag = True
closed = False
stats_opened += 1
opened = in_tag = True
closed = False
stats_opened += 1
# Tag is closed
if line.startswith(tags[1]):
# Tag was already closed
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
closed = True
opened = False
stats_closed += 1
if in_tag:
# Contents must be indented
if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) '\t'%s..."%(
ln+1, line[0:10]
# Tag is closed
if line.startswith(tags[1]):
# Tag was already closed
if closed:
post.error = \
debug.out(53, "%s) %s ... %s"%(
ln+1,
tags[0], tags[1]
), post.uri, True, 2, False)
return False
line = ""
return False
# Create new string, removing in_tag line if in bcodes or quotes
if markers in post.raw_contents:
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
closed = True
opened = False
stats_closed += 1
texts = new_text_contents.rsplit("\n")
# Create post.stats
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
if in_tag:
# Contents must be indented
if not line.startswith(tags):
if len(line) - len(line.lstrip()) < 3:
post.error = \
debug.out(54, "%s) '\t'%s..."%(
ln+1, line[0:10]
), post.uri, True, 2, False)
return False
line = ""
return True
# Create new string, removing in_tag line if in bcodes or quotes
if markers in post.raw_contents:
if not new_text_contents: new_text_contents = line
else: new_text_contents = "%s\n%s"%(new_text_contents, line)
texts = new_text_contents.rsplit("\n")
# Create post.stats
post.cf.set("STATS_TEXTS", markers, str(stats_opened))
return True
#============================#
# Check optional title tags #
# Count tyto + html comments #
# Add stat for logo #
# Add stat for _image:logo #
# Return True/False #
#----------------------------#
def titles():
for ln, line in enumerate(texts, post.head_lines + 1):
if not line or line.isspace(): continue
# legacy Tyto Titles
if line.startswith(post.tyto_titles):
if not line[3:]:
@ -563,31 +579,49 @@ def titles():
# Avoic wanting #6 - #9 (but accept #1x.. #5x.. as comments...)
elif line[1].isdigit() and int(line[1]) >= 6:
post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
return False
post.error = \
debug.out(52, "%s) %s..."%(ln, line[0:10]), post.uri, True, 1, False)
return False
post.stats_titles += 1
# Create html value for this title in database
link_var = "title_%s"%post.stats_titles
post.cf.set("TITLES", link_var, line)
html_var = "html_%s"%post.stats_titles
mark = line[0:2]
title = line[3:]
html_val = post.html_titles[mark]%(domain.css, title)
post.cf.set("TITLES", html_var, html_val)
# Count Tyto Comments
elif line.lstrip().startswith("#"):
post.stats_tyto_text_coms += 1
post.stats_tyto_text_coms += 1
# Count HTML comments
elif line.lstrip().startswith(post.text_comments):
post.stats_html_coms += 1
post.stats_html_coms += 1
# Convert tyto commented marker to HTML
if line.lstrip().startswith(post.text_comments[0]):
real_com = line.lstrip()[3:]
link_var = "comm_%s"%post.stats_html_coms
post.cf.set("COMMENTS", link_var, line.lstrip())
html_var = "html_%s"%post.stats_html_coms
post.cf.set("COMMENTS", html_var, '<!-- %s -->'%real_com)
# Add stat + html for [IMAGES] when user wants to show logo in post
elif line.lstrip().startswith("_image:logo"):
post.stats_text_images += 1
link_var = "image_%s"%(post.stats_images+1)
link_val = "_image:logo"
html_var = "html_%s"%(post.stats_images+1)
html_val = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
post.logo[1], "%%s", "%%s", post.title[1], "%%s"
)
post.cf.set("IMAGES", link_var, link_val)
post.cf.set("IMAGES", html_var, html_val)
post.stats_text_images += 1
link_var = "image_%s"%(post.ml_tags_stats["image:"] + 1)
link_val = "_image:logo"
html_var = "html_%s"%(post.ml_tags_stats["image:"] + 1)
html_val = '<a href="%s" class="%s" target="%s" alt="%s">%s</a>'%(
post.logo[1], "%%s", "%%s", post.title[1], "%%s"
)
post.cf.set("IMAGES", link_var, link_val)
post.cf.set("IMAGES", html_var, html_val)
return True
@ -596,54 +630,58 @@ def titles():
# Update post configuration file #
#--------------------------------#
def cf_update_values():
post.date = ("date:", tools.local_date(post.date[1]))
post.date = ("date:", tools.local_date(post.date[1]))
post.cf.set("DOMAIN", "name", domain.name)
post.cf.set("DOMAIN", "name", domain.name)
post.cf.set("FILE", "id", post.uri_id)
post.cf.set("FILE", "uri", post.uri)
post.cf.set("FILE", "db", post.cf_uri)
post.cf.set("FILE", "target", post.wrk_target)
post.cf.set("FILE", "id", post.uri_id)
post.cf.set("FILE", "uri", post.uri)
post.cf.set("FILE", "db", post.cf_uri)
post.cf.set("FILE", "target", post.wrk_target)
post.cf.set("HEADERS", "title", post.title[1])
post.cf.set("HEADERS", "about", post.about[1])
post.cf.set("HEADERS", "date", post.date[1])
post.cf.set("HEADERS", "tags", post.tags[1])
post.cf.set("HEADERS", "authors", post.author[1])
post.cf.set("HEADERS", "sitemap", str(sitemap))
post.cf.set("HEADERS", "title", post.title[1])
post.cf.set("HEADERS", "about", post.about[1])
post.cf.set("HEADERS", "date", post.date[1])
post.cf.set("HEADERS", "tags", post.tags[1])
post.cf.set("HEADERS", "authors", post.author[1])
post.cf.set("HEADERS", "sitemap", str(sitemap))
post.cf.set("CHECK", "hash", post.wrk_id)
post.cf.set("CHECK", "date", chk_date)
post.cf.set("CHECK", "static", str(domain.static))
post.cf.set("CHECK", "hash", post.wrk_id)
post.cf.set("CHECK", "date", chk_date)
post.cf.set("CHECK", "static", str(domain.static))
post.cf.set("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf.set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
post.cf.set("WIP", "web", "%s%s"%(domain.wip_url, post.wrk_target))
post.cf.set("WIP", "uri", "%s%s"%(domain.wip, post.wrk_target))
post.cf.set("WWW", "web", "%s%s"%(domain.www_url, post.wrk_target))
post.cf.set("WWW", "uri", "%s%s"%(domain.www, post.wrk_target))
post.cf.set("WWW", "web", "%s%s"%(domain.www_url, post.wrk_target))
post.cf.set("WWW", "uri", "%s%s"%(domain.www, post.wrk_target))
stats_tyto_all_coms = post.stats_tyto_text_coms + post.stats_tyto_head_coms
post.cf.set("STATS_FILE", "lines", str(post.lines))
post.cf.set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf.set("STATS_FILE", "files", str(post.stats_total_files))
stats_tyto_all_coms = post.stats_tyto_text_coms + post.stats_tyto_head_coms
post.cf.set("STATS_FILE", "lines", str(post.lines))
post.cf.set("STATS_FILE", "tyto_coms", str(stats_tyto_all_coms))
post.cf.set("STATS_FILE", "files", str(post.stats_total_files))
post.cf.set("STATS_HEADERS", "lines", str(post.head_lines))
post.cf.set("STATS_HEADERS", "tyto_coms", str(post.stats_tyto_head_coms))
post.cf.set("STATS_HEADERS", "links", str(post.stats_links))
post.cf.set("STATS_HEADERS", "files", str(post.stats_files))
post.cf.set("STATS_HEADERS", "images", str(post.stats_images))
post.cf.set("STATS_HEADERS", "abbrs", str(post.stats_abbrs))
post.cf.set("STATS_HEADERS", "lines", str(post.head_lines))
post.cf.set("STATS_HEADERS", "tyto_coms", str(post.stats_tyto_head_coms))
post.cf.set("STATS_HEADERS", "links", str(post.ml_tags_stats["link:"]))
post.cf.set("STATS_HEADERS", "files", str(post.ml_tags_stats["file:"]))
post.cf.set("STATS_HEADERS", "images", str(post.ml_tags_stats["image:"]))
post.cf.set("STATS_HEADERS", "abbrs", str(post.ml_tags_stats["abbr:"]))
post.cf.set("STATS_HEADERS", "codes", str(post.ml_tags_stats["code:"]))
post.cf.set("STATS_HEADERS", "raws", str(post.ml_tags_stats["raw:"]))
post.cf.set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf.set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
post.cf.set("STATS_TEXTS", "html_coms", str(post.stats_html_coms))
post.cf.set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf.set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf.set("STATS_TEXTS", "files", str(post.stats_text_files))
post.cf.set("STATS_TEXTS", "images", str(post.stats_text_images))
post.cf.set("STATS_TEXTS", "abbrs", str(post.stats_text_abbrs))
post.cf.set("STATS_TEXTS", "lines", str(post.text_lines))
post.cf.set("STATS_TEXTS", "tyto_coms", str(post.stats_tyto_text_coms))
post.cf.set("STATS_TEXTS", "html_coms", str(post.stats_html_coms))
post.cf.set("STATS_TEXTS", "titles", str(post.stats_titles))
post.cf.set("STATS_TEXTS", "links", str(post.stats_text_links))
post.cf.set("STATS_TEXTS", "files", str(post.stats_text_files))
post.cf.set("STATS_TEXTS", "images", str(post.stats_text_images))
post.cf.set("STATS_TEXTS", "abbrs", str(post.stats_text_abbrs))
post.cf.set("STATS_TEXTS", "codes", str(post.stats_text_codes))
post.cf.set("STATS_TEXTS", "raws", str(post.stats_text_raws))
with open(post.cf_uri, "w") as f:
post.cf.write(f)
with open(post.cf_uri, "w") as f:
post.cf.write(f)

View File

@ -47,32 +47,32 @@ import langs, args
# stop to sys exit with nbr if True #
#-----------------------------------#
def out(nbr, var, val, show, color, stop):
args.get_options()
if not show:
# Show only warn and error logs
show = args.dlogs or args.erron and color > 0
args.get_options()
if not show:
# Show only warn and error logs
show = args.dlogs or args.erron and color > 0
if not show:
return nbr
if not show:
return nbr
# COlors
CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink
# COlors
CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink
# Color of "*"
SC = CL # Default gray
if color == 0: SC = CG
elif color == 1: SC = CY
elif color == 2: SC = CR
# Color of "*"
SC = CL # Default gray
if color == 0: SC = CG
elif color == 1: SC = CY
elif color == 2: SC = CR
# Messages for logs
messages = \
# Messages for logs
messages = \
{
# ERRORS (1-100)
1 : langs.logs.err_arg,
@ -117,21 +117,20 @@ def out(nbr, var, val, show, color, stop):
}
# Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
# Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
SC, CS,
CL, messages[nbr], CS,
CB, var, CS,
CC, val, CS
)
)
)
# Exit if stop = True
if stop:
if nbr >= 200:
nbr = 0
sys.exit(nbr)
# Exit if stop = True
if stop:
if nbr >= 200: nbr = 0
sys.exit(nbr)
return nbr
return nbr

View File

@ -40,8 +40,8 @@ import debug, tyto, tools, forms, langs
# Exit if directory name is compatible with a domain name #
#---------------------------------------------------------#
def compatible_name():
if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True)
if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True)
#================================#
@ -49,13 +49,13 @@ def compatible_name():
# As needed, exit if not exists #
#--------------------------------#
def cf_load():
global cf
global cf
cf_exists() or sys.exit(100)
cf_exists() or sys.exit(100)
cf = False
cf = configparser.ConfigParser()
cf.read(cf_uri)
cf = False
cf = configparser.ConfigParser()
cf.read(cf_uri)
#=====================================#
@ -63,29 +63,29 @@ def cf_load():
# As needed, exit if not exists #
#-------------------------------------#
def ult_cf_load():
global ult_cf
global ult_cf
ult_cf = False
if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
ult_cf = False
if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri)
ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri)
#===================================#
# Load User local Domains List File #
#-----------------------------------#
def ult_dlf_load():
global ult_dlf
global ult_dlf
# User Domains list file
ult_dlf = False
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# User Domains list file
ult_dlf = False
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri)
ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri)
#===========================================#
@ -94,36 +94,36 @@ def ult_dlf_load():
# return True or False
#-------------------------------------------#
def cf_exists():
global shown_ok, shown_no
global shown_ok, shown_no
if os.path.exists(cf_uri):
try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True
return True
else:
try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True
compatible_name()
return False
if os.path.exists(cf_uri):
try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True
return True
else:
try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True
compatible_name()
return False
#=========================================#
# Guess and return wip_url from name #
#-----------------------------------------#
def create_wip_url():
www_url = "https://www-wip.%s/"
len_cn = name.count(".")
www_url = "https://www-wip.%s/"
len_cn = name.count(".")
# Domain name Format: a.b
if len_cn == 1:
return www_url%name
# Domain name Format: a.b
if len_cn == 1:
return www_url%name
# Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:]
return www_url%tld
# Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:]
return www_url%tld
#==========================================#
@ -134,41 +134,41 @@ def create_wip_url():
# If not User domains list file, create it #
#------------------------------------------#
def cf_create():
compatible_name()
compatible_name()
# This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log
if cf_exists():
debug.out(102, "!?", cf_uri, True, 1, False)
# This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log
if cf_exists():
debug.out(102, "!?", cf_uri, True, 1, False)
# Ask User to create new domain. Will exit if not ok.
forms.ask_domain_shortname(name)
# Ask User to create new domain. Will exit if not ok.
forms.ask_domain_shortname(name)
# Create default files
tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# Create default files
tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# User Domains list file
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# User Domains list file
if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# Ask user for domain settings
cf_load()
forms.ask_domain_title(True)
forms.ask_domain_date(True)
forms.ask_domain_about(True)
forms.ask_domain_mail(True)
forms.ask_domain_tags(True)
# Ask user for domain settings
cf_load()
forms.ask_domain_title(True)
forms.ask_domain_date(True)
forms.ask_domain_about(True)
forms.ask_domain_mail(True)
forms.ask_domain_tags(True)
# Set default lang, from config file or system lang
forms.ask_domain_lang(True)
# Set default lang, from config file or system lang
forms.ask_domain_lang(True)
# Set server directory
forms.ask_domain_server(True)
# Set server directory
forms.ask_domain_server(True)
# Update Domain Configuration file
cf_update_values(True)
# Update Domain Configuration file
cf_update_values(True)
@ -179,35 +179,35 @@ def cf_create():
# Ask yser when default is a key form and not value #
#---------------------------------------------------#
def cf_set_value(section, key, default):
global new_val
try: new_val
except: new_val = False
global new_val
try: new_val
except: new_val = False
try:
val = cf.get(section, key)
except:
try: cf.add_section(section) ; new_val = True
except: pass
val = ""
try:
val = cf.get(section, key)
except:
try: cf.add_section(section) ; new_val = True
except: pass
val = ""
# Values has a form
if default in tyto.keys_4q:
if val: return val
else: default = tyto.keys_questions[default](False) ; new_val = True
# Values has a form
if default in tyto.keys_4q:
if val: return val
else: default = tyto.keys_questions[default](False) ; new_val = True
# Optional key
elif not default:
if not val: return default
else: default = val
# Optional key
elif not default:
if not val: return default
else: default = val
# Force set default value
if val != default:
new_val = True
# Force set default value
if val != default:
new_val = True
cf.set(section, key, default)
debug.out(204, "[%s] %s"%(section, key), default, False, 0, False)
cf.set(section, key, default)
debug.out(204, "[%s] %s"%(section, key), default, False, 0, False)
return default
return default
#===========================================#
@ -216,334 +216,334 @@ def cf_set_value(section, key, default):
# Ensure to set correct values #
#-------------------------------------------#
def cf_update_values(write):
# Load Domain Configuration file
cf_load()
# Load Domain Configuration file
cf_load()
# [DOMAIN]
# ========
global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no")
# [DOMAIN]
# ========
global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no")
cf_set_value("DOMAIN", "name", name)
cf_set_value("DOMAIN", "name", name)
title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","")
title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "")
if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","")
# Optional
global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# Optional
global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# [SERVER]
# ========
global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server")
if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server")
# [SERVER]
# ========
global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server")
if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name)
srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip)
wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www)
www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www)
# [WIP_DIRS]
# ==========
global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl)
# [WIP_DIRS]
# ==========
global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images)
wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files)
wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files)
# [WWW_DIRS]
# ==========
global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl)
# [WWW_DIRS]
# ==========
global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images)
www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files)
www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files)
# [WEBSITE]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
# [WEBSITE]
# =========
global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
www_url = cf_set_value("WEBSITE", "www_url", "")
if not www_url:
www_url = cf_set_value("WEBSITE", "www_url", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "")
if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang()
langs.load_website_lang()
lang = cf_set_value("WEBSITE", "lang", "")
if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang()
langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "")
if not css:
css = cf_set_value("WEBSITE", "css", "tyto")
css = cf_set_value("WEBSITE", "css", "")
if not css:
css = cf_set_value("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|")
sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no")
# [WEBSITE_MODULES]
# =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
# [WEBSITE_MODULES]
# =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit():
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
if not rss_items or not rss_items.isdigit():
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
if not rss_items or not rss_items.isdigit():
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "0")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
# TEMPLATE_FILENAMES
# ==================
global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS]
# ===========
cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_DIRS]
# ===========
cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES]
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
# [USER_TEMPLATE_FILES]
# =====================
global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES]
# ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
# [USER_MODULES_FILES]
# ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
# [WIP_FILES]
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon)
# [WIP_FILES]
# ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo)
wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles)
wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss)
wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats)
wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header)
wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar)
wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer)
wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer)
# [WWW_FILES]
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon)
# [WWW_FILES]
# ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo)
www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles)
www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss)
www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats)
www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats)
global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas)
global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header)
www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar)
www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar)
www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer)
www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer)
# [TYTO]
# ======
cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri)
# [TYTO]
# ======
cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri)
# ================================= #
# Write Configuration file #
# Only if needed or when new domain #
# --------------------------------- #
if new_val or write:
with open(cf_uri, "w") as f:
cf.write(f)
# ================================= #
# Write Configuration file #
# Only if needed or when new domain #
# --------------------------------- #
if new_val or write:
with open(cf_uri, "w") as f:
cf.write(f)
#=============================================#
# Update User local domain configuration file #
#---------------------------------------------#
ult_write = False
ult_cf_load()
if ult_cf.get("DOMAIN", "name") != name:
ult_cf.set("DOMAIN", "name", name)
ult_write = True
#=============================================#
# Update User local domain configuration file #
#---------------------------------------------#
ult_write = False
ult_cf_load()
if ult_cf.get("DOMAIN", "name") != name:
ult_cf.set("DOMAIN", "name", name)
ult_write = True
cf_hash_c = tools.get_filesum(cf_uri, True)
if ult_cf.get("DOMAIN", "hash") != cf_hash_c:
ult_cf.set("DOMAIN", "hash", cf_hash_c)
ult_write = True
cf_hash_c = tools.get_filesum(cf_uri, True)
if ult_cf.get("DOMAIN", "hash") != cf_hash_c:
ult_cf.set("DOMAIN", "hash", cf_hash_c)
ult_write = True
if ult_cf.get("DOMAIN", "root") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_dir)
ult_write = True
if ult_cf.get("DOMAIN", "root") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_dir)
ult_write = True
if ult_cf.get("DOMAIN", "conf") != cf_uri:
ult_cf.set("DOMAIN", "conf", cf_uri)
ult_write = True
if ult_cf.get("DOMAIN", "conf") != cf_uri:
ult_cf.set("DOMAIN", "conf", cf_uri)
ult_write = True
if ult_cf.get("SERVER", "root") != srv:
ult_cf.set("SERVER", "root", srv)
ult_write = True
if ult_cf.get("SERVER", "root") != srv:
ult_cf.set("SERVER", "root", srv)
ult_write = True
if ult_write:
with open(ult_cf_uri, "w") as f:
ult_cf.write(f)
if ult_write:
with open(ult_cf_uri, "w") as f:
ult_cf.write(f)
# Update User local Domains List File
#------------------------------------
ult_dlf_load()
dlf_write = False
try:
dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != wrk_dir:
dlf_write = True
except:
dlf_write = True
# Update User local Domains List File
#------------------------------------
ult_dlf_load()
dlf_write = False
try:
dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != wrk_dir:
dlf_write = True
except:
dlf_write = True
if dlf_write:
ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f)
if dlf_write:
ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f)
#========================================#
@ -552,19 +552,18 @@ def cf_update_values(write):
# if activated, check/create wrk dirs #
#----------------------------------------#
def userset_status(action):
do = {
do = {
"start" : "yes",
"stop" : "no"
}
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False)
ready()
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False)
ready()
if action == "start":
status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False)
if action == "start":
status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False)
#========================================#
@ -574,12 +573,12 @@ def userset_status(action):
# or check/create wrk directories #
#----------------------------------------#
def ready():
if not activated:
status = cf.get("DOMAIN", "activated")
debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True)
if not activated:
status = cf.get("DOMAIN", "activated")
debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True)
for key, directory in cf.items("USER_DIRS"):
tools.create_dirs(directory)
for key, directory in cf.items("USER_DIRS"):
tools.create_dirs(directory)
#======#=======================================================================
@ -590,10 +589,10 @@ def ready():
# Exit Tyto if in black hole... #
#-----------------------------------#
try:
user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~')
user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~')
except:
debug.out(2, "PWD", "?", True, 2, True)
debug.out(2, "PWD", "?", True, 2, True)
#======#

View File

@ -43,7 +43,7 @@ import debug, domain, langs, tools
# user interrupts... #
#--------------------#
def maybe_later(expected, answer):
debug.out(255, expected, answer, True, 0, True)
debug.out(255, expected, answer, True, 0, True)
#=========================#
@ -51,29 +51,29 @@ def maybe_later(expected, answer):
# yes_only : True / False #
#-------------------------#
def ask(q, yes_only, default):
expected = ""
if yes_only:
expected = langs.logs.ok
expected = ""
if yes_only:
expected = langs.logs.ok
try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
# return default answer if exists
if not answer:
if default:
return default
# return default answer if exists
if not answer:
if default:
return default
maybe_later(expected, "?")
maybe_later(expected, "?")
# Answer is a Y/N process
if yes_only:
for ok in langs.logs.ok:
if answer.lower() == ok.lower():
return True
# Answer is a Y/N process
if yes_only:
for ok in langs.logs.ok:
if answer.lower() == ok.lower():
return True
maybe_later(expected, answer)
maybe_later(expected, answer)
return answer
return answer
#====================================#
@ -81,11 +81,11 @@ def ask(q, yes_only, default):
# return value[0:12] #
#------------------------------------#
def shorter(value):
if len(value) > 12:
return '%s...'%(value[0:12])
if len(value) > 12:
return '%s...'%(value[0:12])
# Or legacy
return value
# Or legacy
return value
#=========================#
@ -93,8 +93,8 @@ def shorter(value):
# from directory basename #
# ------------------------#
def ask_domain_shortname(config_name):
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False)
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False)
#=======================#
@ -104,14 +104,14 @@ def ask_domain_shortname(config_name):
# - False: return value #
#-----------------------#
def ask_domain_title(update):
try: title = domain.cf.get("DOMAIN", "title")
except: title = ""
try: title = domain.cf.get("DOMAIN", "title")
except: title = ""
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title)
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer
#===========================#
@ -122,24 +122,24 @@ def ask_domain_title(update):
# - False: return value #
#---------------------------#
def ask_domain_date(update):
try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]"
try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]"
example = date
example = date
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date)
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date)
# Check date format (not valid date)
try:
parse(answer)
except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update)
return
# Check date format (not valid date)
try:
parse(answer)
except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update)
return
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer
#========================#
@ -149,14 +149,14 @@ def ask_domain_date(update):
# - False: return value #
#------------------------#
def ask_domain_about(update):
try: about = domain.cf.get("DOMAIN", "about")
except: about = ""
try: about = domain.cf.get("DOMAIN", "about")
except: about = ""
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about)
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer
#=======================#
@ -166,14 +166,14 @@ def ask_domain_about(update):
# - False: return value #
#-----------------------#
def ask_domain_mail(update):
try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = ""
try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = ""
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail)
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer
#===============================================#
@ -183,22 +183,22 @@ def ask_domain_mail(update):
# - False: return value #
#-----------------------------------------------#
def ask_domain_tags(update):
try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = ""
try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = ""
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags)
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags)
# Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",")
answer = ""
for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip()
if i != len(tuple_tags) - 1:
answer = answer + ","
# Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",")
answer = ""
for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip()
if i != len(tuple_tags) - 1:
answer = answer + ","
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer
#===================================#
@ -206,52 +206,52 @@ def ask_domain_tags(update):
# default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO
#-----------------------------------#
def ask_domain_lang(update):
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = ""
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = ""
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower()
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower()
# Lang Format is 2 character
if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False)
debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False)
answer = lang
# Lang Format is 2 character
if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False)
debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False)
answer = lang
# Check if translation file exists
if not langs.translation_exists("website", answer, False):
lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang
# Check if translation file exists
if not langs.translation_exists("website", answer, False):
lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang
#===================================#
# Get domain server root #
#-----------------------------------#
def ask_domain_server(update):
try:
srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False):
try:
srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False):
srv = ""
except:
srv = ""
except:
srv = ""
if srv and not tools.dir_exists(srv, False):
srv = ""
if srv and not tools.dir_exists(srv, False):
srv = ""
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
answer = ask(q, False, srv)
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
answer = ask(q, False, srv)
# Check if directory exists
if not tools.dir_exists(answer, False):
answer = ""
ask_domain_server(update)
return
# Check if directory exists
if not tools.dir_exists(answer, False):
answer = ""
ask_domain_server(update)
return
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer

View File

@ -40,4 +40,4 @@ import langs, debug
# Help Contents is in translations/logs_XX #
#------------------------------------------#
def show(action, target):
print(langs.logs.help_contents)
print(langs.logs.help_contents)

View File

@ -49,17 +49,20 @@ trfs = "/var/lib/tyto/translations/"
# return True or False #
#----------------------------------#
def translation_exists(module, lang, out):
global tr_file
global tr_file
modules = ("logs", "website")
if not module in modules: return # in case of internal typo error
modules = ("logs", "website")
# in case of internal typo error
if not module in modules:
print("! langs: internal error: 'logs', 'website'")
sys.exit(254)
tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file):
debug.out(5, lang, tr_file, True, 2, False)
return False
tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file):
debug.out(5, lang, tr_file, True, 2, False)
return False
return True
return True
#=============================================================================#
@ -70,33 +73,33 @@ def translation_exists(module, lang, out):
# Get system Lang to set logs #
#-----------------------------#
def get_sys_lang():
global lang, tr_logs_uri
global lang, tr_logs_uri
tr_logs_uri = "%slogs_%s.py"
tr_logs_uri = "%slogs_%s.py"
try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en"
try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en"
if not translation_exists("logs", lang, False):
lang = "en"
if not translation_exists("logs", lang, False):
lang = "en"
tr_logs_uri = tr_logs_uri%(trfs, lang)
tr_logs_uri = tr_logs_uri%(trfs, lang)
return lang
return lang
#===============================#
# Import logs lang file in logs #
#-------------------------------#
def load_logs_lang():
global logs, lang, set_logs
global logs, lang, set_logs
try:
set_logs
except:
logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True
try:
set_logs
except:
logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True
#=============================================================================#
@ -107,30 +110,31 @@ def load_logs_lang():
# Get website lang from cf to set site #
#---------------------------------------#
def get_website_lang():
global site_lang, tr_website_uri
global site_lang, tr_website_uri
tr_website_uri = "%swebsite_%s.py"
try: site_lang = domain.cf.get("WEBSITE", "lang")
except: site_lang = get_sys_lang()
tr_website_uri = "%swebsite_%s.py"
try: site_lang = domain.cf.get("WEBSITE", "lang")
except: site_lang = get_sys_lang()
if not translation_exists("website", site_lang, False):
site_lang = get_sys_lang() # or default "en"
if not translation_exists("website", site_lang, False):
site_lang = get_sys_lang() # or default "en"
tr_website_uri = tr_website_uri%(trfs, site_lang)
tr_website_uri = tr_website_uri%(trfs, site_lang)
return site_lang
return site_lang
#==================================#
# Import website lang file in site #
#----------------------------------#
def load_website_lang():
global site, site_lang, set_site
global site, site_lang, set_site
site = __import__("website_%s"%get_website_lang())
site = __import__("website_%s"%get_website_lang())
try:
set_site
except:
debug.out(208, site_lang, tr_website_uri, False, 0, False)
set_site = True
try:
set_site
except:
debug.out(208, site_lang, tr_website_uri, False, 0, False)
set_site = True

View File

@ -40,11 +40,11 @@ import args, domain
# Specific to action "new" #
#------------------------------------#
def manage(action, target):
do = {
"domain" : create_domain,
}
do = {
"domain" : create_domain,
}
do[target]()
do[target]()
@ -54,8 +54,8 @@ def manage(action, target):
# or if user "force" option
#-----------------------------------#
def create_domain():
if not domain.cf_exists() or args.force:
domain.cf_create()
return
if not domain.cf_exists() or args.force:
domain.cf_create()
return

View File

@ -46,43 +46,43 @@ error = 0
# load database #
#--------------------------------------------#
def is_article(target):
# User MUST be in articles/
domain.user_dir.startswith(domain.wrk_articles) or \
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
# User MUST be in articles/
domain.user_dir.startswith(domain.wrk_articles) or \
debug.out(2, "-> articles/", domain.wrk_articles, True, 2, True)
# Target URI most be from legacy directory or not begins with
if target.startswith(tyto.notarget):
error = debug.out(20, "./, ../", target, True, 2, False)
return False
# Target URI most be from legacy directory or not begins with
if target.startswith(tyto.notarget):
error = debug.out(20, "./, ../", target, True, 2, False)
return False
# Article exists
global uri
uri = os.path.join(domain.wrk_articles, target)
if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False)
return False
# Article exists
global uri
uri = os.path.join(domain.wrk_articles, target)
if not os.path.exists(uri):
error = debug.out(5, "False", uri, True, 2, False)
return False
# Article is a Tyto format and not empty (exit on errors)
if not is_tyto_format():
return False
# Article is a Tyto format and not empty (exit on errors)
if not is_tyto_format():
return False
global uri_id, wrk_id, cf_uri, wrk_target
# Set post ID from...
uri_id = tools.get_filesum(uri, False) # ...URI
wrk_id = tools.get_filesum(uri, True) # ...CONTENTS
global uri_id, wrk_id, cf_uri, wrk_target
# Set post ID from...
uri_id = tools.get_filesum(uri, False) # ...URI
wrk_id = tools.get_filesum(uri, True) # ...CONTENTS
# Set post configuration file database
cf_uri = os.path.join(domain.wrk_db, uri_id + ".ini")
# Set post configuration file database
cf_uri = os.path.join(domain.wrk_db, uri_id + ".ini")
# Set target from articles/
wrk_target = uri.rsplit(domain.wrk_articles)[1]
# Set target from articles/
wrk_target = uri.rsplit(domain.wrk_articles)[1]
# Load Database
global db
db = False
db = cf_load() # True or False
# Load Database
global db
db = False
db = cf_load() # True or False
return True
return True
#=========================================#
@ -90,33 +90,33 @@ def is_article(target):
# Return True or False #
#-----------------------------------------#
def is_tyto_format():
global head_contents, text_contents, contents
global head_lines, text_lines, lines
global head_contents, text_contents, contents
global head_lines, text_lines, lines
head_contents = text_contents = ""
head_contents = text_contents = ""
with open(uri, "r") as contents:
contents = contents.read()
try:
head_contents = contents.rsplit(sep)[0]
text_contents = contents.rsplit(sep)[1]
except:
error = debug.out(21, sep, uri, True, 2, False)
with open(uri, "r") as contents:
contents = contents.read()
try:
head_contents = contents.rsplit(sep)[0]
text_contents = contents.rsplit(sep)[1]
except:
error = debug.out(21, sep, uri, True, 2, False)
return False
if not head_contents:
error = debug.out(22, "?", uri, True, 2, False)
return False
if not head_contents:
error = debug.out(22, "?", uri, True, 2, False)
return False
if not text_contents:
error = debug.out(23, "?", uri, True, 2, False)
return False
if not text_contents:
error = debug.out(23, "?", uri, True, 2, False)
return False
lines = len(contents.splitlines())
head_lines = len(head_contents.splitlines())
text_lines = len(text_contents.splitlines())
lines = len(contents.splitlines())
head_lines = len(head_contents.splitlines())
text_lines = len(text_contents.splitlines())
return True
return True
#=======================================#
@ -124,32 +124,58 @@ def is_tyto_format():
# return True, or False if unused (yet) #
#---------------------------------------#
def cf_load():
global cf
cf = False
global cf
cf = False
if not os.path.exists(cf_uri):
tools.create_file(cf_uri, ini_template)
os.path.exists(cf_uri) or tools.create_file(cf_uri, ini_template)
cf = configparser.ConfigParser()
cf.read(cf_uri)
cf = configparser.ConfigParser()
cf.read(cf_uri)
return True
return True
#====================================================#
# Check if post database configuration file is valid #
#----------------------------------------------------#
def cf_valid():
global chk_hash, wip_hash, www_hash
global chk_hash, wip_hash, www_hash
chk_hash = cf.get("CHECK", "hash")
wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash")
chk_hash = cf.get("CHECK", "hash")
wip_hash = cf.get("WIP", "hash")
www_hash = cf.get("WWW", "hash")
#======#
# MAIN #=======================================================================
#======#
# Statistics
# ==========
stats_tyto_head_coms = 0
stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_quotes = 0
stats_parags = 0
stats_links = 0
stats_images = 0
stats_files = 0
stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_codes = 0
stats_raws = 0
stats_total_files = 0
stats_text_links = 0
stats_text_files = 0
stats_text_images = 0
stats_text_abbrs = 0
stats_text_codes = 0
stats_text_raws = 0
# head_contents
#==============
@ -170,16 +196,26 @@ author = ("author:", False)
logo = ("logo:", False)
# Multiple lines (3)
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_marks = {
"link:" : "__",
"file:" : "--",
"image:" : "_image:",
"abbr:" : "::"
}
ml_tags = ("link:", "image:", "file:", "raw:", "code:", "abbr:")
ml_tags_marks = {
"link:" : "__",
"file:" : "--",
"image:" : "_image:",
"abbr:" : "::",
"raw:" : "_raw:",
"code:" : "_code:"
}
ml_tags_stats = {
"link:" : stats_links,
"file:" : stats_files,
"image:" : stats_images,
"abbr:" : stats_abbrs,
"raw:" : stats_raws,
"code:" : stats_codes,
}
# Markers with uri in value2
value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3])
value2s_uri = (ml_tags[1], ml_tags[2], ml_tags[3], ml_tags[4])
value2s_ext_uris = ("http", "ftp")
# text_contents
@ -194,41 +230,17 @@ raw_contents = ("bcodes", "quotes")
# Comments
text_comments = (";;", "<!--")
html_comment = { text_comments[0] : "<!-- %s -->" }
# Tyto Titles #1 = <h2>
tyto_titles = ("#1", "#2", "#3", "#4", "#5")
html_titles = {
"#1" : '<h2 class="title_2">%s</h62>',
"#2" : '<h3 class="title_3">%s</h3>',
"#3" : '<h4 class="title_4">%s</h4>',
"#4" : '<h5 class="title_5">%s</h5>',
"#5" : '<h6 class="title_6">%s</h6>',
"#1" : '<h2 class="%s">%s</h2>',
"#2" : '<h3 class="%s">%s</h3>',
"#3" : '<h4 class="%s">%s</h4>',
"#4" : '<h5 class="%s">%s</h5>',
"#5" : '<h6 class="%s">%s</h6>',
}
# Statistics
# ==========
stats_tyto_head_coms = 0
stats_tyto_text_coms = 0
stats_html_coms = 0
stats_titles = 0
stats_bcodes = 0
stats_quotes = 0
stats_parags = 0
stats_links = 0
stats_images = 0
stats_files = 0
stats_raws = 0
stats_codes = 0
stats_abbrs = 0
stats_total_files = 0
stats_text_links = 0
stats_text_files = 0
stats_text_images = 0
stats_text_abbrs = 0
#=============================#
# articles configuration file #
@ -245,6 +257,10 @@ ini_template = """[DOMAIN]
[WWW]
[COMMENTS]
[TITLES]
[LINKS]
[FILES]
@ -264,5 +280,4 @@ ini_template = """[DOMAIN]
[STATS_HEADERS]
[STATS_TEXTS]
"""

View File

@ -41,25 +41,25 @@ import domain, debug
# Specific to action "show" #
#------------------------------------#
def manage(action, target):
do = {
"domains": all_domains,
}
do = {
"domains": all_domains,
}
do[target]()
do[target]()
#============================#
# List all registred domains #
#----------------------------#
def all_domains():
domain.ult_dlf_load()
try:
c = 0
for key, value in domain.ult_dlf.items("DOMAINS"):
if key: c += 1
print(": %s > %s"%(key,value))
print("|\n; total =",c)
domain.ult_dlf_load()
try:
c = 0
for key, value in domain.ult_dlf.items("DOMAINS"):
if key: c += 1
print(": %s > %s"%(key,value))
print("|\n; total =",c)
except:
debug.out(104, "False", domain.ult_dlf_uri, True, 1, False)
except:
debug.out(104, "False", domain.ult_dlf_uri, True, 1, False)

View File

@ -33,7 +33,7 @@
#--------------------------
from hashlib import blake2b
import sys, os, configparser, datetime, time
import sys, os, configparser, datetime, time, base64
import debug, domain
@ -41,17 +41,17 @@ import debug, domain
#
#
def exit(targets, error):
if targets: return
if targets: return
sys.exit(error)
sys.exit(error)
#==============================#
# Set and return date and time #
#------------------------------#
def nowdate():
now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S'))
now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S'))
#
@ -59,18 +59,18 @@ def nowdate():
# Return date (only year) for post database
#
def local_date(date):
date = date.rsplit(" ")[0] # if nowdate()
date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0]
month = date.rsplit("-")[1]
day = date.rsplit("-")[2]
year = date.rsplit("-")[0]
month = date.rsplit("-")[1]
day = date.rsplit("-")[2]
dates = {
"fr" : "%s/%s/%s"%(day, month, year),
"en" : date,
}
dates = {
"fr" : "%s/%s/%s"%(day, month, year),
"en" : date,
}
return dates[domain.lang]
return dates[domain.lang]
#========================#
@ -79,12 +79,12 @@ def local_date(date):
# False = URI #
#------------------------#
def get_filesum(path, src):
file_sum = blake2b(digest_size=4)
file_sum = blake2b(digest_size=4)
if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode())
if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode())
return file_sum.hexdigest()
return file_sum.hexdigest()
#========================================#
@ -92,66 +92,102 @@ def get_filesum(path, src):
# Mainly used to check domain server dir #
#----------------------------------------#
def dir_exists(dir_path, out):
if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out)
return False
if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out)
return False
return True
return True
#====================#
# Create directories #
#--------------------#
def create_dirs(path):
try:
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
debug.out(203, "True", path, False, 0, False)
except:
# Exit if not created
debug.out(5, "False", path, True, 2, True)
try:
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
debug.out(203, "True", path, False, 0, False)
except:
# Exit if not created
debug.out(5, "False", path, True, 2, True)
#============================#
# Create a new file and logs #
#----------------------------#
def create_file(file_path, contents):
up = bool(os.path.exists(file_path))
up = bool(os.path.exists(file_path))
try:
with open(file_path, "w") as f:
f.write(contents)
except:
# Exit at error
debug.out(7, "False", file_path, True, 2, True)
try:
with open(file_path, "w") as f:
f.write(contents)
except:
# Exit at error
debug.out(7, "False", file_path, True, 2, True)
# log "update" or "new"
file_name = os.path.basename(file_path)
if up: debug.out(207, file_name, file_path, False, 0, False)
else: debug.out(206, file_name, file_path, False, 0, False)
# log "update" or "new"
file_name = os.path.basename(file_path)
if up: debug.out(207, file_name, file_path, False, 0, False)
else: debug.out(206, file_name, file_path, False, 0, False)
#===========================================#
# Update ini file, replacing existing value #
#-------------------------------------------#
def update_ini_file(file_path, section, key, val):
# Exit if no file
if not os.path.exists(file_path):
debug.out(5, "False", file_path, True, 2, True)
# Exit if no file
if not os.path.exists(file_path):
debug.out(5, "False", file_path, True, 2, True)
# Load ini file
config = configparser.ConfigParser()
config.read(file_path)
# Load ini file
config = configparser.ConfigParser()
config.read(file_path)
# New value is same as registred
try:
if config.get(section, key) == val:
return
except:
config.add_section(section)
# New value is same as registred
try:
if config.get(section, key) == val:
return
except:
config.add_section(section)
# Update file with new value
config.set(section, key, val)
with open(file_path, "w") as f:
config.write(f)
# Update file with new value
config.set(section, key, val)
with open(file_path, "w") as f:
config.write(f)
#====================#
# Base64 Convertions #
#--------------------#
def b64_convert(action, content):
if action == 'encode':
global b64_content
b64_base64 = ''
content_bytes = content.encode("utf8")
base64_bytes = base64.b64encode(content_bytes)
b64_content = base64_bytes.decode("utf8")
return b64_content
elif action == 'decode':
global src_content
src_content = ''
content_bytes = content.encode("utf8")
base64_bytes = base64.b64decode(content_bytes)
src_content = base64_bytes.decode("utf8")
return src_content
#================================#
# Convert html sign in string #
# used to deactivate HTML markup #
# Return new string #
#--------------------------------#
def convert_html_signs(string):
string = string.replace('<', '&lt;')
string = string.replace('>', '&gt;')
astring = string.replace('"', '&quot;')
string = string.replace("'", '&apos;')
return string

View File

@ -93,3 +93,14 @@ ini_domains_list = """[DOMAINS]
# Put here values where posts target cannot begin with
notarget = ("./", "../")
#======#
# HTML #=======================================================================
#======#
pre_bcode = """<pre class="%s_blockcode">
<code class="%s_blockcode">
<ol class="%s_blockcode">
%s
</ol>
</code>
</pre>"""

View File

@ -40,22 +40,21 @@ import langs, forms, domain
# Specific to action "set #
#------------------------------------#
def manage(action, target):
# Load or Exit if no configuration
domain.cf_load()
# Load or Exit if no configuration
domain.cf_load()
if action == "set":
do = {
"title" : forms.ask_domain_title,
"date" : forms.ask_domain_date,
"about" : forms.ask_domain_about,
"mail" : forms.ask_domain_mail,
"lang" : forms.ask_domain_lang,
"server" : forms.ask_domain_server,
}
if action == "set":
do = {
"title" : forms.ask_domain_title,
"date" : forms.ask_domain_date,
"about" : forms.ask_domain_about,
"mail" : forms.ask_domain_mail,
"lang" : forms.ask_domain_lang,
"server" : forms.ask_domain_server,
}
do[target](True)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)
do[target](True)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)