Passed
Pull Request — master (#4216)
by Matěj
02:33 queued 10s
created

ssg.products.map_name()   A

Complexity

Conditions 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 13
nop 1
dl 0
loc 21
rs 9.2833
c 0
b 0
f 0
ccs 10
cts 10
cp 1
crap 5
1 2
from __future__ import absolute_import
2 2
from __future__ import print_function
3
4 2
import os
5 2
from collections import namedtuple
6
7 2
from .constants import product_directories
8 2
from .yaml import open_raw
9
10
11 2
def get_all(ssg_root):
12
    """
13
    Analyzes all products in the SSG root and sorts them into two categories:
14
    those which use linux_os and those which use their own directory. Returns
15
    a namedtuple of sets, (linux, other).
16
    """
17
18 2
    linux_products = set()
19 2
    other_products = set()
20
21 2
    for product in product_directories:
22 2
        product_dir = os.path.join(ssg_root, product)
23 2
        product_yaml_path = os.path.join(product_dir, "product.yml")
24 2
        product_yaml = open_raw(product_yaml_path)
25
26 2
        guide_dir = os.path.join(product_dir, product_yaml['benchmark_root'])
27 2
        guide_dir = os.path.abspath(guide_dir)
28
29 2
        if 'linux_os' in guide_dir:
30 2
            linux_products.add(product)
31
        else:
32 2
            other_products.add(product)
33
34 2
    products = namedtuple('products', ['linux', 'other'])
35
    return products(linux_products, other_products)
36