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}" 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): def generate(config):
special_archs = {arch: cfg for arch, cfg in config.items() if arch in PLATFORMS.keys()} 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 others = config.get("all") or config.get("others") or None
if others: if others:
if "arch_matrix" not in config: 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"] matrix = config["arch_matrix"]
# Ensure that arch_matrix won't override a specifically-defined arch # Ensure that arch_matrix won't override a specifically-defined arch
for arch in matrix: for arch in matrix:
if arch in special_archs: 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} archs = {arch: others for arch in matrix}
else: else:
@ -32,7 +42,7 @@ def generate(config):
pipelines = [] pipelines = []
for arch, archconfig in archs: for arch, archconfig in archs.items():
pipelines.append(generate_pipeline(config, arch, archconfig)) pipelines.append(generate_pipeline(config, arch, archconfig))
if len(pipelines) == 1: if len(pipelines) == 1:
@ -84,7 +94,7 @@ def generate_pipeline(config, arch, archconfig):
def is_git(pkgconfig): def is_git(pkgconfig):
if type(pkgconfig) == dict: if type(pkgconfig) == "dict":
return 'git' in pkgconfig return 'git' in pkgconfig
else: else:
return pkgconfig == "." or "/" in pkgconfig return pkgconfig == "." or "/" in pkgconfig
@ -93,16 +103,18 @@ def is_git(pkgconfig):
def step_aur(pkgconfig): def step_aur(pkgconfig):
stepcfg = {'settings': {}} stepcfg = {'settings': {}}
if type(pkgconfig) == str: if type(pkgconfig) == "string":
stepcfg['name'] = pkgconfig stepcfg['name'] = pkgconfig
stepcfg['settings']['aur'] = pkgconfig stepcfg['settings']['aur'] = pkgconfig
elif type(pkgconfig) == dict: elif type(pkgconfig) == "dict":
if 'aur' not in pkgconfig: 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['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: 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 return stepcfg
@ -118,19 +130,21 @@ def _gitname(repo_path):
def step_git(pkgconfig): def step_git(pkgconfig):
stepcfg = {'settings': {}} stepcfg = {'settings': {}}
if type(pkgconfig) == str: if type(pkgconfig) == "string":
stepcfg['name'] = _gitname(pkgconfig) stepcfg['name'] = _gitname(pkgconfig)
if pkgconfig != ".": if pkgconfig != ".":
stepcfg['settings']['git'] = pkgconfig stepcfg['settings']['git'] = pkgconfig
elif type(pkgconfig) == dict: elif type(pkgconfig) == "dict":
if 'git' not in pkgconfig: 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']) stepcfg['name'] = pkgconfig.get('name') or _gitname(pkgconfig['git'])
if pkgconfig['git'] != ".": if pkgconfig['git'] != ".":
stepcfg['settings']['git'] = 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: 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 # TODO: probably it's better not to hardcode everything here
@ -138,7 +152,7 @@ def upload_steps(arch):
return [{ return [{
'name': 'upload', 'name': 'upload',
'image': 'plugins/s3', 'image': 'plugins/s3',
'settings': [ 'settings': {
'endpoint': 'https://objstor.depau.eu', 'endpoint': 'https://objstor.depau.eu',
'bucket': 'archlinux-packages', 'bucket': 'archlinux-packages',
'access_key': {'from_secret': 'minio_user'}, 'access_key': {'from_secret': 'minio_user'},
@ -147,5 +161,5 @@ def upload_steps(arch):
'target': '/' + arch, 'target': '/' + arch,
'strip_prefix': True, 'strip_prefix': True,
'path_style': True 'path_style': True
] }
}] }]