Commit 5d67b16a authored by Sébastien Luttringer's avatar Sébastien Luttringer
Browse files

Move install stuff into image

c_install function are moved to image
parent a58a65a5
Loading
Loading
Loading
Loading
+3 −18
Original line number Diff line number Diff line
@@ -301,23 +301,8 @@ def c_install(args):
    image, repo = next(get_images([args.pattern], repoman, min=1, max=1))
    # Print setup information
    arrow(u"Installing %s v%s" % (image.name, image.version))
    # install start time
    t0 = time.time()
    # run parser scripts with parser parser argument
    image.run_parser({"parser": subparser})
    # call parser again, with extended attributes
    arrow("Parsing arguments")
    # Catch exception in custom argparse action
    try:
        args = args.parser.parse_args()
    except Exception as e:
        raise ISError("Parsing error", e)
    # run setup scripts
    if not args.dry_run:
        image.run_setup({"namespace": args})
        # compute building time
        t1 = time.time()
        dt = int(t1 - t0)
    # let's go
    dt = image.run(args.parser, subparser, run_setup=not args.dry_run)
    arrow(u"Install time: %s" % datetime.timedelta(seconds=dt))

def c_list(args):
+34 −0
Original line number Diff line number Diff line
@@ -944,6 +944,40 @@ class PackageImage(Image):
                arrow(u"Extracting payload %s in %s" % (payname, dest))
                self.payload[payname].extract(dest, force=force)

    def run(self, parser, extparser, load_modules=True, run_parser=True,
            run_setup=True):
        '''
        Run images scripts

        parser is the whole command line parser
        extparser is the parser extensible by parser scripts

        if load_modules is true load image modules
        if run_parser is true run parser scripts
        if run_setup is true run setup scripts
        '''
        # register start time
        t0 = time.time()
        # load image modules
        if load_modules:
            self.load_modules(lambda: self.select_scripts("lib"))
        # run parser scripts to extend extparser
        # those scripts should only extand the parser or produce error
        if run_parser:
            self.run_parser({"parser": extparser})
        # call parser (again), with full options
        arrow("Parsing command line")
        # Catch exception in custom argparse action
        try:
            args = parser.parse_args()
        except Exception as e:
            raise ISError("Argument parser", e)
        # run setup scripts
        if run_setup:
            self.run_setup({"namespace": args})
        # return the building time
        return int(time.time() - t0)

    def run_parser(self, global_dict):
        '''
        Run parser scripts