Example #1
0
def _disable(recipes):
    """Disable the given recipe in the link"""
    for recipe in recipes:
        with json_file(config.recipe.profile.link_location(recipe)) as values:
            values["enabled"] = False
        LOGGER.status("Disabling the link file of {} ({})".format(
            recipe, config.recipe.writeprofile))
Example #2
0
 def hooks_to_trigger(self):
     with json_file(self.settings_path) as settings:
         if "hooks" in settings:
             settings["triggers"] = settings["hooks"]
             del settings["hooks"]
     self.computed_location = None
     self.compute_settings()
     return True
Example #3
0
    def recipes_instead_of_settings_level(self):
        if self.isrecipe:
            return True
        recipes_dir = self.location + "/recipes/"

        def migrate_settings_to_recipe(settings_level_file, name):
            if open(settings_level_file,
                    "rb").read().decode("utf-8").strip() == "{}":
                return False
            makedirs(recipes_dir + "/" + name)
            enabled = not json.load(open(settings_level_file)).get(
                "_self", {}).get("disabled", False)
            order = json.load(open(settings_level_file)).get("_self", {}).get(
                "order", 100)
            move(settings_level_file,
                 recipes_dir + "/" + name + "/{}.json".format(self.app_name))
            createfile(recipes_dir + "/" + name + "/version.txt",
                       str(self.version + 1))
            createfile(recipes_dir + "/" + name + ".json",
                       json.dumps({
                           "enabled": enabled,
                           "order": order,
                       }))
            return True

        migrate_something = False
        for settings_level_file in glob(self.location +
                                        "/{}-*.json".format(self.app_name)):
            name = re.sub(".+{}-([a-zA-Z-]+).json$".format(self.app_name),
                          r"\1", settings_level_file)
            name = name.replace("-", "_")
            if name == "private":
                continue
            migrate_something |= migrate_settings_to_recipe(
                settings_level_file, name + "_from_settings")
        private = self.location + "/{}-private.json".format(self.app_name)
        local = self.location + "/{}.json".format(self.app_name)
        if os.path.exists(private):
            if open(private, "rb").read().decode("utf-8").strip() != "{}":
                migrate_something = True
            else:
                rm(private)
        if migrate_something is True:
            name = "migrated_local"
            if os.path.exists(local) and not open(
                    local, "rb").read().decode("utf-8").strip() == "{}":
                migrate_settings_to_recipe(local, name)
            if os.path.exists(private):
                move(private, local)
            with json_file(local) as values:
                recipes = values.get("recipe", {})
                local_order = recipes.get(name, {})
                local_order["order"] = 0
                recipes[name] = local_order
                values["recipe"] = recipes
            self.computed_location = None
            self.compute_settings()
        return True
Example #4
0
 def customcommand_to_executable(self):
     with json_file(self.settings_path) as settings:
         if "customcommands" in settings:
             customcommands = settings["customcommands"]
             if "externalpaths" in customcommands:
                 customcommands["executablepaths"] = customcommands["externalpaths"]
                 del customcommands["externalpaths"]
     self.computed_location = None
     self.compute_settings()
     return True
Example #5
0
    def stack_of_git_records(self):
        for settings_file in glob(self.location + "/{}*json".format(self.app_name)):
            with json_file(settings_file) as settings:
                if "git_record" not in settings:
                    continue

                git_records = settings["git_record"]
                new_git_records = {
                    key: [record]
                    for key, record in six.iteritems(git_records)
                }
                settings["git_record"] = new_git_records
        self.computed_location = None
        self.compute_settings()
        return True
Example #6
0
    def alias_has_documentation(self):
        for settings_file in glob(self.location + "/{}*json".format(self.app_name)):
            with json_file(settings_file) as settings:
                if "alias" not in settings:
                    continue

                aliases = settings["alias"]
                new_aliases = {
                    alias: {
                        "commands": commands,
                        "documentation": None,
                    }
                    for alias, commands in six.iteritems(aliases)
                }
                settings["alias"] = new_aliases
        self.computed_location = None
        self.compute_settings()
        return True
Example #7
0
def _dump(recipe):
    """Show the values of the link file"""
    with json_file(config.recipe.profile.link_location(recipe)) as values:
        click.echo(json_dumps(values))