-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathquery.py
More file actions
68 lines (52 loc) · 2.6 KB
/
query.py
File metadata and controls
68 lines (52 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from elixir.query import Query
from elixir import lib
def cmd_stats(q, **kwargs):
print("Versions: ", len(q.db.vers))
print("Blobs: ", len(q.db.blob))
if len(q.db.blob) != len(q.db.hash) or len(q.db.hash) != len(q.db.file):
print("Warning, number of blobs, hashes or files is not equal")
print("Definitions: ", len(q.db.defs))
print("References: ", len(q.db.refs))
def cmd_versions(q, **kwargs):
for major in q.get_versions().values():
for minor in major.values():
for v in minor:
print(v)
def cmd_ident(q, version, ident, family, **kwargs):
symbol_definitions, symbol_references, symbol_doccomments, peeks = q.search_ident(version, ident, family)
print("Symbol Definitions:")
for symbol_definition in symbol_definitions:
print(symbol_definition)
print("\nSymbol References:")
for symbol_reference in symbol_references:
print(symbol_reference)
print("\nDocumented in:")
for symbol_doccomment in symbol_doccomments:
print(symbol_doccomment)
print("\nSymbol peeks:")
for file, content in peeks.items():
for num, line in content.items():
print(f"{file}:{num}: {line}")
def cmd_file(q, version, path, **kwargs):
code = q.get_tokenized_file(version, path)
print(code)
if __name__ == "__main__":
import argparse
query = Query(lib.getDataDir(), lib.getRepoDir())
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True)
ident_subparser = subparsers.add_parser('stats', help="Get basic database stats")
ident_subparser.set_defaults(func=cmd_stats, q=query)
ident_subparser = subparsers.add_parser('versions', help="Get list of versions in the project")
ident_subparser.set_defaults(func=cmd_versions, q=query)
ident_subparser = subparsers.add_parser('ident', help="Get definitions and references of an identifier")
ident_subparser.add_argument("version", help="The version of the project", type=str, default="latest")
ident_subparser.add_argument('ident', type=str, help="The name of the identifier")
ident_subparser.add_argument('family', type=str, help="The file family requested")
ident_subparser.set_defaults(func=cmd_ident, q=query)
file_subparser = subparsers.add_parser('file', help="Get a source file")
file_subparser.add_argument("version", help="The version of the project", type=str, default="latest")
file_subparser.add_argument('path', type=str, help="The path of the source file")
file_subparser.set_defaults(func=cmd_file, q=query)
args = parser.parse_args()
args.func(**vars(args))