diff --git a/bin/is b/bin/is index 0a7f08bc94c970931d49da5c22d283cf83458453..3f05cf357c2a2c0cd5cb96788016b6d02055b039 100755 --- a/bin/is +++ b/bin/is @@ -301,24 +301,9 @@ 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) - arrow(u"Install time: %s" % datetime.timedelta(seconds=dt)) + # 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): ''' diff --git a/installsystems/image.py b/installsystems/image.py index 5f6d0af52680afb722999e9f71d32ca99979bc35..0e0edbc7b213f8f7079ac7de4843f34e4c997fe3 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -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