[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 ! # 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] ## [1.9.20]
- working on 'check' process - working on 'check' process
- - updated 'logo:' process - - updated 'logo:' process

View File

@ -9,6 +9,11 @@ tyto
## ToDo next (working on) ## ToDo next (working on)
- 'check' action processes - '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 ! - Translate logs in english !

View File

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

View File

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

View File

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

View File

@ -47,32 +47,32 @@ import langs, args
# stop to sys exit with nbr if True # # stop to sys exit with nbr if True #
#-----------------------------------# #-----------------------------------#
def out(nbr, var, val, show, color, stop): def out(nbr, var, val, show, color, stop):
args.get_options() args.get_options()
if not show: if not show:
# Show only warn and error logs # Show only warn and error logs
show = args.dlogs or args.erron and color > 0 show = args.dlogs or args.erron and color > 0
if not show: if not show:
return nbr return nbr
# COlors # COlors
CS = '\033[0;0m' # Unset CS = '\033[0;0m' # Unset
CL = '\033[0;2m' # Gray CL = '\033[0;2m' # Gray
CB = '\033[1;34m' # Blue CB = '\033[1;34m' # Blue
CC = '\033[1;36m' # Cyan CC = '\033[1;36m' # Cyan
CR = '\033[1;31m' # Red CR = '\033[1;31m' # Red
CG = '\033[1;32m' # Green CG = '\033[1;32m' # Green
CY = '\033[1;33m' # Yellow CY = '\033[1;33m' # Yellow
CP = '\033[1;35m' # Pink CP = '\033[1;35m' # Pink
# Color of "*" # Color of "*"
SC = CL # Default gray SC = CL # Default gray
if color == 0: SC = CG if color == 0: SC = CG
elif color == 1: SC = CY elif color == 1: SC = CY
elif color == 2: SC = CR elif color == 2: SC = CR
# Messages for logs # Messages for logs
messages = \ messages = \
{ {
# ERRORS (1-100) # ERRORS (1-100)
1 : langs.logs.err_arg, 1 : langs.logs.err_arg,
@ -117,21 +117,20 @@ def out(nbr, var, val, show, color, stop):
} }
# Print, acoording to parameters # Print, acoording to parameters
print("%s*%s %s%s%s > %s%s%s < %s%s%s"%( print("%s*%s %s%s%s > %s%s%s < %s%s%s"%(
SC, CS, SC, CS,
CL, messages[nbr], CS, CL, messages[nbr], CS,
CB, var, CS, CB, var, CS,
CC, val, CS CC, val, CS
) )
) )
# Exit if stop = True # Exit if stop = True
if stop: if stop:
if nbr >= 200: if nbr >= 200: nbr = 0
nbr = 0 sys.exit(nbr)
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 # # Exit if directory name is compatible with a domain name #
#---------------------------------------------------------# #---------------------------------------------------------#
def compatible_name(): def compatible_name():
if len(name.rsplit(".")) <= 1: if len(name.rsplit(".")) <= 1:
debug.out(3, "abc.tld", name, True, 2, True) debug.out(3, "abc.tld", name, True, 2, True)
#================================# #================================#
@ -49,13 +49,13 @@ def compatible_name():
# As needed, exit if not exists # # As needed, exit if not exists #
#--------------------------------# #--------------------------------#
def cf_load(): def cf_load():
global cf global cf
cf_exists() or sys.exit(100) cf_exists() or sys.exit(100)
cf = False cf = False
cf = configparser.ConfigParser() cf = configparser.ConfigParser()
cf.read(cf_uri) cf.read(cf_uri)
#=====================================# #=====================================#
@ -63,29 +63,29 @@ def cf_load():
# As needed, exit if not exists # # As needed, exit if not exists #
#-------------------------------------# #-------------------------------------#
def ult_cf_load(): def ult_cf_load():
global ult_cf global ult_cf
ult_cf = False ult_cf = False
if not os.path.exists(ult_cf_uri): if not os.path.exists(ult_cf_uri):
tools.create_file(ult_cf_uri, tyto.ini_domain_user) tools.create_file(ult_cf_uri, tyto.ini_domain_user)
ult_cf = configparser.ConfigParser() ult_cf = configparser.ConfigParser()
ult_cf.read(ult_cf_uri) ult_cf.read(ult_cf_uri)
#===================================# #===================================#
# Load User local Domains List File # # Load User local Domains List File #
#-----------------------------------# #-----------------------------------#
def ult_dlf_load(): def ult_dlf_load():
global ult_dlf global ult_dlf
# User Domains list file # User Domains list file
ult_dlf = False ult_dlf = False
if not os.path.exists(ult_dlf_uri): if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list) tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
ult_dlf = configparser.ConfigParser() ult_dlf = configparser.ConfigParser()
ult_dlf.read(ult_dlf_uri) ult_dlf.read(ult_dlf_uri)
#===========================================# #===========================================#
@ -94,36 +94,36 @@ def ult_dlf_load():
# return True or False # return True or False
#-------------------------------------------# #-------------------------------------------#
def cf_exists(): def cf_exists():
global shown_ok, shown_no global shown_ok, shown_no
if os.path.exists(cf_uri): if os.path.exists(cf_uri):
try: shown_ok try: shown_ok
except: debug.out(202, name, cf_uri, False, 0, False) except: debug.out(202, name, cf_uri, False, 0, False)
shown_ok = True shown_ok = True
return True return True
else: else:
try: shown_no try: shown_no
except: debug.out(104, "False", cf_uri, True, 1, False) except: debug.out(104, "False", cf_uri, True, 1, False)
shown_no = True shown_no = True
compatible_name() compatible_name()
return False return False
#=========================================# #=========================================#
# Guess and return wip_url from name # # Guess and return wip_url from name #
#-----------------------------------------# #-----------------------------------------#
def create_wip_url(): def create_wip_url():
www_url = "https://www-wip.%s/" www_url = "https://www-wip.%s/"
len_cn = name.count(".") len_cn = name.count(".")
# Domain name Format: a.b # Domain name Format: a.b
if len_cn == 1: if len_cn == 1:
return www_url%name return www_url%name
# Domain name format: (at least) a.b.c # Domain name format: (at least) a.b.c
len_cn = len(name.rsplit(".")[0]) + 1 len_cn = len(name.rsplit(".")[0]) + 1
tld = name[len_cn:] tld = name[len_cn:]
return www_url%tld return www_url%tld
#==========================================# #==========================================#
@ -134,41 +134,41 @@ def create_wip_url():
# If not User domains list file, create it # # If not User domains list file, create it #
#------------------------------------------# #------------------------------------------#
def cf_create(): def cf_create():
compatible_name() compatible_name()
# This fonction is only called with "new domain" argument # This fonction is only called with "new domain" argument
# If a conf already exists, show important RESET log # If a conf already exists, show important RESET log
if cf_exists(): if cf_exists():
debug.out(102, "!?", cf_uri, True, 1, False) debug.out(102, "!?", cf_uri, True, 1, False)
# Ask User to create new domain. Will exit if not ok. # Ask User to create new domain. Will exit if not ok.
forms.ask_domain_shortname(name) forms.ask_domain_shortname(name)
# Create default files # Create default files
tools.create_file(cf_uri, ini_template%name) tools.create_file(cf_uri, ini_template%name)
tools.create_dirs(ult_dir) tools.create_dirs(ult_dir)
tools.create_file(ult_cf_uri, tyto.ini_domain_user) tools.create_file(ult_cf_uri, tyto.ini_domain_user)
# User Domains list file # User Domains list file
if not os.path.exists(ult_dlf_uri): if not os.path.exists(ult_dlf_uri):
tools.create_file(ult_dlf_uri, tyto.ini_domains_list) tools.create_file(ult_dlf_uri, tyto.ini_domains_list)
# Ask user for domain settings # Ask user for domain settings
cf_load() cf_load()
forms.ask_domain_title(True) forms.ask_domain_title(True)
forms.ask_domain_date(True) forms.ask_domain_date(True)
forms.ask_domain_about(True) forms.ask_domain_about(True)
forms.ask_domain_mail(True) forms.ask_domain_mail(True)
forms.ask_domain_tags(True) forms.ask_domain_tags(True)
# Set default lang, from config file or system lang # Set default lang, from config file or system lang
forms.ask_domain_lang(True) forms.ask_domain_lang(True)
# Set server directory # Set server directory
forms.ask_domain_server(True) forms.ask_domain_server(True)
# Update Domain Configuration file # Update Domain Configuration file
cf_update_values(True) cf_update_values(True)
@ -179,35 +179,35 @@ def cf_create():
# Ask yser when default is a key form and not value # # Ask yser when default is a key form and not value #
#---------------------------------------------------# #---------------------------------------------------#
def cf_set_value(section, key, default): def cf_set_value(section, key, default):
global new_val global new_val
try: new_val try: new_val
except: new_val = False except: new_val = False
try: try:
val = cf.get(section, key) val = cf.get(section, key)
except: except:
try: cf.add_section(section) ; new_val = True try: cf.add_section(section) ; new_val = True
except: pass except: pass
val = "" val = ""
# Values has a form # Values has a form
if default in tyto.keys_4q: if default in tyto.keys_4q:
if val: return val if val: return val
else: default = tyto.keys_questions[default](False) ; new_val = True else: default = tyto.keys_questions[default](False) ; new_val = True
# Optional key # Optional key
elif not default: elif not default:
if not val: return default if not val: return default
else: default = val else: default = val
# Force set default value # Force set default value
if val != default: if val != default:
new_val = True new_val = True
cf.set(section, key, default) cf.set(section, key, default)
debug.out(204, "[%s] %s"%(section, key), default, False, 0, False) 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 # # Ensure to set correct values #
#-------------------------------------------# #-------------------------------------------#
def cf_update_values(write): def cf_update_values(write):
# Load Domain Configuration file # Load Domain Configuration file
cf_load() cf_load()
# [DOMAIN] # [DOMAIN]
# ======== # ========
global activated, title, date, about, mail, tags, license, license_url global activated, title, date, about, mail, tags, license, license_url
try: activated = cf.getboolean("DOMAIN", "activated") try: activated = cf.getboolean("DOMAIN", "activated")
except: activated = cf_set_value("DOMAIN", "activated", "no") 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") title = cf_set_value("DOMAIN", "title", "title")
date = cf_set_value("DOMAIN", "date", "date") date = cf_set_value("DOMAIN", "date", "date")
about = cf_set_value("DOMAIN", "about", "about") about = cf_set_value("DOMAIN", "about", "about")
mail = cf_set_value("DOMAIN", "mail", "mail") mail = cf_set_value("DOMAIN", "mail", "mail")
tags = cf_set_value("DOMAIN", "tags", "tags") tags = cf_set_value("DOMAIN", "tags", "tags")
license = cf_set_value("DOMAIN", "lincese", "") license = cf_set_value("DOMAIN", "lincese", "")
if not license: if not license:
license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3") license = cf_set_value("DOMAIN", "lincese", "gfdl-1.3")
license_url = cf_set_value("DOMAIN", "lincese_url", license_url = cf_set_value("DOMAIN", "lincese_url",
"https://www.gnu.org/licenses/fdl-1.3.txt") "https://www.gnu.org/licenses/fdl-1.3.txt")
elif not license == "gfdl-1.3": elif not license == "gfdl-1.3":
license_url = cf_set_value("DOMAIN", "lincese_url","") license_url = cf_set_value("DOMAIN", "lincese_url","")
# Optional # Optional
global legals_url, terms_url, statuses_url global legals_url, terms_url, statuses_url
legals_url = cf_set_value("DOMAIN", "legals_url", "") legals_url = cf_set_value("DOMAIN", "legals_url", "")
terms_url = cf_set_value("DOMAIN", "terms_url", "") terms_url = cf_set_value("DOMAIN", "terms_url", "")
statuses_url = cf_set_value("DOMAIN", "statuses_url", "") statuses_url = cf_set_value("DOMAIN", "statuses_url", "")
# [SERVER] # [SERVER]
# ======== # ========
global srv, srv_name, wip, www global srv, srv_name, wip, www
srv = cf_set_value("SERVER", "root", "server") srv = cf_set_value("SERVER", "root", "server")
if not tools.dir_exists(srv, False): if not tools.dir_exists(srv, False):
srv = cf_set_value("SERVER", "root", "server") srv = cf_set_value("SERVER", "root", "server")
srv_name = os.path.join(srv, name + "/") srv_name = os.path.join(srv, name + "/")
cf_set_value("SERVER", "domain", srv_name) cf_set_value("SERVER", "domain", srv_name)
wip = os.path.join(srv_name, "wip/") wip = os.path.join(srv_name, "wip/")
cf_set_value("SERVER", "wip", wip) cf_set_value("SERVER", "wip", wip)
www = os.path.join(srv_name, "www/") www = os.path.join(srv_name, "www/")
cf_set_value("SERVER", "www", www) cf_set_value("SERVER", "www", www)
# [WIP_DIRS] # [WIP_DIRS]
# ========== # ==========
global wip_tpl, wip_images, wip_files global wip_tpl, wip_images, wip_files
wip_tpl = os.path.join(wip, "template/") wip_tpl = os.path.join(wip, "template/")
cf_set_value("WIP_DIRS", "template", wip_tpl) cf_set_value("WIP_DIRS", "template", wip_tpl)
wip_images = os.path.join(wip, "images/") wip_images = os.path.join(wip, "images/")
cf_set_value("WIP_DIRS", "images", wip_images) cf_set_value("WIP_DIRS", "images", wip_images)
wip_files = os.path.join(wip, "files/") wip_files = os.path.join(wip, "files/")
cf_set_value("WIP_DIRS", "files", wip_files) cf_set_value("WIP_DIRS", "files", wip_files)
# [WWW_DIRS] # [WWW_DIRS]
# ========== # ==========
global www_tpl, www_images, www_files global www_tpl, www_images, www_files
www_tpl = os.path.join(www, "template/") www_tpl = os.path.join(www, "template/")
cf_set_value("WWW_DIRS", "template", www_tpl) cf_set_value("WWW_DIRS", "template", www_tpl)
www_images = os.path.join(www, "images/") www_images = os.path.join(www, "images/")
cf_set_value("WWW_DIRS", "images", www_images) cf_set_value("WWW_DIRS", "images", www_images)
www_files = os.path.join(www, "files/") www_files = os.path.join(www, "files/")
cf_set_value("WWW_DIRS", "files", www_files) cf_set_value("WWW_DIRS", "files", www_files)
# [WEBSITE] # [WEBSITE]
# ========= # =========
global wip_url, www_url, lang, css, sep, article_code, static global wip_url, www_url, lang, css, sep, article_code, static
wip_url = cf_set_value("WEBSITE", "wip_url", "") wip_url = cf_set_value("WEBSITE", "wip_url", "")
if not wip_url: if not wip_url:
wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url()) wip_url = cf_set_value("WEBSITE", "wip_url", create_wip_url())
www_url = cf_set_value("WEBSITE", "www_url", "") www_url = cf_set_value("WEBSITE", "www_url", "")
if not 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", "https://%s/"%name)
lang = cf_set_value("WEBSITE", "lang", "") lang = cf_set_value("WEBSITE", "lang", "")
if not lang: if not lang:
lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang()) lang = cf_set_value("WEBSITE", "lang", langs.load_website_lang())
elif not langs.translation_exists("website", lang, False): elif not langs.translation_exists("website", lang, False):
lang = langs.get_sys_lang() lang = langs.get_sys_lang()
langs.load_website_lang() langs.load_website_lang()
css = cf_set_value("WEBSITE", "css", "") css = cf_set_value("WEBSITE", "css", "")
if not css: if not css:
css = cf_set_value("WEBSITE", "css", "tyto") css = cf_set_value("WEBSITE", "css", "tyto")
sep = cf_set_value("WEBSITE", "separator", "") sep = cf_set_value("WEBSITE", "separator", "")
if not sep or len(sep) > 2: if not sep or len(sep) > 2:
sep = cf_set_value("WEBSITE", "separator", "|") sep = cf_set_value("WEBSITE", "separator", "|")
try: article_code = cf.getboolean("WEBSITE", "article_code") try: article_code = cf.getboolean("WEBSITE", "article_code")
except: article_code = cf_set_value("WEBSITE", "article_code", "yes") except: article_code = cf_set_value("WEBSITE", "article_code", "yes")
try: static = cf.getboolean("WEBSITE", "static") try: static = cf.getboolean("WEBSITE", "static")
except: static = cf_set_value("WEBSITE", "static", "no") except: static = cf_set_value("WEBSITE", "static", "no")
# [WEBSITE_MODULES] # [WEBSITE_MODULES]
# ================= # =================
global navbar, sidebar_title, sidebar_items, rss_items, sitemaps global navbar, sidebar_title, sidebar_items, rss_items, sitemaps
try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar") try: navbar = cf.getboolean("WEBSITE_MODULES", "navbar")
except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes") except: navbar = cf_set_value("WEBSITE_MODULES", "navbar", "yes")
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "") sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", "")
if not sidebar_title: if not sidebar_title:
sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title", sidebar_title = cf_set_value("WEBSITE_MODULES", "sidebar_title",
langs.site.sidebar_title) langs.site.sidebar_title)
sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "") sidebar_items = cf_set_value("WEBSITE_MODULES", "sidebar_items", "")
if not sidebar_items or not sidebar_items.isdigit(): 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", "0")
rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "") rss_items = cf_set_value("WEBSITE_MODULES", "rss_items", "")
if not rss_items or not rss_items.isdigit(): 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", "0")
try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps") try: sitemaps = cf.getboolean("WEBSITE_MODULES", "sitemaps")
except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes") except: sitemaps = cf_set_value("WEBSITE_MODULES", "sitemaps", "yes")
# TEMPLATE_FILENAMES # TEMPLATE_FILENAMES
# ================== # ==================
global favicon, logo, styles, rss, stats global favicon, logo, styles, rss, stats
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "")
if not favicon: if not favicon:
favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png") favicon = cf_set_value("TEMPLATE_FILENAMES", "favicon", "favicon.png")
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "") logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "")
if not logo: if not logo:
logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png") logo = cf_set_value("TEMPLATE_FILENAMES", "logo", "logo.png")
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "") styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "")
if not styles: if not styles:
styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css") styles = cf_set_value("TEMPLATE_FILENAMES", "styles", "styles.css")
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "") rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "")
if not rss: if not rss:
rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml") rss = cf_set_value("TEMPLATE_FILENAMES", "rss", "rss.xml")
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "") stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "")
if not stats: if not stats:
stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini") stats = cf_set_value("TEMPLATE_FILENAMES", "stats", "tyto_stats.ini")
# [USER_DIRS] # [USER_DIRS]
# =========== # ===========
cf_set_value("USER_DIRS", "root", wrk_dir) cf_set_value("USER_DIRS", "root", wrk_dir)
cf_set_value("USER_DIRS", "articles", wrk_articles) cf_set_value("USER_DIRS", "articles", wrk_articles)
cf_set_value("USER_DIRS", "images", wrk_images) cf_set_value("USER_DIRS", "images", wrk_images)
cf_set_value("USER_DIRS", "files", wrk_files) cf_set_value("USER_DIRS", "files", wrk_files)
cf_set_value("USER_DIRS", "template", wrk_tpl) cf_set_value("USER_DIRS", "template", wrk_tpl)
cf_set_value("USER_DIRS", "modules", wrk_mods) cf_set_value("USER_DIRS", "modules", wrk_mods)
cf_set_value("USER_DIRS", "database", wrk_db) cf_set_value("USER_DIRS", "database", wrk_db)
# [USER_TEMPLATE_FILES] # [USER_TEMPLATE_FILES]
# ===================== # =====================
global wrk_favicon, wrk_logo, wri_styles global wrk_favicon, wrk_logo, wri_styles
wrk_favicon = os.path.join(wrk_tpl, favicon) wrk_favicon = os.path.join(wrk_tpl, favicon)
cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon) cf_set_value("USER_TEMPLATE_FILES", "favicon", wrk_favicon)
wrk_logo = os.path.join(wrk_tpl, logo) wrk_logo = os.path.join(wrk_tpl, logo)
cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo) cf_set_value("USER_TEMPLATE_FILES", "logo", wrk_logo)
wrk_styles = os.path.join(wrk_tpl, styles) wrk_styles = os.path.join(wrk_tpl, styles)
cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles) cf_set_value("USER_TEMPLATE_FILES", "styles", wrk_styles)
# [USER_MODULES_FILES] # [USER_MODULES_FILES]
# ==================== # ====================
global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer global wrk_metas, wrk_header, wrk_navbar, wrk_sidebar, wrk_footer
wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw") wrk_metas = os.path.join(wrk_mods, "tyto_metas.raw")
cf_set_value("USER_MODULES_FILES", "metas", wrk_metas) cf_set_value("USER_MODULES_FILES", "metas", wrk_metas)
wrk_header = os.path.join(wrk_mods, "tyto_header.raw") wrk_header = os.path.join(wrk_mods, "tyto_header.raw")
cf_set_value("USER_MODULES_FILES", "header", wrk_header) cf_set_value("USER_MODULES_FILES", "header", wrk_header)
wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw") wrk_navbar = os.path.join(wrk_mods, "tyto_navbar.raw")
cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar) cf_set_value("USER_MODULES_FILES", "navbar", wrk_navbar)
wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw") wrk_sidebar = os.path.join(wrk_mods, "tyto_sidebar.raw")
cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar) cf_set_value("USER_MODULES_FILES", "sidebar", wrk_sidebar)
wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw") wrk_footer = os.path.join(wrk_mods, "tyto_footer.raw")
cf_set_value("USER_MODULES_FILES", "footer", wrk_footer) cf_set_value("USER_MODULES_FILES", "footer", wrk_footer)
# [WIP_FILES] # [WIP_FILES]
# =========== # ===========
global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats global wip_favicon, wip_logo, wip_styles, wip_rss, wip_stats
wip_favicon = os.path.join(wip_tpl, favicon) wip_favicon = os.path.join(wip_tpl, favicon)
cf_set_value("WIP_FILES", "favicon", wip_favicon) cf_set_value("WIP_FILES", "favicon", wip_favicon)
wip_logo = os.path.join(wip_tpl, logo) wip_logo = os.path.join(wip_tpl, logo)
cf_set_value("WIP_FILES", "logo", wip_logo) cf_set_value("WIP_FILES", "logo", wip_logo)
wip_styles = os.path.join(wip_tpl, styles) wip_styles = os.path.join(wip_tpl, styles)
cf_set_value("WIP_FILES", "styles", wip_styles) cf_set_value("WIP_FILES", "styles", wip_styles)
wip_rss = os.path.join(wip_tpl, rss) wip_rss = os.path.join(wip_tpl, rss)
cf_set_value("WIP_FILES", "rss", wip_rss) cf_set_value("WIP_FILES", "rss", wip_rss)
wip_stats = os.path.join(wip_tpl, stats) wip_stats = os.path.join(wip_tpl, stats)
cf_set_value("WIP_FILES", "stats", wip_stats) cf_set_value("WIP_FILES", "stats", wip_stats)
global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer global wip_metas, wip_header, wip_navbar, wip_sidebar, wip_footer
wip_metas = os.path.join(wip_tpl, "metas.html") wip_metas = os.path.join(wip_tpl, "metas.html")
cf_set_value("WIP_FILES", "metas", wip_metas) cf_set_value("WIP_FILES", "metas", wip_metas)
wip_header = os.path.join(wip_tpl, "header.html") wip_header = os.path.join(wip_tpl, "header.html")
cf_set_value("WIP_FILES", "header", wip_header) cf_set_value("WIP_FILES", "header", wip_header)
wip_navbar = os.path.join(wip_tpl, "navbar.html") wip_navbar = os.path.join(wip_tpl, "navbar.html")
cf_set_value("WIP_FILES", "navbar", wip_navbar) cf_set_value("WIP_FILES", "navbar", wip_navbar)
wip_sidebar = os.path.join(wip_tpl, "sidebar.html") wip_sidebar = os.path.join(wip_tpl, "sidebar.html")
cf_set_value("WIP_FILES", "sidebar", wip_sidebar) cf_set_value("WIP_FILES", "sidebar", wip_sidebar)
wip_footer = os.path.join(wip_tpl, "footer.html") wip_footer = os.path.join(wip_tpl, "footer.html")
cf_set_value("WIP_FILES", "footer", wip_footer) cf_set_value("WIP_FILES", "footer", wip_footer)
# [WWW_FILES] # [WWW_FILES]
# =========== # ===========
global www_favicon, www_logo, www_styles, www_rss, www_stats global www_favicon, www_logo, www_styles, www_rss, www_stats
www_favicon = os.path.join(www_tpl, favicon) www_favicon = os.path.join(www_tpl, favicon)
cf_set_value("WWW_FILES", "favicon", www_favicon) cf_set_value("WWW_FILES", "favicon", www_favicon)
www_logo = os.path.join(www_tpl, logo) www_logo = os.path.join(www_tpl, logo)
cf_set_value("WWW_FILES", "logo", www_logo) cf_set_value("WWW_FILES", "logo", www_logo)
www_styles = os.path.join(www_tpl, styles) www_styles = os.path.join(www_tpl, styles)
cf_set_value("WWW_FILES", "styles", www_styles) cf_set_value("WWW_FILES", "styles", www_styles)
www_rss = os.path.join(www_tpl, rss) www_rss = os.path.join(www_tpl, rss)
cf_set_value("WWW_FILES", "rss", www_rss) cf_set_value("WWW_FILES", "rss", www_rss)
www_stats = os.path.join(www_tpl, stats) www_stats = os.path.join(www_tpl, stats)
cf_set_value("WWW_FILES", "stats", www_stats) cf_set_value("WWW_FILES", "stats", www_stats)
global www_metas, www_header, www_navbar, www_sidebar, www_footer global www_metas, www_header, www_navbar, www_sidebar, www_footer
www_metas = os.path.join(www_tpl, "metas.html") www_metas = os.path.join(www_tpl, "metas.html")
cf_set_value("WWW_FILES", "metas", www_metas) cf_set_value("WWW_FILES", "metas", www_metas)
www_header = os.path.join(www_tpl, "header.html") www_header = os.path.join(www_tpl, "header.html")
cf_set_value("WWW_FILES", "header", www_header) cf_set_value("WWW_FILES", "header", www_header)
www_navbar = os.path.join(www_tpl, "navbar.html") www_navbar = os.path.join(www_tpl, "navbar.html")
cf_set_value("WWW_FILES", "navbar", www_navbar) cf_set_value("WWW_FILES", "navbar", www_navbar)
www_sidebar = os.path.join(www_tpl, "sidebar.html") www_sidebar = os.path.join(www_tpl, "sidebar.html")
cf_set_value("WWW_FILES", "sidebar", www_sidebar) cf_set_value("WWW_FILES", "sidebar", www_sidebar)
www_footer = os.path.join(www_tpl, "footer.html") www_footer = os.path.join(www_tpl, "footer.html")
cf_set_value("WWW_FILES", "footer", www_footer) cf_set_value("WWW_FILES", "footer", www_footer)
# [TYTO] # [TYTO]
# ====== # ======
cf_set_value("TYTO", "domain_hash", cf_id) cf_set_value("TYTO", "domain_hash", cf_id)
cf_set_value("TYTO", "domain_conf", cf_uri) cf_set_value("TYTO", "domain_conf", cf_uri)
cf_set_value("TYTO", "domain_user", ult_cf_uri) cf_set_value("TYTO", "domain_user", ult_cf_uri)
# ================================= # # ================================= #
# Write Configuration file # # Write Configuration file #
# Only if needed or when new domain # # Only if needed or when new domain #
# --------------------------------- # # --------------------------------- #
if new_val or write: if new_val or write:
with open(cf_uri, "w") as f: with open(cf_uri, "w") as f:
cf.write(f) cf.write(f)
#=============================================# #=============================================#
# Update User local domain configuration file # # Update User local domain configuration file #
#---------------------------------------------# #---------------------------------------------#
ult_write = False ult_write = False
ult_cf_load() ult_cf_load()
if ult_cf.get("DOMAIN", "name") != name: if ult_cf.get("DOMAIN", "name") != name:
ult_cf.set("DOMAIN", "name", name) ult_cf.set("DOMAIN", "name", name)
ult_write = True ult_write = True
cf_hash_c = tools.get_filesum(cf_uri, True) cf_hash_c = tools.get_filesum(cf_uri, True)
if ult_cf.get("DOMAIN", "hash") != cf_hash_c: if ult_cf.get("DOMAIN", "hash") != cf_hash_c:
ult_cf.set("DOMAIN", "hash", cf_hash_c) ult_cf.set("DOMAIN", "hash", cf_hash_c)
ult_write = True ult_write = True
if ult_cf.get("DOMAIN", "root") != wrk_dir: if ult_cf.get("DOMAIN", "root") != wrk_dir:
ult_cf.set("DOMAIN", "root", wrk_dir) ult_cf.set("DOMAIN", "root", wrk_dir)
ult_write = True ult_write = True
if ult_cf.get("DOMAIN", "conf") != cf_uri: if ult_cf.get("DOMAIN", "conf") != cf_uri:
ult_cf.set("DOMAIN", "conf", cf_uri) ult_cf.set("DOMAIN", "conf", cf_uri)
ult_write = True ult_write = True
if ult_cf.get("SERVER", "root") != srv: if ult_cf.get("SERVER", "root") != srv:
ult_cf.set("SERVER", "root", srv) ult_cf.set("SERVER", "root", srv)
ult_write = True ult_write = True
if ult_write: if ult_write:
with open(ult_cf_uri, "w") as f: with open(ult_cf_uri, "w") as f:
ult_cf.write(f) ult_cf.write(f)
# Update User local Domains List File # Update User local Domains List File
#------------------------------------ #------------------------------------
ult_dlf_load() ult_dlf_load()
dlf_write = False dlf_write = False
try: try:
dlf_line = ult_dlf.get("DOMAINS", name) dlf_line = ult_dlf.get("DOMAINS", name)
if dlf_line != wrk_dir: if dlf_line != wrk_dir:
dlf_write = True dlf_write = True
except: except:
dlf_write = True dlf_write = True
if dlf_write: if dlf_write:
ult_dlf.set("DOMAINS", name, wrk_dir) ult_dlf.set("DOMAINS", name, wrk_dir)
with open(ult_dlf_uri, "w") as f: with open(ult_dlf_uri, "w") as f:
ult_dlf.write(f) ult_dlf.write(f)
#========================================# #========================================#
@ -552,19 +552,18 @@ def cf_update_values(write):
# if activated, check/create wrk dirs # # if activated, check/create wrk dirs #
#----------------------------------------# #----------------------------------------#
def userset_status(action): def userset_status(action):
do = {
do = {
"start" : "yes", "start" : "yes",
"stop" : "no" "stop" : "no"
} }
tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action]) tools.update_ini_file(cf_uri, "DOMAIN", "activated", do[action])
cf_update_values(False) cf_update_values(False)
ready() ready()
if action == "start": if action == "start":
status = cf.get("DOMAIN", "activated") status = cf.get("DOMAIN", "activated")
debug.out(209, "[DOMAIN] activated = %s"%status, cf_uri, True, 0, False) 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 # # or check/create wrk directories #
#----------------------------------------# #----------------------------------------#
def ready(): def ready():
if not activated: if not activated:
status = cf.get("DOMAIN", "activated") status = cf.get("DOMAIN", "activated")
debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True) debug.out(105, "[DOMAIN] activated = %s"%status, cf_uri, True, 1, True)
for key, directory in cf.items("USER_DIRS"): for key, directory in cf.items("USER_DIRS"):
tools.create_dirs(directory) tools.create_dirs(directory)
#======#======================================================================= #======#=======================================================================
@ -590,10 +589,10 @@ def ready():
# Exit Tyto if in black hole... # # Exit Tyto if in black hole... #
#-----------------------------------# #-----------------------------------#
try: try:
user_dir = os.getcwd() + "/" user_dir = os.getcwd() + "/"
home_dir = os.path.expanduser('~') home_dir = os.path.expanduser('~')
except: 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... # # user interrupts... #
#--------------------# #--------------------#
def maybe_later(expected, answer): 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 # # yes_only : True / False #
#-------------------------# #-------------------------#
def ask(q, yes_only, default): def ask(q, yes_only, default):
expected = "" expected = ""
if yes_only: if yes_only:
expected = langs.logs.ok expected = langs.logs.ok
try: answer = input(q) try: answer = input(q)
except KeyboardInterrupt: print("") ; maybe_later(expected, "?") except KeyboardInterrupt: print("") ; maybe_later(expected, "?")
# return default answer if exists # return default answer if exists
if not answer: if not answer:
if default: if default:
return default return default
maybe_later(expected, "?") maybe_later(expected, "?")
# Answer is a Y/N process # Answer is a Y/N process
if yes_only: if yes_only:
for ok in langs.logs.ok: for ok in langs.logs.ok:
if answer.lower() == ok.lower(): if answer.lower() == ok.lower():
return True 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] # # return value[0:12] #
#------------------------------------# #------------------------------------#
def shorter(value): def shorter(value):
if len(value) > 12: if len(value) > 12:
return '%s...'%(value[0:12]) return '%s...'%(value[0:12])
# Or legacy # Or legacy
return value return value
#=========================# #=========================#
@ -93,8 +93,8 @@ def shorter(value):
# from directory basename # # from directory basename #
# ------------------------# # ------------------------#
def ask_domain_shortname(config_name): def ask_domain_shortname(config_name):
q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.configure_domain, config_name, langs.logs.q)
ask(q, True, False) ask(q, True, False)
#=======================# #=======================#
@ -104,14 +104,14 @@ def ask_domain_shortname(config_name):
# - False: return value # # - False: return value #
#-----------------------# #-----------------------#
def ask_domain_title(update): def ask_domain_title(update):
try: title = domain.cf.get("DOMAIN", "title") try: title = domain.cf.get("DOMAIN", "title")
except: title = "" except: title = ""
q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_title, shorter(title), langs.logs.q)
answer = ask(q, False, title) answer = ask(q, False, title)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "title", answer)
else: return answer else: return answer
#===========================# #===========================#
@ -122,24 +122,24 @@ def ask_domain_title(update):
# - False: return value # # - False: return value #
#---------------------------# #---------------------------#
def ask_domain_date(update): def ask_domain_date(update):
try: date = domain.cf.get("DOMAIN", "date") try: date = domain.cf.get("DOMAIN", "date")
except: date = "YYYY[-MM][-DD]" except: date = "YYYY[-MM][-DD]"
example = date example = date
q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_date, example, langs.logs.q)
answer = ask(q, False, date) answer = ask(q, False, date)
# Check date format (not valid date) # Check date format (not valid date)
try: try:
parse(answer) parse(answer)
except: except:
debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False) debug.out(50, "YYYY[-MM-DD]", answer, True, 2, False)
ask_domain_date(update) ask_domain_date(update)
return return
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "date", answer)
else: return answer else: return answer
#========================# #========================#
@ -149,14 +149,14 @@ def ask_domain_date(update):
# - False: return value # # - False: return value #
#------------------------# #------------------------#
def ask_domain_about(update): def ask_domain_about(update):
try: about = domain.cf.get("DOMAIN", "about") try: about = domain.cf.get("DOMAIN", "about")
except: about = "" except: about = ""
q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_about, shorter(about), langs.logs.q)
answer = ask(q, False, about) answer = ask(q, False, about)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "about", answer)
else: return answer else: return answer
#=======================# #=======================#
@ -166,14 +166,14 @@ def ask_domain_about(update):
# - False: return value # # - False: return value #
#-----------------------# #-----------------------#
def ask_domain_mail(update): def ask_domain_mail(update):
try: mail = domain.cf.get("DOMAIN", "mail") try: mail = domain.cf.get("DOMAIN", "mail")
except: mail = "" except: mail = ""
q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_mail, shorter(mail), langs.logs.q)
answer = ask(q, False, mail) answer = ask(q, False, mail)
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "mail", answer)
else: return answer else: return answer
#===============================================# #===============================================#
@ -183,22 +183,22 @@ def ask_domain_mail(update):
# - False: return value # # - False: return value #
#-----------------------------------------------# #-----------------------------------------------#
def ask_domain_tags(update): def ask_domain_tags(update):
try: tags = domain.cf.get("DOMAIN", "tags") try: tags = domain.cf.get("DOMAIN", "tags")
except: tags = "" except: tags = ""
q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_tags, shorter(tags), langs.logs.q)
answer = ask(q, False, tags) answer = ask(q, False, tags)
# Remove useless spaces for HTML meta # Remove useless spaces for HTML meta
tuple_tags = answer.rsplit(",") tuple_tags = answer.rsplit(",")
answer = "" answer = ""
for i, tag in enumerate(tuple_tags): for i, tag in enumerate(tuple_tags):
answer = answer + tag.strip() answer = answer + tag.strip()
if i != len(tuple_tags) - 1: if i != len(tuple_tags) - 1:
answer = answer + "," answer = answer + ","
if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer) if update: tools.update_ini_file(domain.cf_uri, "DOMAIN", "tags", answer)
else: return answer else: return answer
#===================================# #===================================#
@ -206,52 +206,52 @@ def ask_domain_tags(update):
# default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO # default en if no translation file # > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < TODO
#-----------------------------------# #-----------------------------------#
def ask_domain_lang(update): def ask_domain_lang(update):
try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang() try: lang = domain.cf.get("WEBSITE", "lang") or langs.get_sys_lang()
except: lang = "" except: lang = ""
q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_lang, lang, langs.logs.q)
answer = ask(q, False, lang).lower() answer = ask(q, False, lang).lower()
# Lang Format is 2 character # Lang Format is 2 character
if len(answer) != 2: if len(answer) != 2:
debug.out("8", "xx", answer, True, 2, False) debug.out("8", "xx", answer, True, 2, False)
debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False) debug.out(103, "en", "%swebsite_en.py"%langs.trfs, True, 1, False)
answer = lang answer = lang
# Check if translation file exists # Check if translation file exists
if not langs.translation_exists("website", answer, False): if not langs.translation_exists("website", answer, False):
lang = lang.get_sys_lang() lang = lang.get_sys_lang()
debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False) debug.out(103, lang, "%swebsite_%s.py"%(langs.trfs, lang), True, 1, False)
answer = lang answer = lang
if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer) if update: tools.update_ini_file(domain.cf_uri, "WEBSITE", "lang", answer)
else: return lang else: return lang
#===================================# #===================================#
# Get domain server root # # Get domain server root #
#-----------------------------------# #-----------------------------------#
def ask_domain_server(update): def ask_domain_server(update):
try: try:
srv = domain.cf.get("SERVER", "root") srv = domain.cf.get("SERVER", "root")
if not tools.dir_exists(srv, False): if not tools.dir_exists(srv, False):
srv = ""
except:
srv = "" srv = ""
except:
srv = ""
if srv and not tools.dir_exists(srv, False): if srv and not tools.dir_exists(srv, False):
srv = "" srv = ""
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q) q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
answer = ask(q, False, srv) answer = ask(q, False, srv)
# Check if directory exists # Check if directory exists
if not tools.dir_exists(answer, False): if not tools.dir_exists(answer, False):
answer = "" answer = ""
ask_domain_server(update) ask_domain_server(update)
return return
if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer) if update: tools.update_ini_file(domain.cf_uri, "SERVER", "root", answer)
else: return answer else: return answer

