summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/conf.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-08-24 15:31:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch)
tree63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/conf.py
parent53a1d9a788fd9f970af980da2ab975cca60685c4 (diff)
downloadast2050-yocto-poky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.zip
ast2050-yocto-poky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/conf.py')
-rw-r--r--scripts/lib/mic/conf.py239
1 files changed, 239 insertions, 0 deletions
diff --git a/scripts/lib/mic/conf.py b/scripts/lib/mic/conf.py
new file mode 100644
index 0000000..e37334c
--- /dev/null
+++ b/scripts/lib/mic/conf.py
@@ -0,0 +1,239 @@
+#!/usr/bin/python -tt
+#
+# Copyright (c) 2011 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import os, sys, re
+import ConfigParser
+
+from mic import msger
+from mic import kickstart
+from mic.utils import misc, runner, proxy, errors
+
+
+DEFAULT_GSITECONF = '/etc/mic/mic.conf'
+
+
+def get_siteconf():
+ mic_path = os.path.dirname(__file__)
+
+ m = re.match(r"(?P<prefix>.*)\/lib(64)?\/.*", mic_path)
+ if m and m.group('prefix') != "/usr":
+ return os.path.join(m.group('prefix'), "etc/mic/mic.conf")
+
+ return DEFAULT_GSITECONF
+
+class ConfigMgr(object):
+ prefer_backends = ["zypp", "yum"]
+
+ DEFAULTS = {'common': {
+ "distro_name": "Default Distribution",
+ "plugin_dir": "/usr/lib/mic/plugins", # TODO use prefix also?
+ },
+ 'create': {
+ "tmpdir": '/var/tmp/mic',
+ "cachedir": '/var/tmp/mic/cache',
+ "outdir": './mic-output',
+
+ "arch": None, # None means auto-detect
+ "pkgmgr": "auto",
+ "name": "output",
+ "ksfile": None,
+ "ks": None,
+ "repomd": None,
+ "local_pkgs_path": None,
+ "release": None,
+ "logfile": None,
+ "record_pkgs": [],
+ "pack_to": None,
+ "name_prefix": None,
+ "name_suffix": None,
+ "proxy": None,
+ "no_proxy": None,
+ "copy_kernel": False,
+ "install_pkgs": None,
+ "repourl": {},
+ "localrepos": [], # save localrepos
+ "runtime": "bootstrap",
+ },
+ 'chroot': {
+ "saveto": None,
+ },
+ 'convert': {
+ "shell": False,
+ },
+ 'bootstrap': {
+ "rootdir": '/var/tmp/mic-bootstrap',
+ "packages": [],
+ },
+ }
+
+ # make the manager class as singleton
+ _instance = None
+ def __new__(cls, *args, **kwargs):
+ if not cls._instance:
+ cls._instance = super(ConfigMgr, cls).__new__(cls, *args, **kwargs)
+
+ return cls._instance
+
+ def __init__(self, ksconf=None, siteconf=None):
+ # reset config options
+ self.reset()
+
+ if not siteconf:
+ siteconf = get_siteconf()
+
+ # initial options from siteconf
+ self._siteconf = siteconf
+
+ if ksconf:
+ self._ksconf = ksconf
+
+ def reset(self):
+ self.__ksconf = None
+ self.__siteconf = None
+
+ # initialize the values with defaults
+ for sec, vals in self.DEFAULTS.iteritems():
+ setattr(self, sec, vals)
+
+ def __set_siteconf(self, siteconf):
+ try:
+ self.__siteconf = siteconf
+ self._parse_siteconf(siteconf)
+ except ConfigParser.Error, error:
+ raise errors.ConfigError("%s" % error)
+ def __get_siteconf(self):
+ return self.__siteconf
+ _siteconf = property(__get_siteconf, __set_siteconf)
+
+ def __set_ksconf(self, ksconf):
+ if not os.path.isfile(ksconf):
+ msger.error('Cannot find ks file: %s' % ksconf)
+
+ self.__ksconf = ksconf
+ self._parse_kickstart(ksconf)
+ def __get_ksconf(self):
+ return self.__ksconf
+ _ksconf = property(__get_ksconf, __set_ksconf)
+
+ def _parse_siteconf(self, siteconf):
+ if not siteconf:
+ return
+
+ if not os.path.exists(siteconf):
+ msger.warning("cannot read config file: %s" % siteconf)
+ return
+
+ parser = ConfigParser.SafeConfigParser()
+ parser.read(siteconf)
+
+ for section in parser.sections():
+ if section in self.DEFAULTS:
+ getattr(self, section).update(dict(parser.items(section)))
+
+ # append common section items to other sections
+ for section in self.DEFAULTS.keys():
+ if section != "common":
+ getattr(self, section).update(self.common)
+
+ # check and normalize the scheme of proxy url
+ if self.create['proxy']:
+ m = re.match('^(\w+)://.*', self.create['proxy'])
+ if m:
+ scheme = m.group(1)
+ if scheme not in ('http', 'https', 'ftp', 'socks'):
+ msger.error("%s: proxy scheme is incorrect" % siteconf)
+ else:
+ msger.warning("%s: proxy url w/o scheme, use http as default"
+ % siteconf)
+ self.create['proxy'] = "http://" + self.create['proxy']
+
+ proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])
+
+ # bootstrap option handling
+ self.set_runtime(self.create['runtime'])
+ if isinstance(self.bootstrap['packages'], basestring):
+ packages = self.bootstrap['packages'].replace('\n', ' ')
+ if packages.find(',') != -1:
+ packages = packages.split(',')
+ else:
+ packages = packages.split()
+ self.bootstrap['packages'] = packages
+
+ def _parse_kickstart(self, ksconf=None):
+ if not ksconf:
+ return
+
+ ksconf = misc.normalize_ksfile(ksconf,
+ self.create['release'],
+ self.create['arch'])
+
+ ks = kickstart.read_kickstart(ksconf)
+
+ self.create['ks'] = ks
+ self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
+
+ self.create['name'] = misc.build_name(ksconf,
+ self.create['release'],
+ self.create['name_prefix'],
+ self.create['name_suffix'])
+
+ msger.info("Retrieving repo metadata:")
+ ksrepos = misc.get_repostrs_from_ks(ks)
+ if not ksrepos:
+ raise errors.KsError('no valid repos found in ks file')
+
+ for repo in ksrepos:
+ if 'baseurl' in repo and repo['baseurl'].startswith("file:"):
+ repourl = repo['baseurl'].replace('file:', '')
+ repourl = "/%s" % repourl.lstrip('/')
+ self.create['localrepos'].append(repourl)
+
+ self.create['repomd'] = misc.get_metadata_from_repos(
+ ksrepos,
+ self.create['cachedir'])
+ msger.raw(" DONE")
+
+ target_archlist, archlist = misc.get_arch(self.create['repomd'])
+ if self.create['arch']:
+ if self.create['arch'] not in archlist:
+ raise errors.ConfigError("Invalid arch %s for repository. "
+ "Valid arches: %s" \
+ % (self.create['arch'], ', '.join(archlist)))
+ else:
+ if len(target_archlist) == 1:
+ self.create['arch'] = str(target_archlist[0])
+ msger.info("\nUse detected arch %s." % target_archlist[0])
+ else:
+ raise errors.ConfigError("Please specify a valid arch, "
+ "the choice can be: %s" \
+ % ', '.join(archlist))
+
+ kickstart.resolve_groups(self.create, self.create['repomd'])
+
+ # check selinux, it will block arm and btrfs image creation
+ misc.selinux_check(self.create['arch'],
+ [p.fstype for p in ks.handler.partition.partitions])
+
+ def set_runtime(self, runtime):
+ if runtime not in ("bootstrap", "native"):
+ msger.error("Invalid runtime mode: %s" % runtime)
+
+ if misc.get_distro()[0] in ("tizen", "Tizen"):
+ runtime = "native"
+ self.create['runtime'] = runtime
+
+configmgr = ConfigMgr()
OpenPOWER on IntegriCloud