Skip to content

Commit

Permalink
Python 3.4 compatible for ROS usage
Browse files Browse the repository at this point in the history
  • Loading branch information
whindsaks authored and learn-more committed Jan 8, 2024
1 parent 21f9d38 commit 69e6262
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions .github/validate-rapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
b'ppc',
]

LICENSE_TYPES = [
1, # Open source
2, # Freeware
3, # Trial/Demo
]


all_names = {}
all_urls = {}
Expand All @@ -66,7 +72,7 @@ def __init__(self):

def add(self, line, column, problem):
self._problems += 1
print(f'{line.location(column)}: {problem}')
print('{col}: {msg}'.format(col = line.location(column), msg = problem))
print(line.text())
idx = column - 1 + len("b'") # Offset the b' prefix
print(' ' * idx + '^')
Expand Down Expand Up @@ -125,17 +131,19 @@ def _parse_section(self, reporter, stripped):

if section_name != b'Section':
help = 'should always be "Section"'
reporter.add(self, self._text.index(section_name) + 1, f'Invalid section name: "{section_name}", {help}')
reporter.add(self, self._text.index(section_name) + 1,
'Invalid section name: "{sec}", {msg}'.format(sec = section_name, msg = help))
elif not locale:
self.main_section = True

if locale:
if len(locale) not in (2, 4) or not all(c in HEXDIGITS for c in locale):
reporter.add(self, self._text.index(locale) + 1, f'Invalid locale{extra_locale}: "{locale}"')
reporter.add(self, self._text.index(locale) + 1,
'Invalid locale{extra}: "{loc}"'.format(extra = extra_locale, loc = locale))

if arch:
if arch not in ALL_ARCH:
reporter.add(self, self._text.index(arch) + 1, f'Unknown architecture: "{arch}"')
reporter.add(self, self._text.index(arch) + 1, 'Unknown architecture: "%s"' % arch)

def _extract_section_info(self, text, reporter):
text = text[1:-1]
Expand All @@ -152,26 +160,40 @@ def _extract_section_info(self, text, reporter):
else:
locale = parts[1]
arch = None
extra_locale = '(and unknown architecture)'
extra_locale = ' (and unknown architecture)'
elif len(parts) == 3:
locale = parts[1]
arch = parts[2]
else:
locale = arch = None
reporter.add(self, self._text.index(b'[') + 1, f'Unknown section format: "{text}"')
reporter.add(self, self._text.index(b'[') + 1, 'Unknown section format: "%s"' % text)
return section_name, locale, extra_locale, arch

def _parse_key_value(self, reporter, parts):
# key = value
assert len(parts) == 2, self
self.key = parts[0]
self.val = parts[1]
textkey = self.key.decode()
textval = self.val.decode()

if self.key not in ALL_KEYS:
reporter.add(self, 0, f'Unknown key: "{self.key}"')
reporter.add(self, 0, 'Unknown key: "{key}"'.format(key = textkey))

if self.key in [b'LicenseType']:
v = int(textval, base=10)
if v not in LICENSE_TYPES:
reporter.add(self, 0, 'Invalid value: "{val}" in {key}'.format(val = v, key = textkey))

if self.key in [b'License']:
v = textval
if v.casefold() == 'Unknown'.casefold():
# TODO: Reporter should be enabled when the existing DB entries are fixed:
# reporter.add(self, 0, 'Invalid value: "{val}" in {key}'.format(val = v, key = textkey))
print('Warning: {key} is "{val}" ({file})'.format(val = v, key = textkey, file = self._file.filename))

def location(self, column):
return f'{self._file.filename}({self._lineno}:{column})'
return '{file}({line}:{col})'.format(file = self._file.filename, line = self._lineno, col = column)

def text(self):
return self._text
Expand Down Expand Up @@ -216,7 +238,7 @@ def parse(self, reporter):
main_section = section
for key in REQUIRED_KEYS:
if not section[key]:
reporter.add(section, 0, f'Main section has no {key} key!')
reporter.add(section, 0, 'Main section has no {key} key!'.format(key = key))
if section[b'URLDownload'] and not section[b'SizeBytes']:
# We allow this, if the main section has a SizeBytes (alternate mirror without duplicating the info)
if section == main_section or main_section and not main_section[b'SizeBytes']:
Expand Down Expand Up @@ -246,7 +268,7 @@ def parse(self, reporter):
def verify_unique(reporter, lines, line, name):
first = lines.get(name, None)
if first:
reporter.add(line, 0, f'Duplicate value found: {name}')
reporter.add(line, 0, 'Duplicate value found: {name}'.format(name = name))
reporter.add(first, 0, 'First occurence:')
else:
lines[name] = line
Expand Down

0 comments on commit 69e6262

Please sign in to comment.