[RIFT 16413, 16414] Unittest failures fixed for utest_package, utest_publisher_dts
[osm/SO.git] / rwlaunchpad / plugins / rwlaunchpadtasklet / rift / package / image.py
1
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 import re
19
20 IMAGE_REGEX = r"{prefix}/?images/(?P<image_name>[^/]+.\.qcow2)$"
21
22
23 def is_image_file(image_path):
24 match = re.match(
25 IMAGE_REGEX.format(prefix=".*"),
26 image_path,
27 )
28
29 return match is not None
30
31
32 def get_package_image_files(package):
33 """ Return a image name/file map for images in the descriptor
34
35 Arguments:
36 package - A DescriptorPackage
37
38 Returns:
39 A dictionary mapping image names to the relative path within
40 the package.
41 """
42 image_file_map = {}
43
44 for file_name in package.files:
45 match = re.match(
46 IMAGE_REGEX.format(prefix=package.prefix),
47 file_name,
48 )
49 if match is None:
50 continue
51
52 image_name = match.group("image_name")
53 image_file_map[image_name] = file_name
54
55 return image_file_map