示例#1
0
 def testDebug(self):
     excepted = "Debug: hello\n"
     msger.debug("hello")
     self.assertEqual("", sys.stdout.getvalue())
     msger.set_loglevel("debug")
     msger.debug("hello")
     self.assertEqual(excepted, sys.stderr.getvalue())
示例#2
0
 def setUp(self):
     self.stdout = sys.stdout
     self.stderr = sys.stderr
     sys.stdout = StringIO.StringIO()
     sys.stderr = StringIO.StringIO()
     msger.set_loglevel('normal')
     self.loglevel = msger.LOG_LEVEL
示例#3
0
文件: test_msger.py 项目: ronan22/mic
 def testDebug(self):
     excepted = "Debug: hello\n"
     msger.debug("hello")
     self.assertEqual("", sys.stdout.getvalue())
     msger.set_loglevel("debug")
     msger.debug("hello")
     self.assertEqual(excepted, sys.stderr.getvalue())
示例#4
0
文件: test_msger.py 项目: ronan22/mic
 def testVerbose(self):
     excepted = "Verbose: hello\n"
     msger.verbose("hello")
     self.assertEqual("", sys.stdout.getvalue())
     msger.set_loglevel("verbose")
     msger.verbose("hello")
     self.assertEqual(excepted, sys.stdout.getvalue())
示例#5
0
文件: test_msger.py 项目: ronan22/mic
 def setUp(self):
     self.stdout = sys.stdout
     self.stderr = sys.stderr
     sys.stdout = StringIO.StringIO()
     sys.stderr = StringIO.StringIO()
     msger.set_loglevel('normal')
     self.loglevel = msger.LOG_LEVEL
示例#6
0
 def testVerbose(self):
     excepted = "Verbose: hello\n"
     msger.verbose("hello")
     self.assertEqual("", sys.stdout.getvalue())
     msger.set_loglevel("verbose")
     msger.verbose("hello")
     self.assertEqual(excepted, sys.stdout.getvalue())
示例#7
0
文件: rt_util.py 项目: martyone/mic
def select_bootstrap(repomd, cachedir, bootstrapdir):
    cfgmgr = configmgr
    lvl = msger.get_loglevel()
    msger.set_loglevel('quiet')
    repo_rpmver = misc.get_rpmver_in_repo(repomd)
    if not repo_rpmver:
        msger.set_loglevel(lvl)
        return (None, None)

    # Check avaliable bootstrap
    bootstrap_env = bootstrap.Bootstrap(homedir=bootstrapdir)
    for bs in bootstrap_env.list():
        if compare_rpmversion(repo_rpmver, bs['rpm']):
            return (bs['name'], {})

    for bsname, bsrepo in list(cfgmgr.bootstraps.items()):
        repolist = []
        for repo in list(bsrepo.keys()):
            repolist.append(bsrepo[repo])

        rpmver = None
        try:
            repomd = misc.get_metadata_from_repos(repolist, cachedir)
            rpmver = misc.get_rpmver_in_repo(repomd)
        except errors.CreatorError as e:
            msger.set_loglevel(lvl)
            raise

        if not rpmver:
            continue
        if compare_rpmversion(repo_rpmver, rpmver):
            msger.set_loglevel(lvl)
            return (bsname, bsrepo)
    msger.set_loglevel(lvl)
    return (None, None)
