Пример #1
0
    def handle(self, config, options):
        """Run command."""
        with config.storage.transaction() as store:
            try:
                experiment = Experiment.from_store(store, options.experiment)
            except LookupError:
                raise CommandError(
                    'No such experiment: "{id}"'.format(id=options.experiment)
                )

            current_experiments = store.get("active-experiments", [])
            concluded_experiments = store.get("concluded-experiments", [])

            if options.experiment not in current_experiments:
                if experiment.concluded is None:
                    message = ("Experiment '{experiment_id}' not launched!").format(
                        experiment_id=options.experiment
                    )
                else:
                    message = (
                        "Experiment '{experiment_id}' already concluded (at "
                        "{concluded})!"
                    ).format(
                        experiment_id=options.experiment, concluded=experiment.concluded
                    )

                raise CommandError(message)

            current_experiments.remove(options.experiment)
            concluded_experiments.append(options.experiment)

            close(
                store,
                experiment.id,
                experiment.constraints,
                experiment.branch_launch_configuration(),
            )

            if options.promote_branch:
                defaults = store.get("defaults", {})

                # Find branch matching ID
                try:
                    branch_configuration = experiment.branch(options.branch)
                except LookupError:
                    raise CommandError(
                        "Experiment '{experiment_id}' has no branch '{branch_name}'".format(
                            experiment_id=options.experiment, branch_name=options.branch
                        )
                    )
                defaults.update(branch_configuration["settings"])

                store["defaults"] = defaults

            experiment.concluded = datetime.datetime.now(dateutil.tz.tzutc())
            experiment.save(store)

            store["active-experiments"] = current_experiments
            store["concluded-experiments"] = concluded_experiments
Пример #2
0
    def handle(self, config, options):
        """Run command."""
        with config.storage.transaction() as store:
            try:
                experiment = Experiment.from_store(store, options.experiment)
            except LookupError:
                raise CommandError(
                    'No such experiment: "{id}"'.format(id=options.experiment)
                )

            current_experiments = store.get("active-experiments", [])

            if experiment.id in current_experiments:
                raise CommandError(
                    "Experiment '{experiment_id}' already launched!".format(
                        experiment_id=experiment.id
                    )
                )

            if experiment.concluded is not None:
                if options.relaunch:
                    experiment.concluded = None
                    experiment.launched = None
                else:
                    raise CommandError(
                        "Experiment '{id}' already concluded!".format(id=experiment.id)
                    )

            experiment.launched = datetime.datetime.now(dateutil.tz.tzutc())

            specialised_constraints = experiment.constraints.specialise(
                ConstraintContext(era_start_date=experiment.launched)
            )

            try:
                release(
                    store,
                    experiment.id,
                    specialised_constraints,
                    experiment.branch_launch_configuration(),
                )
            except NotEnoughBucketsException as e:
                raise CommandError(
                    "Conflicts: {conflicts}".format(
                        conflicts=e.human_readable_conflicts()
                    )
                )

            store["active-experiments"] = (current_experiments + [options.experiment])

            experiment.save(store)
Пример #3
0
    def handle(self, config, options):
        """Run command."""
        with config.storage.transaction() as store:
            key = "overrides/{user_id}".format(user_id=options.user)

            overrides = dict(store.get(key, {}))

            if options.delete:
                with contextlib.suppress(KeyError):
                    del overrides[options.setting]

                if overrides == {}:
                    with contextlib.suppress(KeyError):
                        del store[key]
                else:
                    store[key] = overrides

            elif options.value:
                try:
                    value = yaml.safe_load(options.value)
                except ValueError:
                    raise CommandError(
                        "Could not decode {value!r}".format(value=options.value)
                    )

                overrides[options.setting] = value
                store[key] = overrides

            else:
                yaml.dump(overrides, sys.stdout, default_flow_style=False)
Пример #4
0
    def handle(self, config, options):
        """Run command."""
        with config.storage.transaction() as store:
            defaults = dict(store.get("defaults", {}))

            any_changes = False

            if options.delete:
                with contextlib.suppress(KeyError):
                    del defaults[options.setting]
                    any_changes = True

            else:
                try:
                    value = yaml.safe_load(options.value)
                except ValueError:
                    raise CommandError(
                        "Could not decode {value!r}".format(value=options.value)
                    )

                if not options.add or options.setting not in defaults:
                    defaults[options.setting] = value
                    any_changes = True

            if any_changes:
                store["defaults"] = defaults
Пример #5
0
    def handle(self, config, options):
        """Run command."""
        replacement_config = _DuplicateStorageConfig(config)

        target = self._get_run_target(replacement_config, options)
        target_failure_mode = functools.partial(self._failure_mode, target)

        reference_failure_mode = target_failure_mode()

        if reference_failure_mode is None:
            raise CommandError("Target is not currently failing")

        print("Failure mode: ", reference_failure_mode)

        with self._backed_up_storage(replacement_config.storage):

            def predicate():
                """Determine if the config maintains the original failure."""
                return target_failure_mode() == reference_failure_mode

            # Sequence 1: Simplify by dropping keys
            print("Dropping keys")
            self._progressively_simplify(replacement_config.storage,
                                         self._try_dropping_key, predicate)

            # Sequence 2: Progressively simplify all remaining keys

            print("Simplifying keys")
            self._progressively_simplify(replacement_config.storage,
                                         self._try_simplifying_key, predicate)

            print("Done bugpointing")

            # Output storage state
            run_command(["storage-dump"], replacement_config)
Пример #6
0
    def handle(self, config, option):
        """Run command."""
        if not option.force:
            raise CommandError(
                "This command would erase the database. If you are really "
                "sure this is something you want to do, add --force.")

        with config.storage.transaction() as store:
            store.clear()
Пример #7
0
 def handle(self, config, options):
     """Run command."""
     with config.storage.transaction(read_only=True) as store:
         try:
             experiment = Experiment.from_store(store, options.experiment)
         except LookupError:
             raise CommandError(
                 'No such experiment: "{id}"'.format(id=options.experiment)
             )
         self.show_experiment(experiment, with_settings=options.settings)
Пример #8
0
    def handle(self, config, options):
        """Run command."""
        with config.storage.transaction() as store:
            live_experiments = store.get("active-experiments", ())
            concluded_experiments = store.get("concluded-experiments", ())

            for file in options.files:
                try:
                    definition = yaml.safe_load(file)
                except (yaml.YAMLError, UnicodeError) as e:
                    raise CommandError(str(e))

                if is_recursive(definition):
                    raise CommandError("Recursive structure in experiment definition")

                try:
                    experiment = Experiment.from_json(definition)
                except ValueError as e:
                    raise CommandError(str(e)) from None

                if experiment.id in live_experiments:
                    if options.skip_launched:
                        continue

                    else:
                        raise CommandError(
                            "Experiment '{experiment_id}' is live, "
                            "refusing to edit".format(experiment_id=experiment.id)
                        )

                elif experiment.id in concluded_experiments:
                    if options.skip_launched:
                        continue

                    else:
                        raise CommandError(
                            "Experiment '{experiment_id}' has concluded, "
                            "refusing to edit".format(experiment_id=experiment.id)
                        )

                experiment.save(store)
Пример #9
0
    def handle(self, config, options):
        """Run command."""
        entry = config.directory.lookup(options.user_id)

        if entry is None:
            raise CommandError("No directory entry for ID: {0!r}".format(
                options.user_id))

        print("User ID:", entry.id)
        print("Join date:", entry.join_date)
        if not entry.tags:
            print("No tags")
        else:
            print("Tags: ", ", ".join(entry.tags))