From 6f3de302ee19ff3f80ef9cd7587cb3e9615e5bcc Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Tue, 22 Nov 2022 12:21:55 +0100 Subject: [PATCH] check: added "brut:" marker --- src/var/lib/tyto/program/check.py | 133 +++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 19 deletions(-) diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index f1ec067..07f6101 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -329,14 +329,16 @@ def check_post_header(headers): global stats_files_uniq, stats_files_p global stats_images_uniq, stats_images_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_files_uniq = stats_files_p = 0 stats_images_uniq = stats_images_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 - link = file = image = ('','','','') + link = file = image = brut = ('','','','') #----------------------- # Loop in headers string @@ -360,26 +362,26 @@ def check_post_header(headers): #---------------------- # Set optional markers #---------------------- - # links: + # link: if line.startswith('link:'): - # Create variable array stats_links_uniq += 1 check_links(line, ln, stats_links_uniq) - # files: + # file: elif line.startswith('file:'): - # Create variable array stats_files_uniq += 1 check_files(line, ln, stats_files_uniq) - # images: + # image: elif line.startswith('image:'): - # Create variable array stats_images_uniq += 1 check_images(line, ln, stats_images_uniq) - # ABBR + # abbr: elif line.startswith('abbr:'): - # Create variable array stats_abbrs_uniq += 1 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('tags:', tags) if_mandat_marker('date:', date) - if date: - check_date(date) + if date: check_date(date) #===================# @@ -435,7 +436,7 @@ def check_date(date): # Create date_check (epoch) from article's Date + now TIME if not Post_Err: - fmt_check = '%Y-%m-%d %H:%M:%S' + fmt_check = '%Y-%m-%d %H:%M:%S' time_check = strftime("%H:%M:%S", gmtime()) date_check = date[2] + ' ' + time_check date_check = time.mktime(time.strptime(date_check,fmt_check)) @@ -595,7 +596,7 @@ def check_files(line, ln, stats_files_uniq): usr_file = '%s%s'%(domain.domain_articles, file_uri) if not os.path.exists(usr_file): msg_log = 'Unused file for marker "file:" in %s'%usr_file - log.append_f(post_logs,msg_log,1) + log.append_f(post_logs, msg_log, 1) Post_Err = True else: file_uri = '/%s'%file_uri @@ -622,6 +623,92 @@ def check_files(line, ln, stats_files_uniq): # Stats: count occurence 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:" # # For line, from loop header file # @@ -1110,21 +1197,27 @@ def create_DB(post_db): # Add every "file:" array found to DB, one per line if stats_files_uniq > 0: - for n in range(1,stats_files_uniq+1): + for n in range(1, stats_files_uniq+1): m = 'file_%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_images_uniq > 0: - for n in range(1,stats_images_uniq+1): + for n in range(1, stats_images_uniq+1): 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 if stats_abbrs_uniq > 0: - for n in range(1,stats_abbrs_uniq+1): + for n in range(1, stats_abbrs_uniq+1): m = 'abbr_%s'%n - domain.append_f(post_db,'%s = %s'%(m,globals()[m])) + domain.append_f(post_db, '%s = %s'%(m,globals()[m])) # Statistics Post conf lines_conf = '' @@ -1133,6 +1226,7 @@ def create_DB(post_db): 'links_u = %d'%stats_links_uniq, 'files_u = %d'%stats_files_uniq, 'images_u = %d'%stats_images_uniq, + 'bruts_u = %d'%stats_bruts_uniq, 'abbrs_u = %d'%stats_abbrs_uniq, '\n# Statistics (Wordings)', 'strongs = %d'%m_stats[0], @@ -1149,6 +1243,7 @@ def create_DB(post_db): 'links_p = %d'%stats_links_p, 'files_p = %d'%stats_files_p, 'images_p = %d'%stats_images_p, + 'bruts_p = %d'%stats_bruts_p, 'abbrs_p = %d'%stats_abbrs_p, '\n# Statistics (Templates)', 'titles = %d'%stats_titles,