3 # Copyright 2011 Intel, Inc.
5 # This copyrighted material is made available to anyone wishing to use, modify,
6 # copy, or redistribute it subject to the terms and conditions of the GNU
7 # General Public License v.2. This program is distributed in the hope that it
8 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
9 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along with
13 # this program; if not, write to the Free Software Foundation, Inc., 51
14 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
15 # trademarks that are incorporated in the source code or documentation are not
16 # subject to the GNU General Public License and may only be used or replicated
17 # with the express permission of Red Hat, Inc.
23 from mic import kickstart
25 from mic.utils import misc
26 from mic.utils import errors
28 DEFAULT_GSITECONF='/etc/mic/mic.conf'
31 DEFAULT_TMPDIR='/var/tmp/mic'
32 DEFAULT_CACHEDIR='/var/tmp/mic/cache'
35 "tmpdir": DEFAULT_TMPDIR,
36 "cachedir": DEFAULT_CACHEDIR,
37 "outdir": DEFAULT_OUTDIR,
44 "local_pkgs_path": None,
48 class ConfigMgr(object):
49 def __init__(self, ksconf=None, siteconf=None):
50 # reset config options
53 # initial options from siteconf
54 self._siteconf = siteconf
55 if not self.__siteconf:
56 self._siteconf = DEFAULT_GSITECONF
64 self.__siteconf = None
67 for key in DEFAULT_CREATE.keys():
68 self.create[key] = DEFAULT_CREATE[key]
70 def __set_siteconf(self, siteconf):
72 self.__siteconf = siteconf
73 self.parse_siteconf(siteconf)
74 except ConfigParser.Error, error:
75 raise errors.ConfigError("%s" % error)
76 def __get_siteconf(self):
77 return self.__siteconf
78 _siteconf = property(__get_siteconf, __set_siteconf)
80 def __set_ksconf(self, ksconf):
81 if not os.path.isfile(ksconf):
82 msger.error('Cannot find ks file: %s' % ksconf)
84 self.__ksconf = ksconf
85 self.parse_kickstart(ksconf)
86 def __get_ksconf(self):
88 _ksconf = property(__get_ksconf, __set_ksconf)
89 def parse_siteconf(self, siteconf = None):
93 from ConfigParser import SafeConfigParser
94 siteconf_parser = SafeConfigParser()
95 if not os.path.exists(siteconf):
96 raise errors.ConfigError("Failed to find config file: %s" % siteconf)
97 siteconf_parser.read(siteconf)
99 for option in siteconf_parser.options('common'):
100 value = siteconf_parser.get('common', option)
101 self.common[option] = value
103 for option in siteconf_parser.options('create'):
104 value = siteconf_parser.get('create', option)
105 self.create[option] = value
107 for option in siteconf_parser.options('convert'):
108 value = siteconf_parser.get('convert', option)
109 self.convert[option] = value
111 for option in siteconf_parser.options('chroot'):
112 value = siteconf_parser.get('chroot', option)
113 self.chroot[option] = value
115 def parse_kickstart(self, ksconf=None):
119 ks = kickstart.read_kickstart(ksconf)
121 self.create['ks'] = ks
122 self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
124 msger.info("Retrieving repo metadata:")
125 ksrepos = misc.get_repostrs_from_ks(ks)
126 self.create['repomd'] = misc.get_metadata_from_repos(ksrepos, self.create['cachedir'])
127 kickstart.resolve_groups(self.create, self.create['repomd'])
133 configmgr = ConfigMgr()