convert comments to @.. notation

This commit is contained in:
Trilarion
2020-09-07 20:09:51 +02:00
parent 625871062f
commit ec233f2f6a
286 changed files with 336 additions and 344 deletions

View File

@ -41,6 +41,10 @@ valid_properties = ('Home', 'Media', 'Inspirations', 'State', 'Play', 'Download'
# only these fields can be used currently (in this order)
valid_fields = ('File', 'Title') + valid_properties + ('Note', 'Building')
url_fields = ('Home', 'Media', 'Play', 'Download', 'Code repository')
valid_url_prefixes = ('http://', 'https://', 'git://', 'svn://', 'ftp://', 'bzr://', '@see-')
valid_building_properties = ('Build system', 'Build instructions')
valid_building_fields = valid_building_properties + ('Note',)

View File

@ -534,13 +534,12 @@ def check_and_process_entry(entry):
d[field] = value
building = d
# check valid fields TODO should also check order
# check valid fields in building TODO should also check order
for field in building.keys():
if field not in valid_building_fields:
message += 'Building field "{}" invalid\n'.format(field)
entry['Building'] = building
# check canonical file name
file = entry['File']
canonical_file_name = canonical_entry_name(entry['Title']) + '.md'
@ -548,11 +547,38 @@ def check_and_process_entry(entry):
if canonical_file_name != file and canonical_file_name != file[:-5] + '.md':
message += 'file name should be {}\n'.format(canonical_file_name)
# state must contain either beta or mature but not both
state = entry['State']
for t in state:
if t != 'beta' and t != 'mature' and not t.startswith('inactive since '):
message += 'Unknown state "{}"'.format(t)
if 'beta' in state == 'mature' in state:
message += 'State must be one of <"beta", "mature">'
# check urls
for field in url_fields:
values = entry.get(field, [])
for value in values:
if value.value.startswith('<') and value.value.endswith('>'):
value.value = value.value[1:-1]
if not any(value.startswith(x) for x in valid_url_prefixes):
message += 'URL "{}" in field "{}" does not start with a valid prefix'.format(value, field)
if message:
raise RuntimeError(message)
return entry
def extract_inactive_year(entry):
state = entry['State']
phrase = 'inactive since '
inactive_year = [x[len(phrase):] for x in state if x.startswith(phrase)]
assert len(inactive_year) <= 1
if inactive_year:
return inactive_year[0]
else:
return None
def write_entries(entries):
"""

View File

@ -14,7 +14,7 @@ class ListingTransformer(lark.Transformer):
"""
def unquoted_value(self, x):
return x[0].value
return x[0].value.strip()
def quoted_value(self, x):
return x[0].value[1:-1].strip() # remove quotation marks and strip whitespaces
@ -33,7 +33,7 @@ class ListingTransformer(lark.Transformer):
:param x:
:return:
"""
return 'Name', x[0].value
return 'Name', x[0].value.strip()
def entry(self, x):
"""
@ -56,13 +56,13 @@ class ListingTransformer(lark.Transformer):
class EntryTransformer(lark.Transformer):
def unquoted_value(self, x):
return x[0].value
return x[0].value.strip()
def quoted_value(self, x):
return x[0].value[1:-1] # remove quotation marks
return x[0].value[1:-1].strip() # remove quotation marks
def comment_value(self, x):
return x[0].value[1:-1] # remove parenthesis
return x[0].value[1:-1].strip() # remove parenthesis
def value(self, x):
if len(x) == 1:
@ -77,10 +77,10 @@ class EntryTransformer(lark.Transformer):
:param x:
:return:
"""
return x[0].value, x[1:]
return x[0].value.strip(), x[1:]
def title(self, x):
return 'Title', x[0].value
return 'Title', x[0].value.strip()
def note(self, x):
"""
@ -109,6 +109,12 @@ class ValueWithComment:
self.value = value
self.comment = comment
def is_empty(self):
return self.value == ''
def startswith(self, str):
return self.value.startswith(str)
def __contains__(self, item):
return item in self.value