-
Notifications
You must be signed in to change notification settings - Fork 15
/
tag_manager.py
47 lines (41 loc) · 1.5 KB
/
tag_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# Copyright (c) 2019 Foundries.io
# SPDX-License-Identifier: BSD-3-Clause
class TagMgr:
def __init__(self, ota_lite_tag=''):
# Convert thinkgs like:
# tag1,tag2 -> [(tag1, tag1), (tag2, tag2)]
# tag1:blah,tag2 -> [(tag1, blah), (tag2, tag2)]
self._tags = []
for x in ota_lite_tag.split(','):
parts = x.strip().split(':', 1)
if len(parts) == 1 or parts[1] == '':
self._tags.append((parts[0], parts[0]))
else:
self._tags.append((parts[0], parts[1]))
def __repr__(self):
return str(self._tags)
@property
def tags(self):
return self._tags
def intersection(self, tags):
if self._tags == [('', '')]:
# Factory doesn't use tags, so its good.
# This empty value is special and understood by the caller
yield ''
else:
for t in tags:
for target, parent in self._tags:
if t == parent:
yield target
def create_target_name(self, target, version, tag):
name = target['custom']['name'] + '-' + version
if len(self._tags) == 1:
return name
# we have more than one tag - so we need something else to make
# this dictionary key name unique:
return name + '-' + tag
@property
def target_tags(self):
"""Return the list of tags we should produce Targets for."""
return [x[0] for x in self._tags]