Fix syntax issues

This commit is contained in:
Davide Depau 2020-04-19 03:15:15 +02:00
parent 513abf4604
commit 91648d180f

View file

@ -8,21 +8,31 @@ PLATFORMS = {
}
DOCKER_IMAGE = "depau/drone-makepkg:{arch}"
# For debugging purposes since Drone CLI won't print anything unless you
# give it a somewhat valid pipeline
def _debug_bogus(*a, **kw):
print(kw, *a)
return {
'kind': 'pipeline',
'type': 'docker',
}
def generate(config):
special_archs = {arch: cfg for arch, cfg in config.items() if arch in PLATFORMS.keys()}
others = config.get("all") or config.get("others") or None
if others:
if "arch_matrix" not in config:
fail("arch_matrix is required if all/others is defined")
print("arch_matrix is required if all/others is defined")
return None
matrix = config["arch_matrix"]
# Ensure that arch_matrix won't override a specifically-defined arch
for arch in matrix:
if arch in special_archs:
fail("arch '{}' is defined in both arch_matrix and top level config".format(arch))
print("arch '{}' is defined in both arch_matrix and top level config".format(arch))
return None
archs = {arch: others for arch in matrix}
else:
@ -32,7 +42,7 @@ def generate(config):
pipelines = []
for arch, archconfig in archs:
for arch, archconfig in archs.items():
pipelines.append(generate_pipeline(config, arch, archconfig))
if len(pipelines) == 1:
@ -84,7 +94,7 @@ def generate_pipeline(config, arch, archconfig):
def is_git(pkgconfig):
if type(pkgconfig) == dict:
if type(pkgconfig) == "dict":
return 'git' in pkgconfig
else:
return pkgconfig == "." or "/" in pkgconfig
@ -93,16 +103,18 @@ def is_git(pkgconfig):
def step_aur(pkgconfig):
stepcfg = {'settings': {}}
if type(pkgconfig) == str:
if type(pkgconfig) == "string":
stepcfg['name'] = pkgconfig
stepcfg['settings']['aur'] = pkgconfig
elif type(pkgconfig) == dict:
elif type(pkgconfig) == "dict":
if 'aur' not in pkgconfig:
fail("{} is not a valid aur package definition".format(pkgconfig))
print("{} is not a valid aur package definition".format(pkgconfig))
return None
stepcfg['name'] = pkgconfig.get('name') or pkgconfig['aur']
stepcfg['settings'].update({k, v for k, v in pkgconfig.items() if k != 'name'})
stepcfg['settings'].update({k: v for k, v in pkgconfig.items() if k != 'name'})
else:
fail("{} is not a valid aur package definition".format(pkgconfig))
print("{} is not a valid aur package definition".format(pkgconfig))
return None
return stepcfg
@ -118,19 +130,21 @@ def _gitname(repo_path):
def step_git(pkgconfig):
stepcfg = {'settings': {}}
if type(pkgconfig) == str:
if type(pkgconfig) == "string":
stepcfg['name'] = _gitname(pkgconfig)
if pkgconfig != ".":
stepcfg['settings']['git'] = pkgconfig
elif type(pkgconfig) == dict:
elif type(pkgconfig) == "dict":
if 'git' not in pkgconfig:
fail("{} is not a valid git package definition".format(pkgconfig))
print("{} is not a valid git package definition".format(pkgconfig))
return None
stepcfg['name'] = pkgconfig.get('name') or _gitname(pkgconfig['git'])
if pkgconfig['git'] != ".":
stepcfg['settings']['git'] = pkgconfig['git']
stepcfg['settings'].update({k, v for k, v in pkgconfig.items() if k not in ('git', 'name')})
stepcfg['settings'].update({k: v for k, v in pkgconfig.items() if k not in ('git', 'name')})
else:
fail("{} is not a valid git package definition".format(pkgconfig))
print("{} is not a valid git package definition".format(pkgconfig))
return None
# TODO: probably it's better not to hardcode everything here
@ -138,7 +152,7 @@ def upload_steps(arch):
return [{
'name': 'upload',
'image': 'plugins/s3',
'settings': [
'settings': {
'endpoint': 'https://objstor.depau.eu',
'bucket': 'archlinux-packages',
'access_key': {'from_secret': 'minio_user'},
@ -147,5 +161,5 @@ def upload_steps(arch):
'target': '/' + arch,
'strip_prefix': True,
'path_style': True
]
}
}]