~gandelman-a/+junk/placement_policy

« back to all changes in this revision

Viewing changes to lib/permutations.py

  • Committer: Adam Gandelman
  • Date: 2013-10-30 04:23:13 UTC
  • Revision ID: adamg@canonical.com-20131030042313-6jm0m0u228u4vzw6
Checkin permutations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import os
 
3
import yaml
 
4
 
 
5
OS_CI_ROOT = os.getenv('OS_CI_ROOT', '/home/ubuntu/src/ods-demo')
 
6
 
 
7
 
 
8
def load_data():
 
9
    cfg = os.path.join(OS_CI_ROOT, 'etc', 'permutations.yaml')
 
10
    return yaml.load(open(cfg))
 
11
 
 
12
 
 
13
def resolve(made, paths, order, components):
 
14
    # populate 'paths' with all potential paths through order
 
15
    if len(made) == len(order):
 
16
        paths.append(made)
 
17
        return
 
18
 
 
19
    decision = order[len(made)]
 
20
    choices = components[decision]
 
21
 
 
22
    for choice in choices:
 
23
        resolve(made + [choice], paths, order, components)
 
24
 
 
25
    return paths
 
26
 
 
27
 
 
28
def get_permutations():
 
29
    data = load_data()
 
30
    order = data['order']
 
31
    components = data['components']
 
32
    paths = []
 
33
    for path in resolve([], [], order, components):
 
34
        valid = True
 
35
        for (choice, conflicts) in data['blacklists'].items():
 
36
            for conflict in conflicts:
 
37
                if choice in path and conflict in path:
 
38
                    valid = False
 
39
                    break
 
40
            if not valid:
 
41
                break
 
42
        if valid:
 
43
            paths.append(path)
 
44
 
 
45
    return paths