check: abbr + markers (if new line is new marker)
This commit is contained in:
parent
066e89b684
commit
191329a69c
|
@ -35,6 +35,12 @@ markers_reg = [
|
|||
[ r'^\[\[$|^\[\[\s', r'^\]\]$', 'brut codes' ],
|
||||
[ r'^-\($|^-\(\s' , r'^-\)$' , 'lists' ]
|
||||
]
|
||||
markers_opt = (
|
||||
'image:',
|
||||
'file:',
|
||||
'link:',
|
||||
'abbr:'
|
||||
)
|
||||
|
||||
#=======#
|
||||
# Tools #
|
||||
|
@ -169,7 +175,7 @@ def manage_check(file_post, Force):
|
|||
#==========================#
|
||||
# Pre-processing post file #
|
||||
#--------------------------#
|
||||
def check_article(post_uri,Force):
|
||||
def check_article(post_uri, Force):
|
||||
global article
|
||||
# Check needed directories. Create if not exist
|
||||
create_domain_dirs('db')
|
||||
|
@ -318,13 +324,14 @@ def post_to_strings(post_uri):
|
|||
#------------------------------------#
|
||||
def check_post_header(headers):
|
||||
global Post_Err
|
||||
global stats_links_uniq, stats_files_uniq, stats_images_uniq
|
||||
global stats_links_uniq, stats_files_uniq, stats_images_uniq, stats_abbrs_uniq
|
||||
global stats_links_p, stats_files_p, stats_images_p
|
||||
global stats_links
|
||||
# Mandatory markers
|
||||
global title, about, author, tags, date
|
||||
|
||||
# Set Stats
|
||||
stats_links_uniq = stats_files_uniq = stats_images_uniq = 0
|
||||
stats_links_uniq = stats_files_uniq = stats_images_uniq = stats_abbrs_uniq = 0
|
||||
stats_links = stats_links_p = stats_files_p = stats_images_p = 0
|
||||
|
||||
# Set Mandatory marker. 0:True/False 1:ln 2: Content
|
||||
|
@ -343,13 +350,13 @@ def check_post_header(headers):
|
|||
#-----------------------
|
||||
if line.startswith('title:'):
|
||||
title = (True,ln,line.split('title:')[1].lstrip())
|
||||
if line.startswith('about:'):
|
||||
elif line.startswith('about:'):
|
||||
about = (True,ln,line.split('about:')[1].lstrip())
|
||||
if line.startswith('author:'):
|
||||
elif line.startswith('author:'):
|
||||
author = (True,ln,line.split('author:')[1].lstrip())
|
||||
if line.startswith('tags:'):
|
||||
elif line.startswith('tags:'):
|
||||
tags = (True,ln,line.split('tags:')[1].lstrip())
|
||||
if line.startswith('date:'):
|
||||
elif line.startswith('date:'):
|
||||
date = (True,ln,line.split('date:')[1].lstrip())
|
||||
|
||||
#----------------------
|
||||
|
@ -361,15 +368,21 @@ def check_post_header(headers):
|
|||
stats_links_uniq += 1
|
||||
check_links(line, ln, stats_links_uniq)
|
||||
# files:
|
||||
if line.startswith('file:'):
|
||||
elif line.startswith('file:'):
|
||||
# Create variable array
|
||||
stats_files_uniq += 1
|
||||
check_files(line, ln, stats_files_uniq)
|
||||
# images:
|
||||
if line.startswith('image:'):
|
||||
elif line.startswith('image:'):
|
||||
# Create variable array
|
||||
stats_images_uniq += 1
|
||||
check_images(line, ln, stats_images_uniq)
|
||||
# ABBR
|
||||
elif line.startswith('abbr:'):
|
||||
# Create variable array
|
||||
stats_abbrs_uniq += 1
|
||||
check_abbrs(line, ln, stats_abbrs_uniq)
|
||||
|
||||
|
||||
#-------------------------------
|
||||
# Check valid Mandatory markers
|
||||
|
@ -460,20 +473,20 @@ def if_option_marker(marker, m_in):
|
|||
|
||||
if not m_in[2]:
|
||||
msg_log = 'Line %s. Unused URL for marker "%s"'%(
|
||||
m_in[0]+1, marker
|
||||
m_in[0], marker
|
||||
)
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
Post_Err = True
|
||||
|
||||
if not m_in[3]:
|
||||
msg_log = 'Line %s. Unused Alt-Text for marker "%s"'%(
|
||||
m_in[0]+2, marker
|
||||
m_in[0]+1, marker
|
||||
)
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
Post_Err = True
|
||||
|
||||
#=================================#
|
||||
# Check every marker "links:" #
|
||||
# Check every marker "link:" #
|
||||
# For line, from loop header file #
|
||||
# Also, create Stats #
|
||||
#---------------------------------#
|
||||
|
@ -486,6 +499,14 @@ def check_links(line, ln, stats_links_uniq):
|
|||
link_url = headers.rsplit('\n')[ln].lstrip()
|
||||
link_alt = headers.rsplit('\n')[ln+1].lstrip()
|
||||
|
||||
# Check 2nd line
|
||||
check_new_marker(link_url)
|
||||
if new_marker: link_url = ''
|
||||
|
||||
# Check 3rd line
|
||||
check_new_marker(link_alt)
|
||||
if new_marker: link_alt = ''
|
||||
|
||||
link = (
|
||||
ln,
|
||||
link_name,
|
||||
|
@ -517,7 +538,7 @@ def check_links(line, ln, stats_links_uniq):
|
|||
stats_links_p = stats_counter(link_page)
|
||||
|
||||
#=================================#
|
||||
# Check every marker "files:" #
|
||||
# Check every marker "file:" #
|
||||
# For line, from loop header file #
|
||||
# Also, create Stats #
|
||||
#---------------------------------#
|
||||
|
@ -531,6 +552,14 @@ def check_files(line, ln, stats_files_uniq):
|
|||
file_uri = headers.rsplit('\n')[ln].lstrip()
|
||||
file_alt = headers.rsplit('\n')[ln+1].lstrip()
|
||||
|
||||
# Check 2nd line
|
||||
check_new_marker(file_uri)
|
||||
if new_marker: file_uri = ''
|
||||
|
||||
# Check 3rd line
|
||||
check_new_marker(file_alt)
|
||||
if new_marker: file_alt = ''
|
||||
|
||||
file = (
|
||||
ln,
|
||||
file_name,
|
||||
|
@ -595,7 +624,7 @@ def check_files(line, ln, stats_files_uniq):
|
|||
stats_files_p = stats_counter(file_page)
|
||||
|
||||
#=================================#
|
||||
# Check every marker "images:" #
|
||||
# Check every marker "image:" #
|
||||
# For line, from loop header file #
|
||||
# Also, create Stats #
|
||||
#---------------------------------#
|
||||
|
@ -609,12 +638,20 @@ def check_images(line, ln, stats_images_uniq):
|
|||
image_uri = headers.rsplit('\n')[ln].lstrip()
|
||||
image_alt = headers.rsplit('\n')[ln+1].lstrip()
|
||||
|
||||
# Check 2nd line
|
||||
check_new_marker(image_uri)
|
||||
if new_marker: image_uri = ''
|
||||
|
||||
# Check 3rd line
|
||||
check_new_marker(image_alt)
|
||||
if new_marker: image_alt = ''
|
||||
|
||||
image = (
|
||||
ln,
|
||||
image_name,
|
||||
image_uri,
|
||||
image_alt
|
||||
)
|
||||
ln,
|
||||
image_name,
|
||||
image_uri,
|
||||
image_alt
|
||||
)
|
||||
|
||||
# Set/Check values to check in header
|
||||
globals()[image_nbr] = image
|
||||
|
@ -672,6 +709,64 @@ def check_images(line, ln, stats_images_uniq):
|
|||
# Stats: count occurence
|
||||
stats_images_p = stats_counter(image_page)
|
||||
|
||||
#=================================#
|
||||
# Check every marker "abbr:" #
|
||||
# For line, from loop header file #
|
||||
# Also, create Stats #
|
||||
#---------------------------------#
|
||||
def check_abbrs(line, ln, stats_abbrs_uniq):
|
||||
global Post_Err
|
||||
global stats_abbrs_p
|
||||
|
||||
# Create variable array
|
||||
abbr_name = line.split('abbr:')[1].lstrip()
|
||||
abbr_alt = headers.rsplit('\n')[ln].lstrip()
|
||||
abbr_rep = headers.rsplit('\n')[ln+1].lstrip()
|
||||
|
||||
# Set/Check values to check in header
|
||||
if not abbr_name:
|
||||
msg_log = 'Line %s. Unused NAME for marker "abbr:"'%ln
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
Post_Err = True
|
||||
elif abbr_name.isupper() is False:
|
||||
msg_log = 'Line %s. NAME not in CAPITAL for marker "abbr:"'%ln
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
Post_Err = True
|
||||
|
||||
# Check 2rd line
|
||||
check_new_marker(abbr_alt)
|
||||
if new_marker: abbr_name = ''
|
||||
# Set/Check values to check in header
|
||||
if not abbr_alt:
|
||||
msg_log = 'Line %s. Unused alt-text for marker "abbr:"'%ln + 1
|
||||
log.append_f(post_logs,msg_log,1)
|
||||
Post_Err = True
|
||||
|
||||
# Check 3rd line
|
||||
check_new_marker(abbr_rep)
|
||||
if new_marker or not abbr_rep: abbr_rep = abbr_name
|
||||
|
||||
abbr_nbr = 'abbr_%s'%stats_abbrs_uniq
|
||||
abbr = (
|
||||
abbr_name,
|
||||
abbr_alt,
|
||||
abbr_rep
|
||||
)
|
||||
globals()[abbr_nbr] = abbr
|
||||
|
||||
#============================#
|
||||
# Check marker's 3rd line #
|
||||
# if new marker, or empty #
|
||||
# for every optional markers #
|
||||
#----------------------------#
|
||||
def check_new_marker(line3):
|
||||
global new_marker
|
||||
|
||||
new_marker = False
|
||||
|
||||
for marker in markers_opt:
|
||||
if line3.startswith(marker):
|
||||
new_marker = True
|
||||
|
||||
#=================#
|
||||
# ARTICLE CONTENT #
|
||||
|
@ -988,24 +1083,30 @@ def create_DB(post_db):
|
|||
domain.append_f(post_db, line_conf)
|
||||
|
||||
# Optional headers to Post conf
|
||||
# Add every links: array found to DB, one per line
|
||||
# Add every "link:" array found to DB, one per line
|
||||
if stats_links_uniq > 0:
|
||||
for n in range(1,stats_links_uniq+1):
|
||||
m = 'link_%s'%n
|
||||
domain.append_f(post_db,'%s = %s'%(m,globals()[m]))
|
||||
|
||||
# Add every files: array found to DB, one per line
|
||||
# Add every "file:" array found to DB, one per line
|
||||
if stats_files_uniq > 0:
|
||||
for n in range(1,stats_files_uniq+1):
|
||||
m = 'file_%s'%n
|
||||
domain.append_f(post_db,'%s = %s'%(m,globals()[m]))
|
||||
|
||||
# Add every images: array found to DB, one per line
|
||||
# Add every "image:" array found to DB, one per line
|
||||
if stats_images_uniq > 0:
|
||||
for n in range(1,stats_images_uniq+1):
|
||||
m = 'image_%s'%n
|
||||
domain.append_f(post_db,'%s = %s'%(m,globals()[m]))
|
||||
|
||||
# Add every "abbr:" array found to DB, one per line
|
||||
if stats_abbrs_uniq > 0:
|
||||
for n in range(1,stats_abbrs_uniq+1):
|
||||
m = 'abbr_%s'%n
|
||||
domain.append_f(post_db,'%s = %s'%(m,globals()[m]))
|
||||
|
||||
# Statistics Post conf
|
||||
lines_conf = ''
|
||||
lines_conf = (
|
||||
|
@ -1013,6 +1114,7 @@ def create_DB(post_db):
|
|||
'links_u = %d'%stats_links_uniq,
|
||||
'files_u = %d'%stats_files_uniq,
|
||||
'images_u = %d'%stats_images_uniq,
|
||||
'abbrs_u = %d'%stats_abbrs_uniq,
|
||||
'\n# Statistics (Wordings)',
|
||||
'strongs = %d'%m_stats[0],
|
||||
'bolds = %d'%m_stats[2],
|
||||
|
|
Loading…
Reference in New Issue