check: image in post + titles ; wip: fix empty lines in bCodes converter
This commit is contained in:
parent
cc039f4555
commit
ceec24105c
|
@ -153,11 +153,10 @@ def create_domain_dirs(path_type):
|
||||||
def get_filesum(path,src):
|
def get_filesum(path,src):
|
||||||
from hashlib import blake2b
|
from hashlib import blake2b
|
||||||
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:
|
else : file_sum.update(path.encode())
|
||||||
file_sum.update(path.encode())
|
return file_sum.hexdigest()
|
||||||
return file_sum.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
#=========================#
|
#=========================#
|
||||||
|
@ -169,13 +168,13 @@ def manage_check(file_post, Force):
|
||||||
post_IDs(file_post)
|
post_IDs(file_post)
|
||||||
|
|
||||||
# Start checking Post, then exit if errors found in
|
# Start checking Post, then exit if errors found in
|
||||||
check_article(post_uri, Force)
|
process_article(post_uri, Force)
|
||||||
|
|
||||||
|
|
||||||
#==========================#
|
#==========================#
|
||||||
# Pre-processing post file #
|
# Pre-processing post file #
|
||||||
#--------------------------#
|
#--------------------------#
|
||||||
def check_article(post_uri, Force):
|
def process_article(post_uri, Force):
|
||||||
global article
|
global article
|
||||||
# Check needed directories. Create if not exist
|
# Check needed directories. Create if not exist
|
||||||
create_domain_dirs('db')
|
create_domain_dirs('db')
|
||||||
|
@ -201,10 +200,11 @@ def check_article(post_uri, Force):
|
||||||
# backup hash_wip/www values
|
# backup hash_wip/www values
|
||||||
hash_wip = post_wip[0];time_wip = post_wip[1]
|
hash_wip = post_wip[0];time_wip = post_wip[1]
|
||||||
hash_www = post_www[0];time_www = post_www[1]
|
hash_www = post_www[0];time_www = post_www[1]
|
||||||
|
|
||||||
# Compare chk Hashes.
|
# Compare chk Hashes.
|
||||||
# Pass if Force, and not same
|
# Pass if Force, and not same
|
||||||
if hash_chk == post_chk[0] and not Force:
|
if hash_chk == post_chk[0] and not Force:
|
||||||
print(':) Check was already done, on',post_chk[1])
|
print(':) Check was already done, on', post_chk[1])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Processing
|
# Processing
|
||||||
|
@ -218,6 +218,8 @@ def check_article(post_uri, Force):
|
||||||
|
|
||||||
# Check markers in headers
|
# Check markers in headers
|
||||||
check_post_header(headers.rsplit('\n'))
|
check_post_header(headers.rsplit('\n'))
|
||||||
|
if Post_Err: sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# Protect bCodes, keep markers for stats, before checking other markers
|
# Protect bCodes, keep markers for stats, before checking other markers
|
||||||
wip.convert_bcodes(article.rsplit('\n'),
|
wip.convert_bcodes(article.rsplit('\n'),
|
||||||
|
@ -249,9 +251,7 @@ def check_article(post_uri, Force):
|
||||||
|
|
||||||
# Error in article
|
# Error in article
|
||||||
#---------------------
|
#---------------------
|
||||||
if Post_Err:
|
if Post_Err: sys.exit(1)
|
||||||
print(':( Invalid article. Needs corrections')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# No Domain registred yet
|
# No Domain registred yet
|
||||||
#-------------------------
|
#-------------------------
|
||||||
|
@ -297,8 +297,8 @@ def post_to_strings(post_uri):
|
||||||
# Split post in 2 strings for Headers and Article
|
# Split post in 2 strings for Headers and Article
|
||||||
global headers, article, post_lines, headers_ln
|
global headers, article, post_lines, headers_ln
|
||||||
|
|
||||||
post_lines = file_string.rsplit('\n')
|
|
||||||
headers = article = ''
|
headers = article = ''
|
||||||
|
post_lines = file_string.rsplit('\n')
|
||||||
post = False
|
post = False
|
||||||
|
|
||||||
for line in post_lines:
|
for line in post_lines:
|
||||||
|
@ -320,20 +320,23 @@ def post_to_strings(post_uri):
|
||||||
# Loop into headers to check markers #
|
# Loop into headers to check markers #
|
||||||
#------------------------------------#
|
#------------------------------------#
|
||||||
def check_post_header(headers):
|
def check_post_header(headers):
|
||||||
global Post_Err
|
|
||||||
global stats_links_uniq, stats_files_uniq, stats_images_uniq, stats_abbrs_uniq
|
|
||||||
global stats_links_p, stats_files_p, stats_images_p, stats_abbrs_p
|
|
||||||
global stats_links
|
|
||||||
# Mandatory markers
|
# Mandatory markers
|
||||||
global title, about, author, tags, date
|
global title, about, author, tags, date
|
||||||
|
|
||||||
# Set Stats
|
|
||||||
stats_links_uniq = stats_files_uniq = stats_images_uniq = stats_abbrs_uniq = 0
|
|
||||||
stats_links = stats_links_p = stats_files_p = stats_images_p = stats_abbrs_p = 0
|
|
||||||
|
|
||||||
# Set Mandatory marker. 0:True/False 1:ln 2: Content
|
# Set Mandatory marker. 0:True/False 1:ln 2: Content
|
||||||
title = about = author = tags = date = ('','','')
|
title = about = author = tags = date = ('','','')
|
||||||
|
|
||||||
|
# Set Stats
|
||||||
|
global stats_links_uniq, stats_links, stats_links_p
|
||||||
|
global stats_files_uniq, stats_files_p
|
||||||
|
global stats_images_uniq, stats_images_p
|
||||||
|
global stats_abbrs_uniq, stats_abbrs_p
|
||||||
|
|
||||||
|
stats_links_uniq = stats_links = stats_links_p = 0
|
||||||
|
stats_files_uniq = stats_files_p = 0
|
||||||
|
stats_images_uniq = stats_images_p = 0
|
||||||
|
stats_abbrs_uniq = stats_abbrs_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 = ('','','','')
|
||||||
|
|
||||||
|
@ -799,8 +802,8 @@ def check_article_markers(article):
|
||||||
#------------------------
|
#------------------------
|
||||||
for ln, line in enumerate(article.rsplit('\n'), 1):
|
for ln, line in enumerate(article.rsplit('\n'), 1):
|
||||||
|
|
||||||
# Do not check if in precode: [[ and ]]
|
# Do not check line if in precode: [[ and ]]
|
||||||
if re.match(markers_reg[2][0], line): precode = True
|
if re.match(markers_reg[2][0], line): precode = True
|
||||||
elif re.match(markers_reg[2][1], line): precode = False
|
elif re.match(markers_reg[2][1], line): precode = False
|
||||||
if precode: continue
|
if precode: continue
|
||||||
|
|
||||||
|
@ -833,15 +836,15 @@ def check_article_markers(article):
|
||||||
elif re.match(markers_reg[1][1], line): stats_qe += 1
|
elif re.match(markers_reg[1][1], line): stats_qe += 1
|
||||||
|
|
||||||
# Check if referenced in header for markers
|
# Check if referenced in header for markers
|
||||||
for marker_p in '_image:', '_code:', '_brut:':
|
for marker in '_image:', '_code:', '_brut:':
|
||||||
if re.match(r'^%s'%marker_p, line):
|
if re.match(r'^%s'%marker, line):
|
||||||
m_name = line.split(':')[1][0]
|
m_name = line.split(':')[1].split(' ')[0]
|
||||||
marker_h = marker_p[1:len(marker_p)]
|
marker_h = marker[1:len(marker)]
|
||||||
if not re.findall(r'%s\s+%s'%(marker_h, m_name), headers):
|
if not re.findall(r'\b%s\s+%s\b'%(marker_h, m_name), headers):
|
||||||
msg_log = 'Line %s. Unused marker "%s %s" in header'%(
|
msg_log = 'Line %s. Unused marker "%s %s" in header'%(
|
||||||
ln+headers_ln, marker_h, m_name
|
ln+headers_ln, marker_h, m_name
|
||||||
)
|
)
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
|
|
||||||
#------------------------------
|
#------------------------------
|
||||||
|
@ -962,7 +965,7 @@ def check_article_titles(article):
|
||||||
#------------------------
|
#------------------------
|
||||||
for ln, line in enumerate(article, 1):
|
for ln, line in enumerate(article, 1):
|
||||||
|
|
||||||
# Do not check if in precode: [[ and ]]
|
# Do not check line if in precode: [[ and ]]
|
||||||
if re.match(markers_reg[2][0], line):
|
if re.match(markers_reg[2][0], line):
|
||||||
precode = True
|
precode = True
|
||||||
stats_bcodes += 1
|
stats_bcodes += 1
|
||||||
|
@ -977,22 +980,33 @@ def check_article_titles(article):
|
||||||
title = line.split(' ', 1)
|
title = line.split(' ', 1)
|
||||||
ht = line[1]
|
ht = line[1]
|
||||||
|
|
||||||
|
# Check title marker #[1-6]
|
||||||
if ht == ' ' or ht == '#':
|
if ht == ' ' or ht == '#':
|
||||||
stats_comments += 1
|
stats_comments += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ht.isnumeric() and not int(ht) in range(1,7):
|
# Title number not in range
|
||||||
msg_log = 'Line %s. Mismatch title number "%s" (1-6)'%(
|
elif ht.isdigit():
|
||||||
ln + headers_ln, ht)
|
if not int(ht) in range(1,7):
|
||||||
log.append_f(post_logs,msg_log,1)
|
msg_log = 'Line %s. Mismatch title number "%s" (1-6)'%(
|
||||||
Post_Err = True
|
ln + headers_ln, ht)
|
||||||
continue
|
log.append_f(post_logs,msg_log,1)
|
||||||
|
Post_Err = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Not a digit in marker title
|
||||||
|
else:
|
||||||
|
msg_log = 'Line %s. Mismatch title number "%s" (1-6)'%(
|
||||||
|
ln + headers_ln, ht)
|
||||||
|
log.append_f(post_logs,msg_log,1)
|
||||||
|
Post_Err = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check description's title
|
||||||
try:
|
try:
|
||||||
title[1]
|
title[1]
|
||||||
if title[1] == ' ' or title[1] == '':
|
if not title[1] or title[1] == ' ': Title_Err = True
|
||||||
Title_Err = True
|
else : stats_titles += 1
|
||||||
else:
|
|
||||||
stats_titles += 1
|
|
||||||
except:
|
except:
|
||||||
Title_Err = True
|
Title_Err = True
|
||||||
|
|
||||||
|
@ -1011,7 +1025,6 @@ def check_article_titles(article):
|
||||||
def check_links_anchors(article):
|
def check_links_anchors(article):
|
||||||
global Post_Err
|
global Post_Err
|
||||||
|
|
||||||
#for ln, line in enumerate(article.rsplit('\n'), 1):
|
|
||||||
anchors_link = re.findall(r'\>_(.*?)_\<', article)
|
anchors_link = re.findall(r'\>_(.*?)_\<', article)
|
||||||
for anchor in anchors_link:
|
for anchor in anchors_link:
|
||||||
anchor_id = anchor.rsplit(':',1)[0]
|
anchor_id = anchor.rsplit(':',1)[0]
|
||||||
|
@ -1042,7 +1055,7 @@ def check_lists_contents(article):
|
||||||
|
|
||||||
if inlist and not re.match(r'^\+|^\=|\s', line):
|
if inlist and not re.match(r'^\+|^\=|\s', line):
|
||||||
msg_log = 'Content list not "+" or "=": %s'%line
|
msg_log = 'Content list not "+" or "=": %s'%line
|
||||||
log.append_f(post_logs,msg_log,1)
|
log.append_f(post_logs, msg_log, 1)
|
||||||
Post_Err = True
|
Post_Err = True
|
||||||
|
|
||||||
#====================================#
|
#====================================#
|
||||||
|
|
|
@ -573,7 +573,8 @@ def convert_bcodes(article, fm, lm, css):
|
||||||
for line in article:
|
for line in article:
|
||||||
if line.startswith(fm):
|
if line.startswith(fm):
|
||||||
bCode = True
|
bCode = True
|
||||||
article_temp = '%s\n%s'%(article_temp, line)
|
if article_temp: article_temp = '%s\n%s'%(article_temp, line)
|
||||||
|
else : article_temp = line
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith(lm):
|
if line.startswith(lm):
|
||||||
|
@ -594,7 +595,8 @@ def convert_bcodes(article, fm, lm, css):
|
||||||
if bCode_lines: bCode_lines = '%s\n%s'%(bCode_lines, line)
|
if bCode_lines: bCode_lines = '%s\n%s'%(bCode_lines, line)
|
||||||
else : bCode_lines = line
|
else : bCode_lines = line
|
||||||
else:
|
else:
|
||||||
article_temp = '%s\n%s'%(article_temp, line)
|
if article_temp: article_temp = '%s\n%s'%(article_temp, line)
|
||||||
|
else : article_temp = line
|
||||||
|
|
||||||
#====================================#
|
#====================================#
|
||||||
# Protect iCodes contents to base64 #
|
# Protect iCodes contents to base64 #
|
||||||
|
|
Loading…
Reference in New Issue