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