-
-
Save nicwest/2c971901e71019b8bb9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import json | |
import sys | |
import difflib | |
import os | |
import argparse | |
BASEDIR = os.path.dirname(os.path.realpath(__file__)) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Looks for python import paths for given names.') | |
parser.add_argument('names', metavar='names', type=str, nargs='+', | |
help='name of python class, function, or constant') | |
parser.add_argument('-f', '--fuzzy', action='store_true', help='force fuzzy matching') | |
args = parser.parse_args() | |
with open(os.path.join(BASEDIR, 'django-1.7.4.json'), 'r') as json_data: | |
data = json.load(json_data) | |
for arg in args.names: | |
paths = [] | |
if arg not in data or args.fuzzy: | |
matches = difflib.get_close_matches(arg, data.keys()) | |
if matches: | |
if not args.fuzzy: | |
paths = data[matches[0]] | |
sys.stdout.write('fuzzy matching to "%s"\n' % matches[0]) | |
else: | |
paths += [p for n in matches for p in data[n]] | |
else: | |
sys.stderr.write('Could not find "%s" in data :(\n' % arg) | |
continue | |
else: | |
paths = data[arg] | |
for path in set(paths): | |
sys.stdout.write(path + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment