Changeset View
Changeset View
Standalone View
Standalone View
lilybuild/lilybuild/helpers.py
| import json | import json | ||||
| import shlex | import shlex | ||||
| import re | |||||
| def normalize_path_for_rsync(path): | def normalize_path_for_rsync(path): | ||||
| n = path | n = path | ||||
| if n.startswith('./'): | if n.startswith('./'): | ||||
| n = n[2:] | n = n[2:] | ||||
| if n.endswith('/'): | if n.endswith('/'): | ||||
| n = n[:-1] | n = n[:-1] | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | return ( | ||||
| '\n\nexit 0' | '\n\nexit 0' | ||||
| ) | ) | ||||
| def normalize_image(image): | def normalize_image(image): | ||||
| if isinstance(image, str): | if isinstance(image, str): | ||||
| return json.dumps({'name': image}) | return json.dumps({'name': image}) | ||||
| else: | else: | ||||
| return json.dumps(image) | return json.dumps(image) | ||||
| def get_service_aliases_from_name(name): | |||||
| # https://docs.gitlab.com/ci/services/#accessing-the-services | |||||
| pos = name.find(':') | |||||
| if pos != -1: | |||||
| name = name[:pos] | |||||
| primary = name.replace('/', '__') | |||||
| secondary = name.replace('/', '-') | |||||
| if primary == secondary: | |||||
| return [primary] | |||||
| else: | |||||
| return [primary, secondary] | |||||
| SERVICE_ALIAS_SEPARATOR = re.compile(r'[ ,]+') | |||||
| def normalize_services(services): | |||||
| res = [] | |||||
| for s in services: | |||||
| so = s if isinstance(s, dict) else {'name': s} | |||||
| normalized_service = { | |||||
| 'name': so['name'], | |||||
| 'aliases': SERVICE_ALIAS_SEPARATOR.split(so.get('alias')) if so.get('alias') else get_service_aliases_from_name(so['name']), | |||||
| 'entrypoint': so.get('entrypoint'), | |||||
| 'command': so.get('command'), | |||||
| } | |||||
| res.append(normalized_service) | |||||
| return json.dumps(res) | |||||