diff options
Diffstat (limited to 'scripts/lib/mic/conf.py')
| -rw-r--r-- | scripts/lib/mic/conf.py | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/scripts/lib/mic/conf.py b/scripts/lib/mic/conf.py deleted file mode 100644 index a686e9caa7..0000000000 --- a/scripts/lib/mic/conf.py +++ /dev/null | |||
| @@ -1,102 +0,0 @@ | |||
| 1 | #!/usr/bin/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 | |||
| 18 | import os, sys, re | ||
| 19 | import ConfigParser | ||
| 20 | |||
| 21 | from mic import msger | ||
| 22 | from mic import kickstart | ||
| 23 | from mic.utils import misc, runner, errors | ||
| 24 | |||
| 25 | |||
| 26 | def get_siteconf(): | ||
| 27 | mic_path = os.path.dirname(__file__) | ||
| 28 | eos = mic_path.find('scripts') + len('scripts') | ||
| 29 | scripts_path = mic_path[:eos] | ||
| 30 | |||
| 31 | return scripts_path + "/lib/image/config/wic.conf" | ||
| 32 | |||
| 33 | class ConfigMgr(object): | ||
| 34 | DEFAULTS = {'common': { | ||
| 35 | "distro_name": "Default Distribution", | ||
| 36 | "plugin_dir": "/usr/lib/wic/plugins", # TODO use prefix also? | ||
| 37 | }, | ||
| 38 | 'create': { | ||
| 39 | "tmpdir": '/var/tmp/wic', | ||
| 40 | "outdir": './wic-output', | ||
| 41 | |||
| 42 | "release": None, | ||
| 43 | "logfile": None, | ||
| 44 | "name_prefix": None, | ||
| 45 | "name_suffix": None, | ||
| 46 | }, | ||
| 47 | } | ||
| 48 | |||
| 49 | # make the manager class as singleton | ||
| 50 | _instance = None | ||
| 51 | def __new__(cls, *args, **kwargs): | ||
| 52 | if not cls._instance: | ||
| 53 | cls._instance = super(ConfigMgr, cls).__new__(cls, *args, **kwargs) | ||
| 54 | |||
| 55 | return cls._instance | ||
| 56 | |||
| 57 | def __init__(self, ksconf=None, siteconf=None): | ||
| 58 | # reset config options | ||
| 59 | self.reset() | ||
| 60 | |||
| 61 | if not siteconf: | ||
| 62 | siteconf = get_siteconf() | ||
| 63 | |||
| 64 | # initial options from siteconf | ||
| 65 | self._siteconf = siteconf | ||
| 66 | |||
| 67 | if ksconf: | ||
| 68 | self._ksconf = ksconf | ||
| 69 | |||
| 70 | def reset(self): | ||
| 71 | self.__ksconf = None | ||
| 72 | self.__siteconf = None | ||
| 73 | |||
| 74 | # initialize the values with defaults | ||
| 75 | for sec, vals in self.DEFAULTS.iteritems(): | ||
| 76 | setattr(self, sec, vals) | ||
| 77 | |||
| 78 | def __set_ksconf(self, ksconf): | ||
| 79 | if not os.path.isfile(ksconf): | ||
| 80 | msger.error('Cannot find ks file: %s' % ksconf) | ||
| 81 | |||
| 82 | self.__ksconf = ksconf | ||
| 83 | self._parse_kickstart(ksconf) | ||
| 84 | def __get_ksconf(self): | ||
| 85 | return self.__ksconf | ||
| 86 | _ksconf = property(__get_ksconf, __set_ksconf) | ||
| 87 | |||
| 88 | def _parse_kickstart(self, ksconf=None): | ||
| 89 | if not ksconf: | ||
| 90 | return | ||
| 91 | |||
| 92 | ks = kickstart.read_kickstart(ksconf) | ||
| 93 | |||
| 94 | self.create['ks'] = ks | ||
| 95 | self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0] | ||
| 96 | |||
| 97 | self.create['name'] = misc.build_name(ksconf, | ||
| 98 | self.create['release'], | ||
| 99 | self.create['name_prefix'], | ||
| 100 | self.create['name_suffix']) | ||
| 101 | |||
| 102 | configmgr = ConfigMgr() | ||
