Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete database_blob type #6196

Merged
merged 2 commits into from
Jul 1, 2021

Conversation

ichorid
Copy link
Contributor

@ichorid ichorid commented Jul 1, 2021

fixes #6097 with some bowler magic:

import mmap
import re
from lib2to3.pgen2.parse import ParseError
from pathlib import Path

from bowler.query import Query

fun_name = "database_blob"

dbblob = re.compile(fun_name.encode())


def modify_file(filename):
    (
        Query(filename).
            select_function(fun_name).
            is_call().
            modify(remove_call).execute(interactive=False, write=True)
    )


def remove_call(ast_node, capture, _):
    args = capture.get('function_arguments')

    parent = ast_node.parent
    children_list = parent.children
    for ind, leaf in enumerate(children_list):
        if leaf is ast_node:
            children_list[ind] = args[0].clone()


if __name__ == "__main__":
    for file in Path("src/tribler-core").rglob("*.py"):
        try:
            with open(file, "r+") as f:
                data = mmap.mmap(f.fileno(), 0)
                if not re.search(dbblob, data):
                    continue
        except:
            continue
        try:
            modify_file(file)
        except ParseError:
            print("Can't handle file ", file)

@ichorid ichorid force-pushed the refactor/database_blob branch 2 times, most recently from 6784e95 to 55f5e4f Compare July 1, 2021 12:03
@ichorid ichorid marked this pull request as ready for review July 1, 2021 12:03
@ichorid ichorid requested a review from qstokkink July 1, 2021 12:04
@ichorid ichorid force-pushed the refactor/database_blob branch from 55f5e4f to 39e1c0c Compare July 1, 2021 12:14
@ichorid ichorid requested a review from qstokkink July 1, 2021 12:14
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 1, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This has been on my wishlist for quite a long time.

@ichorid ichorid merged commit d3dbf1d into Tribler:main Jul 1, 2021
@ichorid ichorid deleted the refactor/database_blob branch July 1, 2021 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Remove usages of database_blob
2 participants