View File

@ -40,4 +40,4 @@ import langs, debug
# Help Contents is in translations/logs_XX # # Help Contents is in translations/logs_XX #
#------------------------------------------# #------------------------------------------#
def show(action, target): 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 # # return True or False #
#----------------------------------# #----------------------------------#
def translation_exists(module, lang, out): def translation_exists(module, lang, out):
global tr_file global tr_file
modules = ("logs", "website") modules = ("logs", "website")
if not module in modules: return # in case of internal typo error # 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) tr_file = "%s%s_%s.py"%(trfs, module, lang)
if not os.path.exists(tr_file): if not os.path.exists(tr_file):
debug.out(5, lang, tr_file, True, 2, False) debug.out(5, lang, tr_file, True, 2, False)
return False return False
return True return True
#=============================================================================# #=============================================================================#
@ -70,33 +73,33 @@ def translation_exists(module, lang, out):
# Get system Lang to set logs # # Get system Lang to set logs #
#-----------------------------# #-----------------------------#
def get_sys_lang(): 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] try: lang = locale.getdefaultlocale()[0].rsplit("_")[0]
except: lang = "en" except: lang = "en"
if not translation_exists("logs", lang, False): if not translation_exists("logs", lang, False):
lang = "en" 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 # # Import logs lang file in logs #
#-------------------------------# #-------------------------------#
def load_logs_lang(): def load_logs_lang():
global logs, lang, set_logs global logs, lang, set_logs
try: try:
set_logs set_logs
except: except:
logs = __import__("logs_%s"%get_sys_lang()) logs = __import__("logs_%s"%get_sys_lang())
debug.out(201, lang, tr_logs_uri, False, 0, False) debug.out(201, lang, tr_logs_uri, False, 0, False)
set_logs = True set_logs = True
#=============================================================================# #=============================================================================#
@ -107,30 +110,31 @@ def load_logs_lang():
# Get website lang from cf to set site # # Get website lang from cf to set site #
#---------------------------------------# #---------------------------------------#
def get_website_lang(): def get_website_lang():
global site_lang, tr_website_uri global site_lang, tr_website_uri
tr_website_uri = "%swebsite_%s.py" tr_website_uri = "%swebsite_%s.py"
try: site_lang = domain.cf.get("WEBSITE", "lang") try: site_lang = domain.cf.get("WEBSITE", "lang")
except: site_lang = get_sys_lang() except: site_lang = get_sys_lang()
if not translation_exists("website", site_lang, False): if not translation_exists("website", site_lang, False):
site_lang = get_sys_lang() # or default "en" 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 # # Import website lang file in site #
#----------------------------------# #----------------------------------#
def load_website_lang(): 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" # # Specific to action "new" #
#------------------------------------# #------------------------------------#
def manage(action, target): def manage(action, target):
do = { do = {
"domain" : create_domain, "domain" : create_domain,
} }
do[target]() do[target]()
@ -54,8 +54,8 @@ def manage(action, target):
# or if user "force" option # or if user "force" option
#-----------------------------------# #-----------------------------------#
def create_domain(): def create_domain():
if not domain.cf_exists() or args.force: if not domain.cf_exists() or args.force:
domain.cf_create() domain.cf_create()
return return

