Пример #1
0
def json_driver(tmpdir_factory):
    import uuid

    rand = str(uuid.uuid4())
    path = Path(str(tmpdir_factory.mktemp(rand)))
    driver = red_json.JSON("PyTest",
                           identifier=str(uuid.uuid4()),
                           data_path_override=path)
    return driver
Пример #2
0
async def mongov2_to_json(instance):
    load_basic_configuration(instance)

    core_path = core_data_path()

    from redbot.core.drivers import red_json

    core_conf = Config.get_core_conf()
    new_driver = red_json.JSON(cog_name="Core",
                               identifier="0",
                               data_path_override=core_path)

    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.")

    collection_names = await core_conf.driver.db.list_collection_names()
    splitted_names = list(
        filter(
            lambda elem: elem[1] != "" and elem[0] != "Core",
            [n.split(".") for n in collection_names],
        ))

    ident_map = {}  # Cogname: idents list
    for cog_name, category in splitted_names:
        if cog_name not in ident_map:
            ident_map[cog_name] = set()

        idents = await core_conf.driver.db[cog_name][category].distinct(
            "_id.RED_uuid")
        ident_map[cog_name].update(set(idents))

    for cog_name, idents in ident_map.items():
        for identifier in idents:
            curr_custom_data = custom_group_data.get(cog_name,
                                                     {}).get(identifier, {})
            try:
                conf = Config.get_conf(None,
                                       int(identifier),
                                       cog_name=cog_name)
            except ValueError:
                continue
            exported_data = await conf.driver.export_data(curr_custom_data)

            new_path = cog_data_path(raw_name=cog_name)
            new_driver = red_json.JSON(cog_name,
                                       identifier,
                                       data_path_override=new_path)
            conversion_log.info(
                f"Converting {cog_name} with identifier {identifier}...")
            await new_driver.import_data(exported_data, curr_custom_data)

    # cog_data_path(raw_name=cog_name)

    conversion_log.info("Cog conversion complete.")

    return {}