Xen Test Framework
mkcfg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Construct an xl configuration file for a test (from various fragments), and
5 substitue variables appropriately.
6 """
7 import os
8 import sys
9 
10 # Usage: mkcfg.py $OUT $DEFAULT-CFG $EXTRA-CFG $VARY-CFG
11 _, out, defcfg, vcpus, extracfg, varycfg = sys.argv
12 
13 # Evaluate environment and name from $OUT
14 _, env, name = out.split('.')[0].split('-', 2)
15 
16 # Possibly split apart the variation suffix
17 variation = ''
18 if '~' in name:
19  parts = name.split('~', 1)
20  name, variation = parts[0], '~' + parts[1]
21 
22 def expand(text):
23  """ Expand certain variables in text """
24  return (text
25  .replace("@@NAME@@", name)
26  .replace("@@ENV@@", env)
27  .replace("@@VCPUS@@", vcpus)
28  .replace("@@XTFDIR@@", os.environ["xtfdir"])
29  .replace("@@VARIATION@@", variation)
30  )
31 
32 config = open(defcfg).read()
33 
34 if extracfg:
35  config += "\n# Test Extra Configuration:\n"
36  config += open(extracfg).read()
37 
38 if varycfg:
39  config += "\n# Test Variation Configuration:\n"
40  config += open(varycfg).read()
41 
42 cfg = expand(config)
43 
44 open(out, "w").write(cfg)
def expand(text)
Definition: mkcfg.py:22