示例#8
0
文件: creator.py 项目: csdb/mic
    def postoptparse(self):
        if self.options.verbose:
            msger.set_loglevel('verbose')
        if self.options.debug:
            msger.set_loglevel('debug')

        if self.options.logfile:
            msger.set_interactive(False)
            msger.set_logfile(self.options.logfile)
            configmgr.create['logfile'] = self.options.logfile

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = self.options.outdir
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = self.options.cachedir
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']
        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                msger.error('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'content', 'license'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "content", "license"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage('Invalid architecture: "%s".\n'
                                   '  Supported architectures are: \n'
                                   '  %s\n' % (self.options.arch,
                                               ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.create['runtime'] = self.options.runtime

        if self.options.compress_disk_image is not None:
            configmgr.create['compress_disk_image'] = \
                                                self.options.compress_disk_image
示例#9
0
    def postoptparse(self):
        if self.options.verbose:
            msger.set_loglevel('verbose')
        if self.options.debug:
            msger.set_loglevel('debug')

        if self.options.logfile:
            msger.set_interactive(False)
            msger.set_logfile(self.options.logfile)
            configmgr.create['logfile'] = self.options.logfile

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = self.options.outdir
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = self.options.cachedir
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']
        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                msger.error('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'content', 'license'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "content", "license"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage(
                    'Invalid architecture: "%s".\n'
                    '  Supported architectures are: \n'
                    '  %s\n' % (self.options.arch, ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.create['runtime'] = self.options.runtime

        if self.options.compress_disk_image is not None:
            configmgr.create['compress_disk_image'] = \
                                                self.options.compress_disk_image
示例#10
0
 def setUp(self):
     self.stdout = sys.stdout
     self.stream = sys.stdout
     msger.STREAM = StringIO.StringIO()
     shutil.copy2(KSCONF, KSBAK)
     with open(KSCONF, 'r') as f:
         content = f.read()
     content = content.replace('$$$$$$', "file://" + REPOURI)
     with open(KSCONF, 'w') as f:
         f.write(content)
     msger.set_loglevel('quiet')
示例#11
0
 def setUp(self):
     self.stdout = sys.stdout
     self.stream = sys.stdout
     msger.STREAM = StringIO.StringIO()
     shutil.copy2(KSCONF, KSBAK)
     with open(KSCONF, 'r') as f:
         content = f.read()
     content = content.replace('$$$$$$', "file://" + REPOURI)
     with open(KSCONF, 'w') as f:
         f.write(content)
     msger.set_loglevel('quiet')
示例#12
0
 def setUp(self):
     self.configmgr = conf.ConfigMgr(siteconf=SITECONF)
     shutil.copy2(KSCONF, KSBAK)
     with open(KSCONF, 'r') as f:
         content = f.read()
     content = content.replace('$$$$$$', "file://" + REPOURI)
     with open(KSCONF, 'w') as f:
         f.write(content)
     if not os.path.exists(CACHEDIR):
         os.makedirs(CACHEDIR)
     self.configmgr.create['cachedir'] = CACHEDIR
     self.level = msger.get_loglevel()
     msger.set_loglevel('RAWTEXT')
示例#13
0
文件: rt_util.py 项目: saukko/mic
def select_bootstrap(repomd, cachedir, bootstrapdir):
    cfgmgr = configmgr
    lvl = msger.get_loglevel()
    msger.set_loglevel('quiet')
    repo_rpmver = misc.get_rpmver_in_repo(repomd)
    if not repo_rpmver:
        msger.set_loglevel(lvl)
        return (None, None)

    # Check avaliable bootstrap
    bootstrap_env = bootstrap.Bootstrap(homedir = bootstrapdir)
    for bs in bootstrap_env.list():
        if compare_rpmversion(repo_rpmver, bs['rpm']):
            return (bs['name'], {})

    for bsname, bsrepo in cfgmgr.bootstraps.items():
        repolist = []
        for repo in bsrepo.keys():
            repolist.append(bsrepo[repo])

        rpmver = None
        try:
            repomd = misc.get_metadata_from_repos(repolist, cachedir)
            rpmver = misc.get_rpmver_in_repo(repomd)
        except errors.CreatorError, e:
            msger.set_loglevel(lvl)
            raise

        if not rpmver:
            continue
        if compare_rpmversion(repo_rpmver, rpmver):
            msger.set_loglevel(lvl)
            return (bsname, bsrepo)
示例#14
0
文件: test_msger.py 项目: ronan22/mic
 def testLoglevel(self):
     # test default value
     self.assertEqual("normal", msger.get_loglevel())
     # test no effect value
     msger.set_loglevel("zzzzzz")
     self.assertEqual("normal", msger.get_loglevel())
     # test effect value
     msger.set_loglevel("verbose")
     self.assertEqual("verbose", msger.get_loglevel())
     msger.set_loglevel("debug")
     self.assertEqual("debug", msger.get_loglevel())
     msger.set_loglevel("quiet")
     self.assertEqual("quiet", msger.get_loglevel())
示例#15
0
 def testLoglevel(self):
     # test default value
     self.assertEqual("normal", msger.get_loglevel())
     # test no effect value
     msger.set_loglevel("zzzzzz")
     self.assertEqual("normal", msger.get_loglevel())
     # test effect value
     msger.set_loglevel("verbose")
     self.assertEqual("verbose", msger.get_loglevel())
     msger.set_loglevel("debug")
     self.assertEqual("debug", msger.get_loglevel())
     msger.set_loglevel("quiet")
     self.assertEqual("quiet", msger.get_loglevel())
示例#16
0
    def run(self, name, cmd, chdir='/', bindmounts=None):
        self.rootdir = name
        def mychroot():
            os.chroot(self.rootdir)
            os.chdir(chdir)

        if isinstance(cmd, list):
            cmd = ' '.join(cmd)

        lvl = msger.get_loglevel()
        msger.set_loglevel('quiet')
        globalmounts = chroot.setup_chrootenv(self.rootdir, bindmounts)
        try:
            proxy.set_proxy_environ()
            subprocess.call(cmd, preexec_fn=mychroot, shell=True)
            proxy.unset_proxy_environ()
        except:
            raise errors.BootstrapError("Run in bootstrap fail")
        finally:
            chroot.cleanup_chrootenv(self.rootdir, bindmounts, globalmounts)

        msger.set_loglevel(lvl)
示例#17
0
def main(parser, args, argv):
    """mic create entry point."""
    #args is argparser namespace, argv is the input cmd line
    if args is None:
        raise errors.Usage("Invalid arguments")

    if not os.path.exists(args.ksfile):
        raise errors.CreatorError("Can't find the file: %s" % args.ksfile)

    if os.geteuid() != 0:
        msger.error("Root permission is required, abort")

    try:
        w = pwd.getpwuid(os.geteuid())
    except KeyError:
        msger.warning("Might fail in compressing stage for undetermined user")

    abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))
    if args.logfile:
        logfile_abs_path = abspath(args.logfile)
        if os.path.isdir(logfile_abs_path):
            raise errors.Usage("logfile's path %s should be file" %
                               args.logfile)
        configmgr.create['logfile'] = logfile_abs_path
        configmgr.set_logfile()

    if args.subcommand == "auto":
        do_auto(parser, args.ksfile, argv)
        return

    if args.interactive:
        msger.enable_interactive()
    else:
        msger.disable_interactive()

    if args.verbose:
        msger.set_loglevel('VERBOSE')

    if args.debug:
        try:
            import rpm
            rpm.setVerbosity(rpm.RPMLOG_NOTICE)
        except ImportError:
            pass

        msger.set_loglevel('DEBUG')

    #check the imager type
    createrClass = None
    for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
        if subcmd == args.subcommand and hasattr(klass, 'do_create'):
            createrClass = klass

    if createrClass is None:
        raise errors.CreatorError("Can't support subcommand %s" %
                                  args.subcommand)

    if args.config:
        configmgr.reset()
        configmgr._siteconf = args.config

    if args.outdir is not None:
        configmgr.create['outdir'] = abspath(args.outdir)
    if args.cachedir is not None:
        configmgr.create['cachedir'] = abspath(args.cachedir)
    os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

    for cdir in ('outdir', 'cachedir'):
        if os.path.exists(configmgr.create[cdir]) \
          and not os.path.isdir(configmgr.create[cdir]):
            raise errors.Usage('Invalid directory specified: %s' \
                               % configmgr.create[cdir])
        if not os.path.exists(configmgr.create[cdir]):
            os.makedirs(configmgr.create[cdir])
            if os.getenv('SUDO_UID', '') and os.getenv('SUDO_GID', ''):
                os.chown(configmgr.create[cdir], int(os.getenv('SUDO_UID')),
                         int(os.getenv('SUDO_GID')))

    if args.local_pkgs_path is not None:
        if not os.path.exists(args.local_pkgs_path):
            raise errors.Usage('Local pkgs directory: \'%s\' not exist' \
                          % args.local_pkgs_path)
        configmgr.create['local_pkgs_path'] = args.local_pkgs_path

    if args.release:
        configmgr.create['release'] = args.release.rstrip('/')

    if args.record_pkgs:
        configmgr.create['record_pkgs'] = []
        for infotype in args.record_pkgs.split(','):
            if infotype not in ('name', 'content', 'license', 'vcs'):
                raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                   ' "name", "content", "license", "vcs"' \
                                   % infotype)

            configmgr.create['record_pkgs'].append(infotype)

    if args.strict_mode:
        configmgr.create['strict_mode'] = args.strict_mode
    if args.arch is not None:
        supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
        if args.arch in supported_arch:
            configmgr.create['arch'] = args.arch
        else:
            raise errors.Usage('Invalid architecture: "%s".\n'
                               '  Supported architectures are: \n'
                               '  %s' % (args.arch, ', '.join(supported_arch)))

    if args.pkgmgr is not None:
        configmgr.create['pkgmgr'] = args.pkgmgr

    if args.runtime:
        configmgr.set_runtime(args.runtime)

    if args.pack_to is not None:
        configmgr.create['pack_to'] = args.pack_to

    if args.copy_kernel:
        configmgr.create['copy_kernel'] = args.copy_kernel

    if args.install_pkgs:
        configmgr.create['install_pkgs'] = []
        for pkgtype in args.install_pkgs.split(','):
            if pkgtype not in ('source', 'debuginfo', 'debugsource'):
                raise errors.Usage('Invalid parameter specified: "%s", '
                                   'valid values: source, debuginfo, '
                                   'debusource' % pkgtype)

            configmgr.create['install_pkgs'].append(pkgtype)

    if args.check_pkgs:
        for pkg in args.check_pkgs.split(','):
            configmgr.create['check_pkgs'].append(pkg)

    if args.enabletmpfs:
        configmgr.create['enabletmpfs'] = args.enabletmpfs

    if args.repourl:
        for item in args.repourl:
            try:
                key, val = item.split('=')
            except:
                continue
            configmgr.create['repourl'][key] = val

    if args.repo:
        for optvalue in args.repo:
            repo = {}
            for item in optvalue.split(';'):
                try:
                    key, val = item.split('=')
                except:
                    continue
                repo[key.strip()] = val.strip()
            if 'name' in repo:
                configmgr.create['extrarepos'][repo['name']] = repo

    if args.ignore_ksrepo:
        configmgr.create['ignore_ksrepo'] = args.ignore_ksrepo
    if args.run_script:
        configmgr.create['run_script'] = args.run_script
    if args.tpk_install:
        configmgr.create['tpk_install'] = args.tpk_install

    creater = createrClass()
    creater.do_create(args)
示例#18
0
文件: creator.py 项目: 01org/mic
    def postoptparse(self):
        abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))

        if self.options.verbose:
            msger.set_loglevel('VERBOSE')
        if self.options.debug:
            msger.set_loglevel('DEBUG')

        if self.options.logfile:
            logfile_abs_path = abspath(self.options.logfile)
            if os.path.isdir(logfile_abs_path):
                raise errors.Usage("logfile's path %s should be file"
                                   % self.options.logfile)
            configmgr.create['logfile'] = logfile_abs_path
            configmgr.set_logfile()

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = abspath(self.options.outdir)
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = abspath(self.options.cachedir)
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

        for cdir in ('outdir', 'cachedir'):
            if os.path.exists(configmgr.create[cdir]) \
              and not os.path.isdir(configmgr.create[cdir]):
                raise errors.Usage('Invalid directory specified: %s' \
                                   % configmgr.create[cdir])
            if not os.path.exists(configmgr.create[cdir]):
                os.makedirs(configmgr.create[cdir])
                if os.getenv('SUDO_UID', '') and os.getenv('SUDO_GID', ''):
                    os.chown(configmgr.create[cdir],
                             int(os.getenv('SUDO_UID')),
                             int(os.getenv('SUDO_GID')))

        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                raise errors.Usage('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release.rstrip('/')

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'content', 'license', 'vcs'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "content", "license", "vcs"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.strict_mode:
          configmgr.create['strict_mode'] = self.options.strict_mode
        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage('Invalid architecture: "%s".\n'
                                   '  Supported architectures are: \n'
                                   '  %s' % (self.options.arch,
                                               ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.set_runtime(self.options.runtime)

        if self.options.pack_to is not None:
            configmgr.create['pack_to'] = self.options.pack_to

        if self.options.copy_kernel:
            configmgr.create['copy_kernel'] = self.options.copy_kernel

        if self.options.install_pkgs:
            configmgr.create['install_pkgs'] = []
            for pkgtype in self.options.install_pkgs.split(','):
                if pkgtype not in ('source', 'debuginfo', 'debugsource'):
                    raise errors.Usage('Invalid parameter specified: "%s", '
                                       'valid values: source, debuginfo, '
                                       'debusource' % pkgtype)

                configmgr.create['install_pkgs'].append(pkgtype)

        if self.options.check_pkgs:
            for pkg in self.options.check_pkgs.split(','):
                configmgr.create['check_pkgs'].append(pkg)

        if self.options.enabletmpfs:
            configmgr.create['enabletmpfs'] = self.options.enabletmpfs

        if self.options.repourl:
            for item in self.options.repourl:
                try:
                    key, val = item.split('=')
                except:
                    continue
                configmgr.create['repourl'][key] = val

        if self.options.repo:
            for optvalue in self.options.repo:
                repo = {}
                for item in optvalue.split(';'):
                    try:
                        key, val = item.split('=')
                    except:
                        continue
                    repo[key.strip()] = val.strip()
                if 'name' in repo:
                    configmgr.create['extrarepos'][repo['name']] = repo

        if self.options.ignore_ksrepo:
            configmgr.create['ignore_ksrepo'] = self.options.ignore_ksrepo
示例#19
0
def wic_create(args,
               wks_file,
               rootfs_dir,
               bootimg_dir,
               kernel_dir,
               native_sysroot,
               hdddir,
               staging_data_dir,
               scripts_path,
               image_output_dir,
               debug,
               properties_file,
               properties=None):
    """
    Create image

    wks_file - user-defined OE kickstart file
    rootfs_dir - absolute path to the build's /rootfs dir
    bootimg_dir - absolute path to the build's boot artifacts directory
    kernel_dir - absolute path to the build's kernel directory
    native_sysroot - absolute path to the build's native sysroots dir
    hdddir - absolute path to the build's HDDDIR dir
    staging_data_dir - absolute path to the build's STAGING_DATA_DIR dir
    scripts_path - absolute path to /scripts dir
    image_output_dir - dirname to create for image
    properties_file - use values from this file if nonempty i.e no prompting
    properties - use values from this string if nonempty i.e no prompting

    Normally, the values for the build artifacts values are determined
    by 'wic -e' from the output of the 'bitbake -e' command given an
    image name e.g. 'core-image-minimal' and a given machine set in
    local.conf.  If that's the case, the variables get the following
    values from the output of 'bitbake -e':

    rootfs_dir:        IMAGE_ROOTFS
    kernel_dir:        STAGING_KERNEL_DIR
    native_sysroot:    STAGING_DIR_NATIVE
    hdddir:            HDDDIR
    staging_data_dir:  STAGING_DATA_DIR

    In the above case, bootimg_dir remains unset and the image
    creation code determines which of the passed-in directories to
    use.

    In the case where the values are passed in explicitly i.e 'wic -e'
    is not used but rather the individual 'wic' options are used to
    explicitly specify these values, hdddir and staging_data_dir will
    be unset, but bootimg_dir must be explicit i.e. explicitly set to
    either hdddir or staging_data_dir, depending on the image being
    generated.  The other values (rootfs_dir, kernel_dir, and
    native_sysroot) correspond to the same values found above via
    'bitbake -e').

    """
    try:
        oe_builddir = os.environ["BUILDDIR"]
    except KeyError:
        print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
        sys.exit(1)

    direct_args = list()
    direct_args.insert(0, oe_builddir)
    direct_args.insert(0, image_output_dir)
    direct_args.insert(0, wks_file)
    direct_args.insert(0, rootfs_dir)
    direct_args.insert(0, bootimg_dir)
    direct_args.insert(0, kernel_dir)
    direct_args.insert(0, native_sysroot)
    direct_args.insert(0, hdddir)
    direct_args.insert(0, staging_data_dir)
    direct_args.insert(0, "direct")

    if debug:
        msger.set_loglevel('debug')

    cr = creator.Creator()

    cr.main(direct_args)

    print "\nThe image(s) were created using OE kickstart file:\n  %s" % wks_file
示例#20
0
def wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
               native_sysroot, hdddir, staging_data_dir, scripts_path,
               image_output_dir, debug, properties_file, properties=None):
    """
    Create image

    wks_file - user-defined OE kickstart file
    rootfs_dir - absolute path to the build's /rootfs dir
    bootimg_dir - absolute path to the build's boot artifacts directory
    kernel_dir - absolute path to the build's kernel directory
    native_sysroot - absolute path to the build's native sysroots dir
    hdddir - absolute path to the build's HDDDIR dir
    staging_data_dir - absolute path to the build's STAGING_DATA_DIR dir
    scripts_path - absolute path to /scripts dir
    image_output_dir - dirname to create for image
    properties_file - use values from this file if nonempty i.e no prompting
    properties - use values from this string if nonempty i.e no prompting

    Normally, the values for the build artifacts values are determined
    by 'wic -e' from the output of the 'bitbake -e' command given an
    image name e.g. 'core-image-minimal' and a given machine set in
    local.conf.  If that's the case, the variables get the following
    values from the output of 'bitbake -e':

    rootfs_dir:        IMAGE_ROOTFS
    kernel_dir:        STAGING_KERNEL_DIR
    native_sysroot:    STAGING_DIR_NATIVE
    hdddir:            HDDDIR
    staging_data_dir:  STAGING_DATA_DIR

    In the above case, bootimg_dir remains unset and the image
    creation code determines which of the passed-in directories to
    use.

    In the case where the values are passed in explicitly i.e 'wic -e'
    is not used but rather the individual 'wic' options are used to
    explicitly specify these values, hdddir and staging_data_dir will
    be unset, but bootimg_dir must be explicit i.e. explicitly set to
    either hdddir or staging_data_dir, depending on the image being
    generated.  The other values (rootfs_dir, kernel_dir, and
    native_sysroot) correspond to the same values found above via
    'bitbake -e').

    """
    try:
        oe_builddir = os.environ["BUILDDIR"]
    except KeyError:
        print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
        sys.exit(1)

    direct_args = list()
    direct_args.insert(0, oe_builddir)
    direct_args.insert(0, image_output_dir)
    direct_args.insert(0, wks_file)
    direct_args.insert(0, rootfs_dir)
    direct_args.insert(0, bootimg_dir)
    direct_args.insert(0, kernel_dir)
    direct_args.insert(0, native_sysroot)
    direct_args.insert(0, hdddir)
    direct_args.insert(0, staging_data_dir)
    direct_args.insert(0, "direct")

    if debug:
        msger.set_loglevel('debug')

    cr = creator.Creator()

    cr.main(direct_args)

    print "\nThe image(s) were created using OE kickstart file:\n  %s" % wks_file
示例#21
0
文件: creator.py 项目: d0b3rm4n/mic
    def postoptparse(self):
        abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))

        if self.options.verbose:
            msger.set_loglevel('verbose')
        if self.options.debug:
            msger.set_loglevel('debug')

        if self.options.logfile:
            msger.set_interactive(False)
            msger.set_logfile(self.options.logfile)
            configmgr.create['logfile'] = self.options.logfile

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = abspath(self.options.outdir)
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = abspath(self.options.cachedir)
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                msger.error('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'url', 'content', 'license'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "url", "content", "license"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage('Invalid architecture: "%s".\n'
                                   '  Supported architectures are: \n'
                                   '  %s' % (self.options.arch,
                                               ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.create['runtime'] = self.options.runtime

        if self.options.pack_to is not None:
            configmgr.create['pack_to'] = self.options.pack_to

        if self.options.copy_kernel:
            configmgr.create['copy_kernel'] = self.options.copy_kernel

        if self.options.tokenmap:
            tokenmap = {}
            for pair in self.options.tokenmap.split(","):
                token, value = pair.split(":",1)
                tokenmap[token] = value

            if not "RELEASE" in tokenmap and self.options.release:
                tokenmap["RELEASE"] = self.options.release
            if not "BUILD_ID" in tokenmap and "RELEASE" in tokenmap:
                tokenmap["BUILD_ID"] = tokenmap["RELEASE"]

            configmgr.create['tokenmap'] = tokenmap
示例#22
0
 def tearDown(self):
     msger.set_loglevel(self.level)
     shutil.copy2(KSBAK, KSCONF)
     os.unlink(KSBAK)
     shutil.rmtree(CACHEDIR, ignore_errors = True)
示例#23
0
文件: rt_util.py 项目: saukko/mic
            repolist.append(bsrepo[repo])

        rpmver = None
        try:
            repomd = misc.get_metadata_from_repos(repolist, cachedir)
            rpmver = misc.get_rpmver_in_repo(repomd)
        except errors.CreatorError, e:
            msger.set_loglevel(lvl)
            raise

        if not rpmver:
            continue
        if compare_rpmversion(repo_rpmver, rpmver):
            msger.set_loglevel(lvl)
            return (bsname, bsrepo)
    msger.set_loglevel(lvl)
    return (None, None)

def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
    bootstrap_env = bootstrap.Bootstrap(homedir = opts['bootstrapdir'])
    bootstrap_lst = bootstrap_env.bootstraps
    setattr(bootstrap_env, 'rootdir', name)
    if not bootstrap_lst or not name in bootstrap_lst:
        msger.info("Creating bootstrap %s under %s" %  (name, bootstrap_env.homedir))
        bootstrap_env.create(name, repolist)

    msger.info("Use bootstrap: %s" % bootstrap_env.rootdir)
    # copy mic
    msger.info("Sync native mic to bootstrap")
    copy_mic(bootstrap_env.rootdir)
示例#24
0
文件: creator.py 项目: ronan22/mic
    def postoptparse(self):
        abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))

        if self.options.verbose:
            msger.set_loglevel('verbose')
        if self.options.debug:
            msger.set_loglevel('debug')

        if self.options.logfile:
            logfile_abs_path = abspath(self.options.logfile)
            if os.path.isdir(logfile_abs_path):
                raise errors.Usage("logfile's path %s should be file"
                                   % self.options.logfile)
            if not os.path.exists(os.path.dirname(logfile_abs_path)):
                os.makedirs(os.path.dirname(logfile_abs_path))
            msger.set_interactive(False)
            msger.set_logfile(logfile_abs_path)
            configmgr.create['logfile'] = self.options.logfile

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = abspath(self.options.outdir)
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = abspath(self.options.cachedir)
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

        for cdir in ('outdir', 'cachedir'):
            if os.path.exists(configmgr.create[cdir]) \
              and not os.path.isdir(configmgr.create[cdir]):
                msger.error('Invalid directory specified: %s' \
                            % configmgr.create[cdir])

        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                msger.error('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release.rstrip('/')

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'content', 'license', 'vcs'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "content", "license", "vcs"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage('Invalid architecture: "%s".\n'
                                   '  Supported architectures are: \n'
                                   '  %s' % (self.options.arch,
                                               ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.set_runtime(self.options.runtime)

        if self.options.pack_to is not None:
            configmgr.create['pack_to'] = self.options.pack_to

        if self.options.copy_kernel:
            configmgr.create['copy_kernel'] = self.options.copy_kernel

        if self.options.install_pkgs:
            configmgr.create['install_pkgs'] = []
            for pkgtype in self.options.install_pkgs.split(','):
                if pkgtype not in ('source', 'debuginfo', 'debugsource'):
                    raise errors.Usage('Invalid parameter specified: "%s", '
                                       'valid values: source, debuginfo, '
                                       'debusource' % pkgtype)

                configmgr.create['install_pkgs'].append(pkgtype)

        if self.options.enabletmpfs:
            configmgr.create['enabletmpfs'] = self.options.enabletmpfs

        if self.options.repourl:
            for item in self.options.repourl:
                try:
                    key, val = item.split('=')
                except:
                    continue
                configmgr.create['repourl'][key] = val
示例#25
0
    def postoptparse(self):
        abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))

        if self.options.verbose:
            msger.set_loglevel('verbose')
        if self.options.debug:
            msger.set_loglevel('debug')

        if self.options.logfile:
            logfile_abs_path = abspath(self.options.logfile)
            if os.path.isdir(logfile_abs_path):
                raise errors.Usage("logfile's path %s should be file"
                                   % self.options.logfile)
            if not os.path.exists(os.path.dirname(logfile_abs_path)):
                os.makedirs(os.path.dirname(logfile_abs_path))
            msger.set_interactive(False)
            msger.set_logfile(logfile_abs_path)
            configmgr.create['logfile'] = self.options.logfile

        if self.options.config:
            configmgr.reset()
            configmgr._siteconf = self.options.config

        if self.options.outdir is not None:
            configmgr.create['outdir'] = abspath(self.options.outdir)
        if self.options.cachedir is not None:
            configmgr.create['cachedir'] = abspath(self.options.cachedir)
        os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

        for cdir in ('outdir', 'cachedir'):
            if os.path.exists(configmgr.create[cdir]) \
              and not os.path.isdir(configmgr.create[cdir]):
                msger.error('Invalid directory specified: %s' \
                            % configmgr.create[cdir])

        if self.options.local_pkgs_path is not None:
            if not os.path.exists(self.options.local_pkgs_path):
                msger.error('Local pkgs directory: \'%s\' not exist' \
                              % self.options.local_pkgs_path)
            configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path

        if self.options.release:
            configmgr.create['release'] = self.options.release

        if self.options.record_pkgs:
            configmgr.create['record_pkgs'] = []
            for infotype in self.options.record_pkgs.split(','):
                if infotype not in ('name', 'content', 'license', 'vcs'):
                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
                                       ' "name", "content", "license", "vcs"' \
                                       % infotype)

                configmgr.create['record_pkgs'].append(infotype)

        if self.options.arch is not None:
            supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
            if self.options.arch in supported_arch:
                configmgr.create['arch'] = self.options.arch
            else:
                raise errors.Usage('Invalid architecture: "%s".\n'
                                   '  Supported architectures are: \n'
                                   '  %s' % (self.options.arch,
                                               ', '.join(supported_arch)))

        if self.options.pkgmgr is not None:
            configmgr.create['pkgmgr'] = self.options.pkgmgr

        if self.options.runtime:
            configmgr.set_runtime(self.options.runtime)

        if self.options.pack_to is not None:
            configmgr.create['pack_to'] = self.options.pack_to

        if self.options.copy_kernel:
            configmgr.create['copy_kernel'] = self.options.copy_kernel

        if self.options.install_pkgs:
            configmgr.create['install_pkgs'] = []
            for pkgtype in self.options.install_pkgs.split(','):
                if pkgtype not in ('source', 'debuginfo', 'debugsource'):
                    raise errors.Usage('Invalid parameter specified: "%s", '
                                       'valid values: source, debuginfo, '
                                       'debusource' % pkgtype)

                configmgr.create['install_pkgs'].append(pkgtype)

        if self.options.repourl:
            for item in self.options.repourl:
                try:
                    key, val = item.split('=')
                except:
                    continue
                configmgr.create['repourl'][key] = val
示例#26
0
            repolist.append(bsrepo[repo])

        rpmver = None
        try:
            repomd = misc.get_metadata_from_repos(repolist, cachedir)
            rpmver = misc.get_rpmver_in_repo(repomd)
        except errors.CreatorError, e:
            msger.set_loglevel(lvl)
            raise

        if not rpmver:
            continue
        if compare_rpmversion(repo_rpmver, rpmver):
            msger.set_loglevel(lvl)
            return (bsname, bsrepo)
    msger.set_loglevel(lvl)
    return (None, None)


def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
    bootstrap_env = bootstrap.Bootstrap(homedir=opts['bootstrapdir'])
    bootstrap_lst = bootstrap_env.bootstraps
    setattr(bootstrap_env, 'rootdir', name)
    if not bootstrap_lst or not name in bootstrap_lst:
        msger.info("Creating bootstrap %s under %s" %
                   (name, bootstrap_env.homedir))
        bootstrap_env.create(name, repolist)

    msger.info("Use bootstrap: %s" % bootstrap_env.rootdir)
    # copy mic
    msger.info("Sync native mic to bootstrap")