Пример #1
0
def basic_setup():
    """
    Creates the data storage folder.
    :return:
    """

    default_data_dir = get_data_dir()

    default_dirs = deepcopy(basic_config_default)
    default_dirs["DATA_PATH"] = str(default_data_dir.resolve())

    storage = get_storage_type()

    storage_dict = {1: BackendType.JSON, 2: BackendType.MONGO}
    storage_type: BackendType = storage_dict.get(storage, BackendType.JSON)
    default_dirs["STORAGE_TYPE"] = storage_type.value

    if storage_type == BackendType.MONGO:
        from redbot.core.drivers.red_mongo import get_config_details

        default_dirs["STORAGE_DETAILS"] = get_config_details()
    else:
        default_dirs["STORAGE_DETAILS"] = {}

    name = get_name()
    save_config(name, default_dirs)

    print()
    print(
        "Your basic configuration has been saved. Please run `redbot <name>` to"
        " continue your setup process and to run the bot.")
Пример #2
0
async def json_to_mongov2(instance):
    instance_vals = instance_data[instance]
    current_data_dir = Path(instance_vals["DATA_PATH"])

    load_basic_configuration(instance)

    from redbot.core.drivers import red_mongo

    storage_details = red_mongo.get_config_details()

    core_conf = Config.get_core_conf()
    new_driver = red_mongo.Mongo(cog_name="Core",
                                 identifier="0",
                                 **storage_details)

    core_conf.init_custom("CUSTOM_GROUPS", 2)
    custom_group_data = await core_conf.custom("CUSTOM_GROUPS").all()

    curr_custom_data = custom_group_data.get("Core", {}).get("0", {})
    exported_data = await core_conf.driver.export_data(curr_custom_data)
    conversion_log.info("Starting Core conversion...")
    await new_driver.import_data(exported_data, curr_custom_data)
    conversion_log.info("Core conversion complete.")

    for p in current_data_dir.glob("cogs/**/settings.json"):
        cog_name = p.parent.stem
        if "." in cog_name:
            # Garbage handler
            continue
        with p.open(mode="r") as f:
            cog_data = json.load(f)
        for identifier, all_data in cog_data.items():
            try:
                conf = Config.get_conf(None,
                                       int(identifier),
                                       cog_name=cog_name)
            except ValueError:
                continue
            new_driver = red_mongo.Mongo(
                cog_name=cog_name,
                identifier=conf.driver.unique_cog_identifier,
                **storage_details)

            curr_custom_data = custom_group_data.get(cog_name,
                                                     {}).get(identifier, {})

            exported_data = await conf.driver.export_data(curr_custom_data)
            conversion_log.info(
                f"Converting {cog_name} with identifier {identifier}...")
            await new_driver.import_data(exported_data, curr_custom_data)

    conversion_log.info("Cog conversion complete.")

    return storage_details
Пример #3
0
async def edit_instance():
    instance_list = load_existing_config()
    if not instance_list:
        print("No instances have been set up!")
        return

    print("You have chosen to edit an instance. The following "
          "is a list of instances that currently exist:\n")
    for instance in instance_list.keys():
        print("{}\n".format(instance))
    print("Please select one of the above by entering its name")
    selected = input("> ")

    if selected not in instance_list.keys():
        print("That isn't a valid instance!")
        return
    instance_data = instance_list[selected]
    default_dirs = deepcopy(basic_config_default)

    current_data_dir = Path(instance_data["DATA_PATH"])
    print("You have selected '{}' as the instance to modify.".format(selected))
    if not confirm("Please confirm (y/n):"):
        print("Ok, we will not continue then.")
        return

    print("Ok, we will continue on.")
    print()
    if confirm("Would you like to change the instance name? (y/n)"):
        name = get_name()
    else:
        name = selected

    if confirm("Would you like to change the data location? (y/n)"):
        default_data_dir = get_data_dir()
        default_dirs["DATA_PATH"] = str(default_data_dir.resolve())
    else:
        default_dirs["DATA_PATH"] = str(current_data_dir.resolve())

    if confirm("Would you like to change the storage type? (y/n):"):
        storage = get_storage_type()

        storage_dict = {1: "JSON", 2: "MongoDB"}
        default_dirs["STORAGE_TYPE"] = storage_dict[storage]
        if storage_dict.get(storage, 1) == "MongoDB":
            from redbot.core.drivers.red_mongo import get_config_details

            storage_details = get_config_details()
            default_dirs["STORAGE_DETAILS"] = storage_details

            if instance_data["STORAGE_TYPE"] == "JSON":
                if confirm("Would you like to import your data? (y/n) "):
                    await json_to_mongo(current_data_dir, storage_details)
        else:
            storage_details = instance_data["STORAGE_DETAILS"]
            default_dirs["STORAGE_DETAILS"] = {}
            if instance_data["STORAGE_TYPE"] == "MongoDB":
                if confirm("Would you like to import your data? (y/n) "):
                    await mongo_to_json(current_data_dir, storage_details)

    if name != selected:
        save_config(selected, {}, remove=True)
    save_config(name, default_dirs)

    print("Your basic configuration has been edited")