View File

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

View File

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

View File

@ -33,7 +33,7 @@
#-------------------------- #--------------------------
from hashlib import blake2b from hashlib import blake2b
import sys, os, configparser, datetime, time import sys, os, configparser, datetime, time, base64
import debug, domain import debug, domain
@ -41,17 +41,17 @@ import debug, domain
# #
# #
def exit(targets, error): def exit(targets, error):
if targets: return if targets: return
sys.exit(error) sys.exit(error)
#==============================# #==============================#
# Set and return date and time # # Set and return date and time #
#------------------------------# #------------------------------#
def nowdate(): def nowdate():
now = datetime.datetime.now() now = datetime.datetime.now()
return(now.strftime('%Y-%m-%d %H:%M:%S')) return(now.strftime('%Y-%m-%d %H:%M:%S'))
# #
@ -59,18 +59,18 @@ def nowdate():
# Return date (only year) for post database # Return date (only year) for post database
# #
def local_date(date): def local_date(date):
date = date.rsplit(" ")[0] # if nowdate() date = date.rsplit(" ")[0] # if nowdate()
year = date.rsplit("-")[0] year = date.rsplit("-")[0]
month = date.rsplit("-")[1] month = date.rsplit("-")[1]
day = date.rsplit("-")[2] day = date.rsplit("-")[2]
dates = { dates = {
"fr" : "%s/%s/%s"%(day, month, year), "fr" : "%s/%s/%s"%(day, month, year),
"en" : date, "en" : date,
} }
return dates[domain.lang] return dates[domain.lang]
#========================# #========================#
@ -79,12 +79,12 @@ def local_date(date):
# False = URI # # False = URI #
#------------------------# #------------------------#
def get_filesum(path, src): 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()) if src: file_sum.update(open(path, 'rb').read())
else: file_sum.update(path.encode()) 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 # # Mainly used to check domain server dir #
#----------------------------------------# #----------------------------------------#
def dir_exists(dir_path, out): def dir_exists(dir_path, out):
if not bool(os.path.exists(dir_path)): if not bool(os.path.exists(dir_path)):
debug.out(6, "False", dir_path, out, 2, out) debug.out(6, "False", dir_path, out, 2, out)
return False return False
return True return True
#====================# #====================#
# Create directories # # Create directories #
#--------------------# #--------------------#
def create_dirs(path): def create_dirs(path):
try: try:
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path, exist_ok=True) os.makedirs(path, exist_ok=True)
debug.out(203, "True", path, False, 0, False) debug.out(203, "True", path, False, 0, False)
except: except:
# Exit if not created # Exit if not created
debug.out(5, "False", path, True, 2, True) debug.out(5, "False", path, True, 2, True)
#============================# #============================#
# Create a new file and logs # # Create a new file and logs #
#----------------------------# #----------------------------#
def create_file(file_path, contents): def create_file(file_path, contents):
up = bool(os.path.exists(file_path)) up = bool(os.path.exists(file_path))
try: try:
with open(file_path, "w") as f: with open(file_path, "w") as f:
f.write(contents) f.write(contents)
except: except:
# Exit at error # Exit at error
debug.out(7, "False", file_path, True, 2, True) debug.out(7, "False", file_path, True, 2, True)
# log "update" or "new" # log "update" or "new"
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
if up: debug.out(207, file_name, file_path, False, 0, False) if up: debug.out(207, file_name, file_path, False, 0, False)
else: debug.out(206, file_name, file_path, False, 0, False) else: debug.out(206, file_name, file_path, False, 0, False)
#===========================================# #===========================================#
# Update ini file, replacing existing value # # Update ini file, replacing existing value #
#-------------------------------------------# #-------------------------------------------#
def update_ini_file(file_path, section, key, val): def update_ini_file(file_path, section, key, val):
# Exit if no file # Exit if no file
if not os.path.exists(file_path): if not os.path.exists(file_path):
debug.out(5, "False", file_path, True, 2, True) debug.out(5, "False", file_path, True, 2, True)
# Load ini file # Load ini file
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(file_path) config.read(file_path)
# New value is same as registred # New value is same as registred
try: try:
if config.get(section, key) == val: if config.get(section, key) == val:
return return
except: except:
config.add_section(section) config.add_section(section)
# Update file with new value # Update file with new value
config.set(section, key, val) config.set(section, key, val)
with open(file_path, "w") as f: with open(file_path, "w") as f:
config.write(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 # Put here values where posts target cannot begin with
notarget = ("./", "../") 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 # # Specific to action "set #
#------------------------------------# #------------------------------------#
def manage(action, target): def manage(action, target):
# Load or Exit if no configuration # Load or Exit if no configuration
domain.cf_load() domain.cf_load()
if action == "set": if action == "set":
do = { do = {
"title" : forms.ask_domain_title, "title" : forms.ask_domain_title,
"date" : forms.ask_domain_date, "date" : forms.ask_domain_date,
"about" : forms.ask_domain_about, "about" : forms.ask_domain_about,
"mail" : forms.ask_domain_mail, "mail" : forms.ask_domain_mail,
"lang" : forms.ask_domain_lang, "lang" : forms.ask_domain_lang,
"server" : forms.ask_domain_server, "server" : forms.ask_domain_server,
} }
do[target](True) do[target](True)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)
elif action in ("start", "stop") and target == "domain":
domain.userset_status(action)