summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/conf.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/conf.py')
-rw-r--r--scripts/lib/wic/conf.py103
1 files changed, 0 insertions, 103 deletions
diff --git a/scripts/lib/wic/conf.py b/scripts/lib/wic/conf.py
deleted file mode 100644
index 070ec3096b..0000000000
--- a/scripts/lib/wic/conf.py
+++ /dev/null
@@ -1,103 +0,0 @@
1#!/usr/bin/env python -tt
2#
3# Copyright (c) 2011 Intel, Inc.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the Free
7# Software Foundation; version 2 of the License
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12# for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18import os
19
20from wic.ksparser import KickStart, KickStartError
21from wic import msger
22from wic.utils import misc
23
24
25def get_siteconf():
26 wic_path = os.path.dirname(__file__)
27 eos = wic_path.find('scripts') + len('scripts')
28 scripts_path = wic_path[:eos]
29
30 return scripts_path + "/lib/image/config/wic.conf"
31
32class ConfigMgr(object):
33 DEFAULTS = {
34 'common': {
35 "distro_name": "Default Distribution",
36 "plugin_dir": "/usr/lib/wic/plugins"}, # TODO use prefix also?
37 'create': {
38 "tmpdir": '/var/tmp/wic',
39 "outdir": './wic-output',
40 "release": None,
41 "logfile": None,
42 "name_prefix": None,
43 "name_suffix": None}
44 }
45
46 # make the manager class as singleton
47 _instance = None
48 def __new__(cls, *args, **kwargs):
49 if not cls._instance:
50 cls._instance = super(ConfigMgr, cls).__new__(cls, *args, **kwargs)
51
52 return cls._instance
53
54 def __init__(self, ksconf=None, siteconf=None):
55 # reset config options
56 self.reset()
57
58 if not siteconf:
59 siteconf = get_siteconf()
60
61 # initial options from siteconf
62 self._siteconf = siteconf
63
64 if ksconf:
65 self._ksconf = ksconf
66
67 def reset(self):
68 self.__ksconf = None
69 self.__siteconf = None
70 self.create = {}
71
72 # initialize the values with defaults
73 for sec, vals in self.DEFAULTS.items():
74 setattr(self, sec, vals)
75
76 def __set_ksconf(self, ksconf):
77 if not os.path.isfile(ksconf):
78 msger.error('Cannot find ks file: %s' % ksconf)
79
80 self.__ksconf = ksconf
81 self._parse_kickstart(ksconf)
82 def __get_ksconf(self):
83 return self.__ksconf
84 _ksconf = property(__get_ksconf, __set_ksconf)
85
86 def _parse_kickstart(self, ksconf=None):
87 if not ksconf:
88 return
89
90 try:
91 ksobj = KickStart(ksconf)
92 except KickStartError as err:
93 msger.error(str(err))
94
95 self.create['ks'] = ksobj
96 self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
97
98 self.create['name'] = misc.build_name(ksconf,
99 self.create['release'],
100 self.create['name_prefix'],
101 self.create['name_suffix'])
102
103configmgr = ConfigMgr()