Xen Test Framework
mkcfg.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Construct an xl configuration file for a test (from various fragments), and
5substitue variables appropriately.
6"""
7import os
8import 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
17variation = ''
18if '~' in name:
19 parts = name.split('~', 1)
20 name, variation = parts[0], '~' + parts[1]
21
22def 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
32config = open(defcfg).read()
33
34if extracfg:
35 config += "\n# Test Extra Configuration:\n"
36 config += open(extracfg).read()
37
38if varycfg:
39 config += "\n# Test Variation Configuration:\n"
40 config += open(varycfg).read()
41
42cfg = expand(config)
43
44open(out, "w").write(cfg)
def expand(text)
Definition: mkcfg.py:22