From ebdeac513f96514cb9f1727f8083022493db4cdc Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Sat, 31 Dec 2022 00:19:47 +0100 Subject: [PATCH] check: fixes for tags + brut: to raw: --- README.md | 2 +- src/var/lib/tyto/program/check.py | 92 +++++++++++++++---------------- src/var/lib/tyto/program/tyto.py | 4 +- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 2cae31f..1828d4e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ file: Nom du lien URL Texte Alternatif -brut: Nom +raw : Nom URI Texte Alternatif diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index c5f88ba..248285f 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -157,7 +157,7 @@ def check_icodes(article): def check_headers(post_header): global post_err, err, web_uri, date_check global date, title, author, tags, about - global stat_links, stat_images, stat_files, stat_bruts, stat_abbrs + global stat_links, stat_images, stat_files, stat_raws, stat_abbrs global post_tags # Needed Tags @@ -165,7 +165,7 @@ def check_headers(post_header): date = () # Statistics - stat_links = stat_images = stat_files = stat_bruts = stat_abbrs = 0 + stat_links = stat_images = stat_files = stat_raws = stat_abbrs = 0 ### # First session for needed tags # @@ -176,32 +176,32 @@ def check_headers(post_header): # Set each needed tag # # Only the first one is set # #---------------------------# - tag = 'title:' + tag = tyto.headers[0] # title: if line.startswith(tag): if title: continue title = line.rsplit(tag)[1].lstrip() continue - tag = 'about:' + tag = tyto.headers[1] # about: if line.startswith(tag): if about: continue about = line.rsplit(tag)[1].lstrip() continue - tag = 'tags:' + tag = tyto.headers[2] # author: + if line.startswith(tag): + if author: continue + author = line.rsplit(tag)[1].lstrip() + continue + + tag = tyto.headers[3] # tags: if line.startswith(tag): if tags: continue tags = line.rsplit(tag)[1].lstrip() post_tags = len(tags.strip().split(",")) continue - - tag = 'author:' - if line.startswith(tag): - if author: continue - author = line.rsplit(tag)[1].lstrip() - continue - tag = 'date:' + tag = tyto.headers[4] # date: if line.startswith(tag): if date: continue date = line.rsplit(tag)[1].lstrip() @@ -219,11 +219,11 @@ def check_headers(post_header): #-------------------# # Set needed tags need_headers = { - 'title:' : title, - 'anout:' : about, - 'tags:' : tags, - 'author:': author, - 'date:' : date + tyto.headers[0] : title, + tyto.headers[1] : about, + tyto.headers[2] : author, + tyto.headers[3] : tags, + tyto.headers[4] : date } # Check if set needed tags @@ -245,7 +245,7 @@ def check_headers(post_header): # ABBR #----- - tag = 'abbr:' + tag = tyto.headers[8] # abbr: if line.startswith(tag): stat_abbrs += 1 var_tag = 'abbr_%s'%stat_abbrs @@ -282,7 +282,7 @@ def check_headers(post_header): # LINK #----- - tag = 'link:' + tag = tyto.headers[5] # link: if line.startswith(tag): stat_links += 1 var_tag = 'link_%s'%stat_links @@ -318,7 +318,7 @@ def check_headers(post_header): # IMAGE #------ - tag = 'image:' + tag = tyto.headers[6] # image: if line.startswith(tag): stat_images += 1 var_tag = 'image_%s'%stat_images @@ -353,41 +353,41 @@ def check_headers(post_header): image_alt ) - # BRUT - #----- - tag = 'brut:' + # RAW File + #--------- + tag = tyto.headers[9] # raw: if line.startswith(tag): - stat_bruts += 1 - var_tag = 'brut_%s'%stat_bruts + stat_raws += 1 + var_tag = 'raw_%s'%stat_raws - brut_name = post_header[ln - 1] - brut_name = brut_name.rsplit(tag)[1].lstrip().rsplit(' ')[0] - if not brut_name: + raw_name = post_header[ln - 1] + raw_name = raw_name.rsplit(tag)[1].lstrip().rsplit(' ')[0] + if not raw_name: tyto.exiting("2", "Line %s (Name, %s)"%(ln, tag), False) post_err = True - if not isin(r'\b_%s%s\b'%(tag, brut_name), post_bottom): - tyto.exiting("6", "_%s%s"%(tag, brut_name), False) + if not isin(r'\b_%s%s\b'%(tag, raw_name), post_bottom): + tyto.exiting("6", "_%s%s"%(tag, raw_name), False) post_err = True - brut_uri = post_header[ln].lstrip() - if brut_uri.startswith(tyto.headers): brut_uri = '' - if not brut_uri: + raw_uri = post_header[ln].lstrip() + if raw_uri.startswith(tyto.headers): raw_uri = '' + if not raw_uri: tyto.exiting("2", "Line %s (URI, %s)"%(ln + 1, tag), False) post_err = True else: - check_file_uri('file', brut_uri, ln + 1) + check_file_uri('file', raw_uri, ln + 1) - brut_alt = post_header[ln + 1].lstrip() - if brut_alt.startswith(tyto.headers): brut_alt = '' - if not brut_alt: + raw_alt = post_header[ln + 1].lstrip() + if raw_alt.startswith(tyto.headers): raw_alt = '' + if not raw_alt: tyto.exiting("2", "Line %s (Alt-Text, %s)"%(ln + 2, tag), False) post_err = True if not post_err: - globals()['brut_%s'%stat_bruts] = ( - '_%s%s'%(tag, brut_name), + globals()['raw_%s'%stat_raws] = ( + '_%s%s'%(tag, raw_name), web_uri, - brut_alt + raw_alt ) # FILE @@ -568,7 +568,7 @@ def check_content(post_bottom): match = False for hline in post_header: - if hline.startswith('image:'): + if hline.startswith(htag): htag_id = hline.rsplit(':', 1)[1].lstrip() if htag_id == tag_id: match = True @@ -642,10 +642,10 @@ def create_database(): database, i, globals()['file_%s'%i] ) - if stat_bruts > 0: - for i in range(1, stat_bruts + 1): - database = '%s\nbrut_%s = %s'%( - database, i, globals()['brut_%s'%i] + if stat_raws > 0: + for i in range(1, stat_raws + 1): + database = '%s\nraw_%s = %s'%( + database, i, globals()['raw_%s'%i] ) db_stats = '\n# Statistics from optional tags\n' + \ @@ -654,7 +654,7 @@ def create_database(): 'uniq_links = %s\n'%(int(stat_links)) + \ 'uniq_images = %s\n'%(int(stat_images)) + \ 'uniq_files = %s\n'%(int(stat_files)) + \ - 'uniq_bruts = %s\n'%(int(stat_bruts)) + \ + 'uniq_raws = %s\n'%(int(stat_raws)) + \ '\n# Statistics from post content\n' + \ 'stat_tags = %s\n'%(int(post_tags)) + \ 'stat_words = %s\n'%(int(post_words)) + \ diff --git a/src/var/lib/tyto/program/tyto.py b/src/var/lib/tyto/program/tyto.py index 7d03fd8..4bbae03 100644 --- a/src/var/lib/tyto/program/tyto.py +++ b/src/var/lib/tyto/program/tyto.py @@ -101,7 +101,7 @@ headers = ( 'image:', 'file:', 'abbr:', - 'brut:', + 'raw:', '#' ) @@ -164,7 +164,7 @@ quote_tags = [ ] # Tags to check for header in content -content_tags = ("_image:", '_brut:') +content_tags = ("_image:", '_raw:') #=======#