summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/utils/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/mic/utils/misc.py')
-rw-r--r--scripts/lib/mic/utils/misc.py48
1 files changed, 1 insertions, 47 deletions
diff --git a/scripts/lib/mic/utils/misc.py b/scripts/lib/mic/utils/misc.py
index 010b16ca49..194b88f691 100644
--- a/scripts/lib/mic/utils/misc.py
+++ b/scripts/lib/mic/utils/misc.py
@@ -19,11 +19,6 @@ import os
19import sys 19import sys
20import time 20import time
21 21
22from mic import msger
23from mic.utils.errors import CreatorError
24from mic.utils.fs_related import find_binary_path, makedirs
25from mic.utils import runner
26
27def build_name(kscfg, release=None, prefix = None, suffix = None): 22def build_name(kscfg, release=None, prefix = None, suffix = None):
28 """Construct and return an image name string. 23 """Construct and return an image name string.
29 24
@@ -60,46 +55,5 @@ def build_name(kscfg, release=None, prefix = None, suffix = None):
60 suffix = "-%s" % suffix if suffix else "" 55 suffix = "-%s" % suffix if suffix else ""
61 56
62 ret = prefix + name + suffix 57 ret = prefix + name + suffix
63 return ret
64
65def normalize_ksfile(ksconf, release, arch):
66 '''
67 Return the name of a normalized ks file in which macro variables
68 @BUILD_ID@ and @ARCH@ are replace with real values.
69
70 The original ks file is returned if no special macro is used, otherwise
71 a temp file is created and returned, which will be deleted when program
72 exits normally.
73 '''
74
75 if not release:
76 release = "latest"
77 if not arch or re.match(r'i.86', arch):
78 arch = "ia32"
79
80 with open(ksconf) as f:
81 ksc = f.read()
82
83 if "@ARCH@" not in ksc and "@BUILD_ID@" not in ksc:
84 return ksconf
85 58
86 msger.info("Substitute macro variable @BUILD_ID@/@ARCH@ in ks: %s" % ksconf) 59 return ret
87 ksc = ksc.replace("@ARCH@", arch)
88 ksc = ksc.replace("@BUILD_ID@", release)
89
90 fd, ksconf = tempfile.mkstemp(prefix=os.path.basename(ksconf))
91 os.write(fd, ksc)
92 os.close(fd)
93
94 msger.debug('normalized ks file:%s' % ksconf)
95
96 def remove_temp_ks():
97 try:
98 os.unlink(ksconf)
99 except OSError, err:
100 msger.warning('Failed to remove temp ks file:%s:%s' % (ksconf, err))
101
102 import atexit
103 atexit.register(remove_temp_ks)
104
105 return ksconf