This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
should-I-boot-this.py
executable file
·74 lines (64 loc) · 2.54 KB
/
should-I-boot-this.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright (C) 2017 Free Electrons SAS
# Author: Florent Jacquet <[email protected]>
#
# This module is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
import sys
import configparser
"""
To test the script, just export those variables and play with their values
export LAB=lab-free-electrons
export TREE=mainline
"""
config = configparser.ConfigParser()
config.read('labs.ini')
lab_name = os.environ['LAB']
tree_name = os.environ['TREE']
branch = os.environ['BRANCH']
# Is the lab existing?
if lab_name not in config.sections():
print("Unknown lab '{}'. refusing boot of tree '{}' as config is needed.".format(
lab_name, tree_name))
sys.exit(1)
lab = config[lab_name]
# Is the tree whitelisted for this lab
lab_tree_whitelist = lab.get('tree_whitelist')
if lab_tree_whitelist:
whitelisted_trees = lab_tree_whitelist.split()
for whitelisted_tree in whitelisted_trees:
if '#' in whitelisted_tree:
w_tree = whitelisted_tree.split('#')[0]
w_branch = whitelisted_tree.split('#')[1]
if tree_name == w_tree and branch == w_branch:
print("Tree {} and branch {} is whitelisted for lab {}". format(tree_name, branch, lab_name))
sys.exit(0)
else:
if tree_name == whitelisted_tree:
print("Tree {} is whitelisted for lab {}". format(tree_name, lab_name))
sys.exit(0)
print("Tree {} is not whitelisted for lab {}".format(tree_name, lab_name))
sys.exit(1)
# Is the tree blacklisted for this lab?
lab_tree_blacklist = lab.get('tree_blacklist')
if lab_tree_blacklist and tree_name in lab_tree_blacklist.split():
print("Tree '{}' is blacklisted for lab '{}'".format(
tree_name, lab_name))
sys.exit(1)
print("Booting tree '{}' is allowed for lab '{}'".format(
tree_name, lab_name))
sys.exit(0)