Commit 6292e48b authored by Denis Salem's avatar Denis Salem
Browse files

fix typo in doc, clean up some shitty code from error processing, adding...

fix typo in doc, clean up some shitty code from error processing, adding EntryAttributeError and EntryIdentifierError.

fix typo in doc, clean up some shitty code from error processing, adding EntryAttributeError and EntryIdentifierError.
parent ae00a8d4
......@@ -24,7 +24,7 @@ path:
atom_file_name: atom_feed.xml
archives_sub_folders: ""
categories_sub_folders: ""
entries_sub_folders: ""
entries_sub_folders: "{entry_title}"
chapters_sub_folders: ""
reverse_thread_order: false
feed_lenght: 5
......
......@@ -86,10 +86,10 @@ qui contiendrait
.:CodeHighlight::Text::False::
Voilà les choses qu'il faut que je fasse avant de mourrir
- venc_arg_1
- venc_arg_2
- venc_arg_3
- venc_arg_4
- {venc_arg_1}
- {venc_arg_2}
- {venc_arg_3}
- {venc_arg_4}
:.
En utilisant le motif __IncludeFile__ comme suit
......
......@@ -178,6 +178,7 @@
DONE | Fix chapters rendering (only first level sub-chapter were rendered)
# version 2.1.x
TODO | Improve context / ressource naming for error management
TODO | Because of fully recursive pattern, some contextual variable are now useless, like {relative_origin}
TODO | SetBackgroundColor for text
TODO | Include threads preview in entry
......
......@@ -7,4 +7,5 @@ override:
atom_file_name: 'atom_feed.xml'
rss_file_name: 'rss_feed.xml'
assets_dependencies: ['feed-logo.png', 'VenC-Scripts-Bootstrap-0.0.0.js', 'VenC-Tree-0.1.0.js', 'VenC-Infinite-Scroll-1.2.0.js']
assets_dependencies: ['feed-logo.png', 'VenC-Scripts-Bootstrap-0.0.0.js', 'VenC-Tree-0.1.0.js', 'VenC-Infinite-Scroll-1.2.0.js', 'VenC_nsfw.png']
includes_dependencies: ['nsfw.html']
......@@ -9,4 +9,5 @@ override:
atom_file_name: 'atom_feed.xml'
rss_file_name: 'rss_feed.xml'
assets_dependencies: ['feed-logo.png', 'VenC-Scripts-Bootstrap-0.0.0.js', 'VenC-Infinite-Scroll-1.2.0.js']
assets_dependencies: ['feed-logo.png', 'VenC-Scripts-Bootstrap-0.0.0.js', 'VenC-Infinite-Scroll-1.2.0.js', 'VenC_nsfw.png']
includes_dependencies: ['nsfw.html']
......@@ -72,6 +72,7 @@ class DataStore:
self.html_categories_tree = {}
self.html_categories_leaves = {}
self.html_blog_archives = {}
self.cache_get_entry_attribute_by_id = {}
self.generation_timestamp = datetime.datetime.now()
self.raw_chapters = {}
self.chapters_index = []
......@@ -102,6 +103,7 @@ class DataStore:
self.path_encoding
))
# Might happen during Entry creation.
except MalformedPatterns as e:
from venc2.helpers import handle_malformed_patterns
handle_malformed_patterns(e)
......@@ -654,6 +656,31 @@ class DataStore:
self.blog_configuration["path"]["archives_directory_name"]
)
# TODO : Cache Result
def get_entry_attribute_by_id(self, argv=list()):
key = ''.join(argv[:2])
if not key in self.cache_get_entry_attribute_by_id.keys():
try:
entry = [entry for entry in self.entries if entry.id == int(argv[1])][0]
self.cache_get_entry_attribute_by_id[key] = getattr(entry, argv[0])
except ValueError:
raise PatternInvalidArgument(
"id",
argv[1],
messages.id_must_be_an_integer
)
except AttributeError as e:
notify(messages.entry_has_no_metadata_like.format(argv[0]), color="YELLOW")
self.cache_get_entry_attribute_by_id[key] = ''
except IndexError:
from venc2.patterns.exceptions import EntryIdentifierError
raise EntryIdentifierError(argv[1])
return self.cache_get_entry_attribute_by_id[key]
def get_entry_url(self, argv=list()):
if self.blog_configuration["disable_single_entries"]:
return ''
......
......@@ -119,3 +119,6 @@ class Messages:
illegal_use_of_escape = "illegal use of one or more escape pattern in {0}."
item_deleted_from_server = "Deleted from server: "
item_uploaded_to_server = "Uploaded to server: "
cannot_retrieve_entry_attribute_because_wrong_id = "Cannot retrieve entry attribute because the given id is unknown."
id_must_be_an_integer = "Identifier must be an integer."
......@@ -117,3 +117,5 @@ class Messages:
illegal_use_of_escape = "Usage illégal d'un ou plusieur motif d'échappement dans le fichier {0}."
item_deleted_from_server = "Supprimé du serveur: "
item_uploaded_to_server = "Transféré sur le serveur: "
cannot_retrieve_entry_attribute_because_wrong_id = "Impossible de récupérer l'attribut de la publication parce que l'id renseigné est inconnu."
id_must_be_an_integer = "L'identifiant doit-être un nombre entier."
......@@ -29,6 +29,14 @@ class IllegalUseOfEscape(Exception):
pass
class EntryAttributeError(Exception):
def __init__(self, attribute_name):
self.attribute_name = attribute_name
class EntryIdentifierError(Exception):
def __init__(self, identifier):
self.attribute_name = identifier
class MalformedPatterns(Exception):
def __init__(self, too_many_opening_symbols, escape, ressource):
self.too_many_opening_symbols = too_many_opening_symbols
......
......@@ -56,6 +56,7 @@ class PatternsMap():
"GetAuthorDescription" :datastore.get_author_description,
"GetBlogLicense" : datastore.get_blog_license,
"GetBlogURL" : datastore.get_blog_url,
"GetEntryAttributeByID":datastore.get_entry_attribute_by_id,
"GetBlogLanguage" : datastore.get_blog_language,
"GetAuthorEmail" : datastore.get_author_email,
......
......@@ -29,6 +29,8 @@ from venc2.prompt import notify
from venc2.prompt import die
from venc2.helpers import remove_by_value
from venc2.l10n import messages
from venc2.patterns.exceptions import EntryAttributeError
from venc2.patterns.exceptions import EntryIdentifierError
from venc2.patterns.exceptions import IllegalUseOfEscape
from venc2.patterns.exceptions import MalformedPatterns
from venc2.patterns.exceptions import UnknownContextual
......@@ -299,7 +301,6 @@ class ProcessedString():
class Processor():
def __init__(self):
self.debug = False
self.functions = {}
self.current_input_string = ''
self.ressource = ''
......@@ -319,69 +320,52 @@ class Processor():
except KeyError as e:
output = self.handle_error(
e,
messages.unknown_pattern.format(pattern),
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [self.current_input_string[self.vop:self.vcp]]
)
except EntryIdentifierError as e:
output = self.handle_error(
messages.cannot_retrieve_entry_attribute_because_wrong_id,
)
except UnknownContextual as e:
output = self.handle_error(
e,
messages.unknown_contextual.format(e),
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = "{0["+str(e)[1:-1]+']}'
)
except PatternMissingArguments as e:
output = self.handle_error(
e,
pattern+": "+e.info,
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [self.current_input_string[self.vop:self.vcp]]
)
except PatternInvalidArgument as e:
output = self.handle_error(
e,
messages.wrong_pattern_argument.format(e.name, e.value, pattern)+' '+e.message,
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [self.current_input_string[self.vop:self.vcp]]
)
except GenericMessage as e:
output = self.handle_error(
e,
e.message,
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [self.current_input_string[self.vop:self.vcp]]
)
# might be removed
except FileNotFoundError as e:
output = self.handle_error(
e,
messages.file_not_found.format(e.filename),
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [e.filename ]
)
return str(output)
# Print out notification to user and replace erroneous pattern
def handle_error(self, exception, error, default_output, error_origin = list()):
def handle_error(self, error):
extra= ""
if self.debug:
raise exception
err = get_formatted_message(error, "RED")+"\n"
if self.ressource != str():
err = messages.in_ressource.format(self.ressource)+'\n'+err
if len(error_origin):
extra+=(''.join(self.current_input_string))
for origin in error_origin:
extra = highlight_value(extra, origin)
extra+=(''.join(self.current_input_string))
extra = highlight_value(extra, self.current_input_string[self.vop:self.vcp+2])
die(err, "RED", extra)
def set_function(self, key, function):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment