Пример #1
0
    def __convertVariant(self, variant_path):
        # Copy the variant to the machine_instances/*_settings.inst.cfg
        variant_config = configparser.ConfigParser(interpolation=None)
        with open(variant_path, "r") as fhandle:
            variant_config.read_file(fhandle)

        if variant_config.has_section("general") and variant_config.has_option(
                "general", "name"):
            config_name = variant_config.get("general", "name")
            if config_name.endswith("_variant"):
                config_name = config_name[:-len("_variant")] + "_settings"
                variant_config.set("general", "name", config_name)

        if not variant_config.has_section("metadata"):
            variant_config.add_section("metadata")
        variant_config.set("metadata", "type", "definition_changes")

        resource_path = Resources.getDataStoragePath()
        machine_instances_dir = os.path.join(resource_path,
                                             "machine_instances")

        if variant_path.endswith("_variant.inst.cfg"):
            variant_path = variant_path[:-len("_variant.inst.cfg"
                                              )] + "_settings.inst.cfg"

        with open(
                os.path.join(machine_instances_dir,
                             os.path.basename(variant_path)), "w") as fp:
            variant_config.write(fp)

        return config_name
Пример #2
0
    def __convertVariant(self, variant_path):
        # Copy the variant to the machine_instances/*_settings.inst.cfg
        variant_config = configparser.ConfigParser(interpolation=None)
        with open(variant_path, "r") as fhandle:
            variant_config.read_file(fhandle)

        if variant_config.has_section("general") and variant_config.has_option("general", "name"):
            config_name = variant_config.get("general", "name")
            if config_name.endswith("_variant"):
                config_name = config_name[:-len("_variant")] + "_settings"
                variant_config.set("general", "name", config_name)

        if not variant_config.has_section("metadata"):
            variant_config.add_section("metadata")
        variant_config.set("metadata", "type", "definition_changes")

        resource_path = Resources.getDataStoragePath()
        machine_instances_dir = os.path.join(resource_path, "machine_instances")

        if variant_path.endswith("_variant.inst.cfg"):
            variant_path = variant_path[:-len("_variant.inst.cfg")] + "_settings.inst.cfg"

        with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w") as fp:
            variant_config.write(fp)

        return config_name
Пример #3
0
    def __getUserVariants(self):
        resource_path = Resources.getDataStoragePath()
        variants_dir = os.path.join(resource_path, "variants")

        result = []
        for entry in os.scandir(variants_dir):
            if entry.name.endswith('.inst.cfg') and entry.is_file():
                config = configparser.ConfigParser(interpolation = None)
                with open(entry.path, "r") as fhandle:
                    config.read_file(fhandle)
                if config.has_section("general") and config.has_option("general", "name"):
                    result.append( { "path": entry.path, "name": config.get("general", "name") } )
        return result
Пример #4
0
    def __getUserVariants(self):
        resource_path = Resources.getDataStoragePath()
        variants_dir = os.path.join(resource_path, "variants")

        result = []
        for entry in os.scandir(variants_dir):
            if entry.name.endswith('.inst.cfg') and entry.is_file():
                config = configparser.ConfigParser(interpolation=None)
                with open(entry.path, "r") as fhandle:
                    config.read_file(fhandle)
                if config.has_section("general") and config.has_option(
                        "general", "name"):
                    result.append({
                        "path": entry.path,
                        "name": config.get("general", "name")
                    })
        return result