1
|
1 |
|
from __future__ import absolute_import |
|
|
|
|
2
|
1 |
|
from __future__ import print_function |
3
|
|
|
|
4
|
1 |
|
import re |
5
|
1 |
|
import os |
6
|
1 |
|
from collections import namedtuple |
7
|
|
|
|
8
|
1 |
|
from .constants import product_directories |
9
|
1 |
|
from .yaml import open_raw |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
# SSG Makefile to official product name mapping |
13
|
1 |
|
_version_name_map = { |
|
|
|
|
14
|
|
|
'chromium': 'Google Chromium Browser', |
15
|
|
|
'fedora': 'Fedora', |
16
|
|
|
'firefox': 'Mozilla Firefox', |
17
|
|
|
'jre': 'Java Runtime Environment', |
18
|
|
|
'rhel-osp': 'Red Hat OpenStack Platform', |
19
|
|
|
'rhel': 'Red Hat Enterprise Linux', |
20
|
|
|
'debian': 'Debian', |
21
|
|
|
'ubuntu': 'Ubuntu', |
22
|
|
|
'eap': 'JBoss Enterprise Application Platform', |
23
|
|
|
'fuse': 'JBoss Fuse', |
24
|
|
|
'opensuse': 'openSUSE', |
25
|
|
|
'sle': 'SUSE Linux Enterprise', |
26
|
|
|
'wrlinux': 'Wind River Linux', |
27
|
|
|
'ol': 'Oracle Linux', |
28
|
|
|
'ocp': 'Red Hat OpenShift Container Platform', |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
multi_list = ["rhel", "fedora", "rhel-osp", "debian", "ubuntu", |
|
|
|
|
32
|
|
|
"wrlinux", "opensuse", "sle", "ol", "ocp"] |
33
|
|
|
|
34
|
1 |
|
PRODUCT_NAME_PARSER = re.compile(r"([a-zA-Z\-]+)([0-9]+)") |
35
|
|
|
|
36
|
|
|
|
37
|
1 |
|
def parse_name(product): |
|
|
|
|
38
|
1 |
|
_product = product |
39
|
1 |
|
_product_version = None |
40
|
1 |
|
match = PRODUCT_NAME_PARSER.match(product) |
41
|
|
|
|
42
|
1 |
|
if match: |
43
|
1 |
|
_product = match.group(1) |
44
|
1 |
|
_product_version = match.group(2) |
45
|
|
|
|
46
|
1 |
|
return _product, _product_version |
47
|
|
|
|
48
|
|
|
|
49
|
1 |
|
def get_all(ssg_root): |
50
|
|
|
""" |
51
|
|
|
Analyzes all products in the SSG root and sorts them into two categories: |
52
|
|
|
those which use linux_os and those which use their own directory. Returns |
53
|
|
|
a namedtuple of sets, (linux, other). |
54
|
|
|
""" |
55
|
|
|
|
56
|
1 |
|
linux_products = set() |
57
|
1 |
|
other_products = set() |
58
|
|
|
|
59
|
1 |
|
for product in product_directories: |
60
|
1 |
|
product_dir = os.path.join(ssg_root, product) |
61
|
1 |
|
product_yaml_path = os.path.join(product_dir, "product.yml") |
62
|
1 |
|
product_yaml = open_raw(product_yaml_path) |
63
|
|
|
|
64
|
1 |
|
guide_dir = os.path.join(product_dir, product_yaml['benchmark_root']) |
65
|
1 |
|
guide_dir = os.path.abspath(guide_dir) |
66
|
|
|
|
67
|
1 |
|
if 'linux_os' in guide_dir: |
68
|
1 |
|
linux_products.add(product) |
69
|
|
|
else: |
70
|
1 |
|
other_products.add(product) |
71
|
|
|
|
72
|
1 |
|
products = namedtuple('products', ['linux', 'other']) |
73
|
1 |
|
return products(linux_products, other_products) |
74
|
|
|
|
75
|
|
|
|
76
|
1 |
|
def map_name(version): |
77
|
|
|
"""Maps SSG Makefile internal product name to official product name""" |
78
|
|
|
|
79
|
1 |
|
if version.startswith("multi_platform_"): |
80
|
|
|
trimmed_version = version[len("multi_platform_"):] |
81
|
|
|
if trimmed_version not in multi_list: |
82
|
|
|
raise RuntimeError( |
83
|
|
|
"%s is an invalid product version. If it's multi_platform the " |
84
|
|
|
"suffix has to be from (%s)." |
85
|
|
|
% (version, ", ".join(multi_list)) |
86
|
|
|
) |
87
|
|
|
return map_name(trimmed_version) |
88
|
|
|
|
89
|
|
|
# By sorting in reversed order, keys which are a longer version of other keys are |
90
|
|
|
# visited first (e.g., rhel-osp vs. rhel) |
91
|
1 |
|
for key in sorted(_version_name_map, reverse=True): |
92
|
1 |
|
if version.startswith(key): |
93
|
1 |
|
return _version_name_map[key] |
94
|
|
|
|
95
|
|
|
raise RuntimeError("Can't map version '%s' to any known product!" |
96
|
|
|
% (version)) |
97
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.