예제 #1
0
    def prepare_image(self):
        if not self.args.filesystem:
            try:
                # Configure it with environment variables.
                env = {}
                if self.args.project is not None:
                    env['PROJECT'] = self.args.project
                if self.args.suite is not None:
                    env['SUITE'] = self.args.suite
                if self.args.arch is not None:
                    env['ARCH'] = self.args.arch
                if self.args.subproject is not None:
                    env['SUBPROJECT'] = self.args.subproject
                if self.args.subarch is not None:
                    env['SUBARCH'] = self.args.subarch
                if self.args.with_proposed:
                    env['PROPOSED'] = '1'
                if self.args.extra_ppas is not None:
                    env['EXTRA_PPAS'] = '******'.join(self.args.extra_ppas)
                # Only generate a single rootfs tree for classic images.
                env['IMAGEFORMAT'] = 'none'
                # ensure ARCH is set
                if self.args.arch is None:
                    env['ARCH'] = get_host_arch()
                live_build(self.unpackdir, env)
            except CalledProcessError:
                if self.args.debug:
                    _logger.exception('Full debug traceback follows')
                self.exitcode = 1
                # Stop the state machine here by not appending a next step.
                return

        super().prepare_image()
예제 #2
0
    def prepare_image(self):
        if not self.args.filesystem:
            try:
                # Configure it with environment variables.
                env = {}
                if self.args.project is not None:
                    env['PROJECT'] = self.args.project
                if self.args.suite is not None:
                    env['SUITE'] = self.args.suite
                if self.args.arch is not None:
                    env['ARCH'] = self.args.arch
                if self.args.subproject is not None:
                    env['SUBPROJECT'] = self.args.subproject
                if self.args.subarch is not None:
                    env['SUBARCH'] = self.args.subarch
                if self.args.with_proposed:
                    env['PROPOSED'] = '1'
                if self.args.extra_ppas is not None:
                    env['EXTRA_PPAS'] = '******'.join(self.args.extra_ppas)
                # Only generate a single rootfs tree for classic images.
                env['IMAGEFORMAT'] = 'none'
                # ensure ARCH is set
                if self.args.arch is None:
                    env['ARCH'] = get_host_arch()
                live_build(self.unpackdir, env)
            except CalledProcessError:
                if self.args.debug:
                    _logger.exception('Full debug traceback follows')
                self.exitcode = 1
                # Stop the state machine here by not appending a next step.
                return

        super().prepare_image()
예제 #3
0
 def test_get_host_arch(self):
     self.assertIsNotNone(get_host_arch())
예제 #4
0
def parseargs(argv=None):
    parser = argparse.ArgumentParser(
        prog=PROGRAM,
        description=_('Generate a bootable disk image.'),
        formatter_class=SimpleHelpFormatter)
    parser.add_argument('--version',
                        action='version',
                        version='{} {}'.format(PROGRAM, __version__))
    # create two subcommands, "snap" and "classic"
    subparser = parser.add_subparsers(title=_('Command'), dest='cmd')
    snap_cmd = subparser.add_parser(
        'snap', help=_("""Create snap-based Ubuntu Core image."""))
    classic_cmd = subparser.add_parser(
        'classic', help=_("""Create debian-based Ubuntu Classic image."""))
    argv = get_modified_args(subparser, 'snap', argv)
    snap_cmd = add_common_args(snap_cmd)
    classic_cmd = add_common_args(classic_cmd)
    # Snap-based image options.
    snap_cmd.add_argument(
        'model_assertion',
        nargs='?',
        help=_("""Path to the model assertion file.  This argument must be
        given unless the state machine is being resumed, in which case it
        cannot be given."""))
    snap_cmd.add_argument(
        '--extra-snaps',
        default=None,
        action='append',
        help=_("""Extra snaps to install.  This is passed through to `snap
        prepare-image`."""))
    snap_cmd.add_argument('-c',
                          '--channel',
                          default=None,
                          help=_('The snap channel to use'))
    # Classic-based image options.
    classic_cmd.add_argument(
        'gadget_tree',
        nargs='?',
        help=_("""Gadget tree.  This is a tree equivalent to an unpacked
        and primed gadget snap at core image build time."""))
    classic_cmd.add_argument(
        '-p',
        '--project',
        default=None,
        metavar='PROJECT',
        help=_("""Project name to be specified to livecd-rootfs."""))
    classic_cmd.add_argument(
        '-s',
        '--suite',
        default=get_host_distro(),
        metavar='SUITE',
        help=_("""Distribution name to be specified to livecd-rootfs."""))
    classic_cmd.add_argument(
        '-a',
        '--arch',
        default=get_host_arch(),
        metavar='CPU-ARCHITECTURE',
        help=_("""CPU architecture to be specified to livecd-rootfs.
        default value is builder arch."""))
    classic_cmd.add_argument(
        '--subproject',
        default=None,
        metavar='SUBPROJECT',
        help=_("""Sub project name to be specified to livecd-rootfs."""))
    classic_cmd.add_argument(
        '--subarch',
        default=None,
        metavar='SUBARCH',
        help=_("""Sub architecture to be specified to livecd-rootfs."""))
    classic_cmd.add_argument(
        '--with-proposed',
        default=False,
        action='store_true',
        help=_("""Proposed repo to install, This is passed through to
        livecd-rootfs."""))
    classic_cmd.add_argument(
        '--extra-ppas',
        default=None,
        action='append',
        help=_("""Extra ppas to install. This is passed through to
        livecd-rootfs."""))
    # Perform the actual argument parsing.
    args = parser.parse_args(argv)
    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    # The model assertion argument is required unless --resume is given, in
    # which case it cannot be given.
    if args.cmd == 'snap':
        if args.resume and args.model_assertion:
            parser.error('model assertion is not allowed with --resume')
        if not args.resume and args.model_assertion is None:
            parser.error('model assertion is required')
    else:
        if args.resume and args.gadget_tree:
            parser.error('gadget tree is not allowed with --resume')
        if not args.resume:  # pragma: no branch
            if args.gadget_tree is None:
                parser.error('gadget tree is required')
            elif args.project is None:
                parser.error('project is required')
    if args.resume and args.workdir is None:
        parser.error('--resume requires --workdir')
    # --until and --thru can take an int.
    with suppress(ValueError, TypeError):
        args.thru = int(args.thru)
    with suppress(ValueError, TypeError):
        args.until = int(args.until)
    # --hooks-directory can be a comma-separated list of directories
    if args.hooks_directory:
        args.hooks_directory = args.hooks_directory.split(',')
    # -o/--output is deprecated and mutually exclusive with -O/--output-dir
    if args.output is not None:
        print('-o/--output is deprecated; use -O/--output-dir instead',
              file=sys.stderr)
    return args
예제 #5
0
 def test_get_host_arch(self):
     self.assertIsNotNone(get_host_arch())