mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 21:55:43 -05:00
packages/cli: cmd_check(): reindent and add _nodeps= key
This commit is contained in:
parent
939683f079
commit
cac150d11b
1 changed files with 85 additions and 83 deletions
168
packages/cli.py
168
packages/cli.py
|
@ -204,6 +204,7 @@ def cmd_check(paths):
|
||||||
provided_arches = []
|
provided_arches = []
|
||||||
|
|
||||||
mode_key = '_mode'
|
mode_key = '_mode'
|
||||||
|
nodeps_key = '_nodeps'
|
||||||
pkgbase_key = 'pkgbase'
|
pkgbase_key = 'pkgbase'
|
||||||
pkgname_key = 'pkgname'
|
pkgname_key = 'pkgname'
|
||||||
arches_key = '_arches'
|
arches_key = '_arches'
|
||||||
|
@ -213,6 +214,7 @@ def cmd_check(paths):
|
||||||
sha256sums_key = 'sha256sums'
|
sha256sums_key = 'sha256sums'
|
||||||
required = {
|
required = {
|
||||||
mode_key: True,
|
mode_key: True,
|
||||||
|
nodeps_key: False,
|
||||||
pkgbase_key: False,
|
pkgbase_key: False,
|
||||||
pkgname_key: True,
|
pkgname_key: True,
|
||||||
'pkgdesc': False,
|
'pkgdesc': False,
|
||||||
|
@ -237,107 +239,107 @@ def cmd_check(paths):
|
||||||
pkgbuild_path = os.path.join(config.get_path('pkgbuilds'), package.path, 'PKGBUILD')
|
pkgbuild_path = os.path.join(config.get_path('pkgbuilds'), package.path, 'PKGBUILD')
|
||||||
with open(pkgbuild_path, 'r') as file:
|
with open(pkgbuild_path, 'r') as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
if '\t' in content:
|
if '\t' in content:
|
||||||
logging.fatal(f'\\t is not allowed in {pkgbuild_path}')
|
logging.fatal(f'\\t is not allowed in {pkgbuild_path}')
|
||||||
exit(1)
|
exit(1)
|
||||||
lines = content.split('\n')
|
lines = content.split('\n')
|
||||||
if len(lines) == 0:
|
if len(lines) == 0:
|
||||||
logging.fatal(f'Empty {pkgbuild_path}')
|
logging.fatal(f'Empty {pkgbuild_path}')
|
||||||
exit(1)
|
exit(1)
|
||||||
line_index = 0
|
line_index = 0
|
||||||
key_index = 0
|
key_index = 0
|
||||||
hold_key = False
|
hold_key = False
|
||||||
key = ""
|
key = ""
|
||||||
while True:
|
while True:
|
||||||
line = lines[line_index]
|
line = lines[line_index]
|
||||||
|
|
||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
line_index += 1
|
line_index += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith('_') and not line.startswith(mode_key) and not line.startswith(arches_key) and not line.startswith(commit_key):
|
if line.startswith('_') and line.split('=', 1)[0] not in [mode_key, nodeps_key, arches_key, commit_key]:
|
||||||
line_index += 1
|
line_index += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
formatted = True
|
formatted = True
|
||||||
next_key = False
|
next_key = False
|
||||||
next_line = False
|
next_line = False
|
||||||
reason = ""
|
reason = ""
|
||||||
|
|
||||||
if hold_key:
|
if hold_key:
|
||||||
next_line = True
|
next_line = True
|
||||||
else:
|
else:
|
||||||
if key_index < len(required):
|
if key_index < len(required):
|
||||||
key = list(required)[key_index]
|
key = list(required)[key_index]
|
||||||
if line.startswith(key):
|
if line.startswith(key):
|
||||||
if key == pkgbase_key:
|
if key == pkgbase_key:
|
||||||
required[pkgname_key] = False
|
required[pkgname_key] = False
|
||||||
if key == source_key:
|
if key == source_key:
|
||||||
required[sha256sums_key] = True
|
required[sha256sums_key] = True
|
||||||
next_key = True
|
next_key = True
|
||||||
next_line = True
|
next_line = True
|
||||||
elif key in required and not required[key]:
|
elif key in required and not required[key]:
|
||||||
next_key = True
|
next_key = True
|
||||||
|
|
||||||
if line == ')':
|
if line == ')':
|
||||||
hold_key = False
|
hold_key = False
|
||||||
next_key = True
|
next_key = True
|
||||||
|
|
||||||
if key == arches_key:
|
if key == arches_key:
|
||||||
required_arches = line.split('=')[1]
|
required_arches = line.split('=')[1]
|
||||||
|
|
||||||
if line.endswith('=('):
|
if line.endswith('=('):
|
||||||
hold_key = True
|
hold_key = True
|
||||||
|
|
||||||
if line.startswith(' ') or line == ')':
|
if line.startswith(' ') or line == ')':
|
||||||
next_line = True
|
next_line = True
|
||||||
|
|
||||||
if line.startswith(' ') and not line.startswith(' '):
|
if line.startswith(' ') and not line.startswith(' '):
|
||||||
formatted = False
|
formatted = False
|
||||||
reason = 'Multiline variables should be indented with 4 spaces'
|
reason = 'Multiline variables should be indented with 4 spaces'
|
||||||
|
|
||||||
if '"' in line and not check_quoteworthy(line):
|
if '"' in line and not check_quoteworthy(line):
|
||||||
formatted = False
|
formatted = False
|
||||||
reason = 'Found literal " although no special character was found in the line to justify the usage of a literal "'
|
reason = 'Found literal " although no special character was found in the line to justify the usage of a literal "'
|
||||||
|
|
||||||
if "'" in line and not '"' in line:
|
if "'" in line and not '"' in line:
|
||||||
formatted = False
|
formatted = False
|
||||||
reason = 'Found literal \' although either a literal " or no qoutes should be used'
|
reason = 'Found literal \' although either a literal " or no qoutes should be used'
|
||||||
|
|
||||||
if ('=(' in line and ' ' in line and '"' not in line and not line.endswith('=(')) or (hold_key and line.endswith(')')):
|
if ('=(' in line and ' ' in line and '"' not in line and not line.endswith('=(')) or (hold_key and line.endswith(')')):
|
||||||
formatted = False
|
formatted = False
|
||||||
reason = 'Multiple elements in a list need to be in separate lines'
|
reason = 'Multiple elements in a list need to be in separate lines'
|
||||||
|
|
||||||
if formatted and not next_key and not next_line:
|
if formatted and not next_key and not next_line:
|
||||||
if key_index == len(required):
|
if key_index == len(required):
|
||||||
if lines[line_index] == '':
|
if lines[line_index] == '':
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
formatted = False
|
|
||||||
reason = 'Expected final emtpy line after all variables'
|
|
||||||
else:
|
else:
|
||||||
formatted = False
|
formatted = False
|
||||||
reason = f'Expected to find "{key}"'
|
reason = 'Expected final emtpy line after all variables'
|
||||||
|
else:
|
||||||
|
formatted = False
|
||||||
|
reason = f'Expected to find "{key}"'
|
||||||
|
|
||||||
if not formatted:
|
if not formatted:
|
||||||
logging.fatal(f'Formatting error in {pkgbuild_path}: Line {line_index+1}: "{line}"')
|
logging.fatal(f'Formatting error in {pkgbuild_path}: Line {line_index+1}: "{line}"')
|
||||||
if reason != "":
|
if reason != "":
|
||||||
logging.fatal(reason)
|
logging.fatal(reason)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if key == arch_key:
|
if key == arch_key:
|
||||||
if line.endswith(')'):
|
if line.endswith(')'):
|
||||||
if line.startswith(f'{arch_key}=('):
|
if line.startswith(f'{arch_key}=('):
|
||||||
check_arches_hint(pkgbuild_path, required_arches, [line[6:-1]])
|
check_arches_hint(pkgbuild_path, required_arches, [line[6:-1]])
|
||||||
else:
|
else:
|
||||||
check_arches_hint(pkgbuild_path, required_arches, provided_arches)
|
check_arches_hint(pkgbuild_path, required_arches, provided_arches)
|
||||||
elif line.startswith(' '):
|
elif line.startswith(' '):
|
||||||
provided_arches.append(line[4:])
|
provided_arches.append(line[4:])
|
||||||
|
|
||||||
if next_key and not hold_key:
|
if next_key and not hold_key:
|
||||||
key_index += 1
|
key_index += 1
|
||||||
if next_line:
|
if next_line:
|
||||||
line_index += 1
|
line_index += 1
|
||||||
|
|
||||||
logging.info(f'{package.path} nicely formatted!')
|
logging.info(f'{package.path} nicely formatted!')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue