-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlocal.py
52 lines (42 loc) · 1.49 KB
/
local.py
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
# -*- coding: utf-8 -*-
__author__ = 'eveliotc'
__license__ = 'See LICENSE'
import sys
from os import walk, environ, path
from common import Pom
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
def findtext(element, tag, alt='', ns='http://maven.apache.org/POM/4.0.0'):
fulltag = str(ET.QName(ns, tag))
return element.findtext(fulltag, alt)
def to_pom(project):
pom = Pom()
pom.a = findtext(project, 'artifactId')
pom.g = findtext(project, 'groupId')
pom.p = findtext(project, 'packaging', 'jar')
pom.latestVersion = findtext(project, 'version')
pom.source = 'local'
return pom
def local_search(query):
# TODO a better more relaxed (partial) search e.g. supportv4 should match, fuzzywuzzy?
docs = []
if len(query) < 1:
return docs
andys_home = path.normpath(environ['ANDROID_HOME'])
extras_room = path.join(andys_home, 'extras')
for (dirpath, dirnames, filenames) in walk(extras_room):
if 'm2repository' in dirpath:
for file in filenames:
if file.endswith('.pom') and query in file:
fullpath = path.join(dirpath, file)
root = ET.parse(fullpath).getroot()
doc = to_pom(root)
docs.append(doc)
return sorted(docs, key=lambda doc: doc.latestVersion, reverse=True)
def main(args):
print local_search(' '.join(args))
pass
if __name__ == '__main__':
main(sys.argv[1:])