diff options
author | Whindmar Saksit <whindsaks@proton.me> | 2023-10-23 22:07:05 +0200 |
---|---|---|
committer | Mark Jansen <mark.jansen@reactos.org> | 2024-01-08 09:43:45 +0100 |
commit | 69e6262007a7e69300aeae0242d7a40caefdf6a7 (patch) | |
tree | beea89cba41f172c7a2404f7b04c42f7e953aad7 | |
parent | 21f9d388149f6dd0c586e6b79190849ddb726e9d (diff) | |
download | rapps-db-69e6262007a7e69300aeae0242d7a40caefdf6a7.zip |
Python 3.4 compatible for ROS usage
-rw-r--r-- | .github/validate-rapps.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/.github/validate-rapps.py b/.github/validate-rapps.py index d2ff518..7e48cfb 100644 --- a/.github/validate-rapps.py +++ b/.github/validate-rapps.py @@ -45,6 +45,12 @@ ALL_ARCH = [ b'ppc', ] +LICENSE_TYPES = [ + 1, # Open source + 2, # Freeware + 3, # Trial/Demo +] + all_names = {} all_urls = {} @@ -66,7 +72,7 @@ class Reporter: 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 + '^') @@ -125,17 +131,19 @@ class RappsLine: 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] @@ -152,13 +160,13 @@ class RappsLine: 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): @@ -166,12 +174,26 @@ class RappsLine: 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 @@ -216,7 +238,7 @@ class RappsFile: 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']: @@ -246,7 +268,7 @@ class RappsFile: 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 |