check: added "brut:" marker

This commit is contained in:
Cyrille L 2022-11-22 12:21:55 +01:00
parent 17e3fdd342
commit 6f3de302ee
1 changed files with 114 additions and 19 deletions

View File

@ -329,14 +329,16 @@ def check_post_header(headers):
global stats_files_uniq, stats_files_p global stats_files_uniq, stats_files_p
global stats_images_uniq, stats_images_p global stats_images_uniq, stats_images_p
global stats_abbrs_uniq, stats_abbrs_p global stats_abbrs_uniq, stats_abbrs_p
global stats_bruts_uniq, stats_bruts_p
stats_links_uniq = stats_links = stats_links_p = 0 stats_links_uniq = stats_links = stats_links_p = 0
stats_files_uniq = stats_files_p = 0 stats_files_uniq = stats_files_p = 0
stats_images_uniq = stats_images_p = 0 stats_images_uniq = stats_images_p = 0
stats_abbrs_uniq = stats_abbrs_p = 0 stats_abbrs_uniq = stats_abbrs_p = 0
stats_bruts_uniq = stats_bruts_p = 0
# Set Optional markers. 0:ln 1:Name 2:URL 3:Alt # Set Optional markers. 0:ln 1:Name 2:URL 3:Alt
link = file = image = ('','','','') link = file = image = brut = ('','','','')
#----------------------- #-----------------------
# Loop in headers string # Loop in headers string
@ -360,26 +362,26 @@ def check_post_header(headers):
#---------------------- #----------------------
# Set optional markers # Set optional markers
#---------------------- #----------------------
# links: # link:
if line.startswith('link:'): if line.startswith('link:'):
# Create variable array
stats_links_uniq += 1 stats_links_uniq += 1
check_links(line, ln, stats_links_uniq) check_links(line, ln, stats_links_uniq)
# files: # file:
elif line.startswith('file:'): elif line.startswith('file:'):
# Create variable array
stats_files_uniq += 1 stats_files_uniq += 1
check_files(line, ln, stats_files_uniq) check_files(line, ln, stats_files_uniq)
# images: # image:
elif line.startswith('image:'): elif line.startswith('image:'):
# Create variable array
stats_images_uniq += 1 stats_images_uniq += 1
check_images(line, ln, stats_images_uniq) check_images(line, ln, stats_images_uniq)
# ABBR # abbr:
elif line.startswith('abbr:'): elif line.startswith('abbr:'):
# Create variable array
stats_abbrs_uniq += 1 stats_abbrs_uniq += 1
check_abbrs(line, ln, stats_abbrs_uniq) check_abbrs(line, ln, stats_abbrs_uniq)
# brut:
elif line.startswith('brut:'):
stats_bruts_uniq += 1
check_bruts(line, ln, stats_bruts_uniq)
#------------------------------- #-------------------------------
@ -390,8 +392,7 @@ def check_post_header(headers):
if_mandat_marker('author:', author) if_mandat_marker('author:', author)
if_mandat_marker('tags:', tags) if_mandat_marker('tags:', tags)
if_mandat_marker('date:', date) if_mandat_marker('date:', date)
if date: if date: check_date(date)
check_date(date)
#===================# #===================#
@ -622,6 +623,92 @@ def check_files(line, ln, stats_files_uniq):
# Stats: count occurence # Stats: count occurence
stats_files_p = stats_counter(file_page) stats_files_p = stats_counter(file_page)
#=================================#
# Check every marker "brut:" #
# For line, from loop header file #
# Also, create Stats #
#---------------------------------#
def check_bruts(line, ln, stats_files_uniq):
global Post_Err
global stats_bruts_p
# Create variable array
brut_nbr = 'brut_%s'%stats_bruts_uniq
brut_name = line.split('brut:')[1].lstrip().rsplit(' ')[0]
brut_uri = headers.rsplit('\n')[ln].lstrip()
brut_alt = headers.rsplit('\n')[ln+1].lstrip()
# Check 2nd line
check_new_marker(brut_uri)
if new_marker: brut_uri = ''
# Check 3rd line
check_new_marker(brut_alt)
if new_marker: brut_alt = ''
brut = (
ln,
brut_name,
brut_uri,
brut_alt
)
# Set/Check values to check in header
globals()[brut_nbr] = brut
if_option_marker('brut:', globals()[brut_nbr])
# Check value in article
brut_page = '_brut:%s'%brut_name
if not brut_page in article:
msg_log = 'Unused "%s" for marker "brut:" in article"'%brut_page
log.append_f(post_logs, msg_log, 1)
Post_Err = True
# Check URI value (exists and where)
# In Generic folder /files/
if brut_uri.startswith('@'):
brut_uri = brut_uri.replace('@','')
gen_file = '%s%s'%(domain.domain_files, brut_uri)
if not os.path.exists(gen_file):
msg_log = 'Unused file for marker "brut:" in %s'%gen_file
log.append_f(post_logs, msg_log, 1)
Post_Err = True
else:
brut_uri = '/files/%s'%brut_uri
# From Root articles (www/ in web)
elif brut_uri.startswith('/'):
brut_uri = brut_uri[1:len(brut_uri)] # No need first / to check
usr_file = '%s%s'%(domain.domain_articles, brut_uri)
if not os.path.exists(usr_file):
msg_log = 'Unused file for marker "brut:" in %s'%usr_file
log.append_f(post_logs, msg_log, 1)
Post_Err = True
else:
brut_uri = '/%s'%brut_uri
# Current or custom URI
else:
usr_file = '%s%s'%(domain.domain_articles, brut_uri)
if not os.path.exists(usr_file):
msg_log = 'Unused file for marker "brut:" in %s'%usr_file
log.append_f(post_logs, msg_log, 1)
Post_Err = True
if Post_Err: return
#--------------------
# Set final marker_N
#--------------------
brut = (
'%s'%brut_name,
brut_uri,
brut_alt
)
globals()[brut_nbr] = brut
# Stats: count occurence
stats_bruts_p = stats_counter(brut_page)
#=================================# #=================================#
# Check every marker "image:" # # Check every marker "image:" #
# For line, from loop header file # # For line, from loop header file #
@ -1120,6 +1207,12 @@ def create_DB(post_db):
m = 'image_%s'%n m = 'image_%s'%n
domain.append_f(post_db, '%s = %s'%(m,globals()[m])) domain.append_f(post_db, '%s = %s'%(m,globals()[m]))
# Add every "image:" array found to DB, one per line
if stats_bruts_uniq > 0:
for n in range(1, stats_bruts_uniq+1):
m = 'brut_%s'%n
domain.append_f(post_db, '%s = %s'%(m,globals()[m]))
# Add every "abbr:" array found to DB, one per line # Add every "abbr:" array found to DB, one per line
if stats_abbrs_uniq > 0: if stats_abbrs_uniq > 0:
for n in range(1, stats_abbrs_uniq+1): for n in range(1, stats_abbrs_uniq+1):
@ -1133,6 +1226,7 @@ def create_DB(post_db):
'links_u = %d'%stats_links_uniq, 'links_u = %d'%stats_links_uniq,
'files_u = %d'%stats_files_uniq, 'files_u = %d'%stats_files_uniq,
'images_u = %d'%stats_images_uniq, 'images_u = %d'%stats_images_uniq,
'bruts_u = %d'%stats_bruts_uniq,
'abbrs_u = %d'%stats_abbrs_uniq, 'abbrs_u = %d'%stats_abbrs_uniq,
'\n# Statistics (Wordings)', '\n# Statistics (Wordings)',
'strongs = %d'%m_stats[0], 'strongs = %d'%m_stats[0],
@ -1149,6 +1243,7 @@ def create_DB(post_db):
'links_p = %d'%stats_links_p, 'links_p = %d'%stats_links_p,
'files_p = %d'%stats_files_p, 'files_p = %d'%stats_files_p,
'images_p = %d'%stats_images_p, 'images_p = %d'%stats_images_p,
'bruts_p = %d'%stats_bruts_p,
'abbrs_p = %d'%stats_abbrs_p, 'abbrs_p = %d'%stats_abbrs_p,
'\n# Statistics (Templates)', '\n# Statistics (Templates)',
'titles = %d'%stats_titles, 'titles = %d'%stats_titles,