author | Sebastian Brannstrom <sebastianb@symbian.org> |
Wed, 18 Nov 2009 12:21:26 +0000 | |
changeset 11 | b61dd9190c0e |
permissions | -rw-r--r-- |
11
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
1 |
# findpackage.py - finds which Symbian package contains a file (if any) by searching opengrok |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
2 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
3 |
import urllib2 |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
4 |
import urllib |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
5 |
import os.path |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
6 |
import cookielib |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
7 |
import sys |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
8 |
import getpass |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
9 |
from BeautifulSoup import BeautifulSoup |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
10 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
11 |
user_agent = 'findpackage.py script' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
12 |
headers = { 'User-Agent' : user_agent } |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
13 |
top_level_url = "http://developer.symbian.org" |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
14 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
15 |
COOKIEFILE = 'cookies.lwp' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
16 |
# the path and filename to save your cookies in |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
17 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
18 |
# importing cookielib worked |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
19 |
urlopen = urllib2.urlopen |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
20 |
Request = urllib2.Request |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
21 |
cj = cookielib.LWPCookieJar() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
22 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
23 |
# This is a subclass of FileCookieJar |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
24 |
# that has useful load and save methods |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
25 |
if os.path.isfile(COOKIEFILE): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
26 |
cj.load(COOKIEFILE) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
27 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
28 |
# Now we need to get our Cookie Jar |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
29 |
# installed in the opener; |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
30 |
# for fetching URLs |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
31 |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
32 |
urllib2.install_opener(opener) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
33 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
34 |
def login(): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
35 |
loginurl = 'https://developer.symbian.org/main/user_profile/login.php' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
36 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
37 |
print >> sys.stderr, 'username: ', |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
38 |
username=sys.stdin.readline().strip() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
39 |
password=getpass.getpass() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
40 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
41 |
values = {'username' : username, |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
42 |
'password' : password, |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
43 |
'submit': 'Login'} |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
44 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
45 |
headers = { 'User-Agent' : user_agent } |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
46 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
47 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
48 |
data = urllib.urlencode(values) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
49 |
req = urllib2.Request(loginurl, data, headers) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
50 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
51 |
response = urllib2.urlopen(req) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
52 |
doc=response.read() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
53 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
54 |
if doc.find('Please try again') != -1: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
55 |
print >> sys.stderr, 'Login failed' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
56 |
return False |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
57 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
58 |
cj.save(COOKIEFILE) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
59 |
return True |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
60 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
61 |
def findpackageforlibrary(filename, project): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
62 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
63 |
dotpos = filename.find('.') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
64 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
65 |
if dotpos != -1: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
66 |
searchterm = filename[0:dotpos] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
67 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
68 |
searchterm = filename |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
69 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
70 |
searchurl = 'https://developer.symbian.org/xref/sfl/search?q="TARGET+%s"&defs=&refs=&path=&hist=&project=%%2F%s' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
71 |
url = searchurl % (searchterm, project) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
72 |
req = urllib2.Request(url) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
73 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
74 |
response = urllib2.urlopen(req) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
75 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
76 |
doc=response.read() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
77 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
78 |
if doc.find('Restricted access') != -1: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
79 |
if(login()): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
80 |
# try again after login |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
81 |
response = urllib2.urlopen(req) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
82 |
doc=response.read() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
83 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
84 |
return False |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
85 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
86 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
87 |
# BeatifulSoup chokes on some javascript, so we cut away everything before the <body> |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
88 |
try: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
89 |
bodystart=doc.find('<body>') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
90 |
doc = doc[bodystart:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
91 |
except: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
92 |
pass |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
93 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
94 |
soup=BeautifulSoup(doc) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
95 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
96 |
# let's hope the HTML format never changes... |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
97 |
results=soup.findAll('div', id='results') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
98 |
pkgname='' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
99 |
try: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
100 |
temp=results[0].a.string |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
101 |
fspos=temp.find('sf') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
102 |
temp=temp[fspos+3:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
103 |
pkgpos=temp.find('/') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
104 |
temp=temp[pkgpos+1:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
105 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
106 |
endpkgpos=temp.find('/') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
107 |
pkgname=temp[0:endpkgpos] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
108 |
except: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
109 |
print 'error: file \'%s\' not found in opengrok' % filename |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
110 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
111 |
print 'first package with target %s: %s' % (searchterm,pkgname) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
112 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
113 |
return True |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
114 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
115 |
def findpackageforheader(filename, project): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
116 |
searchterm=filename |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
117 |
searchurl = 'https://developer.symbian.org/xref/sfl/search?q=&defs=&refs=&path=%s&hist=&project=%%2F%s' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
118 |
url = searchurl % (searchterm, project) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
119 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
120 |
req = urllib2.Request(url) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
121 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
122 |
response = urllib2.urlopen(req) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
123 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
124 |
doc=response.read() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
125 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
126 |
if doc.find('Restricted access') != -1: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
127 |
if(login()): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
128 |
# try again after login |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
129 |
response = urllib2.urlopen(req) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
130 |
doc=response.read() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
131 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
132 |
return False |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
133 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
134 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
135 |
# BeatifulSoup chokes on some javascript, so we cut away everything before the <body> |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
136 |
try: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
137 |
bodystart=doc.find('<body>') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
138 |
doc = doc[bodystart:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
139 |
except: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
140 |
pass |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
141 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
142 |
soup=BeautifulSoup(doc) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
143 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
144 |
# let's hope the HTML format never changes... |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
145 |
results=soup.findAll('div', id='results') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
146 |
pkgname='' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
147 |
try: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
148 |
temp=results[0].a.string |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
149 |
fspos=temp.find('sf') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
150 |
temp=temp[fspos+3:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
151 |
pkgpos=temp.find('/') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
152 |
temp=temp[pkgpos+1:] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
153 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
154 |
endpkgpos=temp.find('/') |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
155 |
pkgname=temp[0:endpkgpos] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
156 |
except: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
157 |
print 'error: file \'%s\' not found in opengrok' % filename |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
158 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
159 |
print 'package:', pkgname |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
160 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
161 |
return True |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
162 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
163 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
164 |
if len(sys.argv) < 2: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
165 |
print 'usage: findpackage.py <filename> [project]' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
166 |
exit() |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
167 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
168 |
filename = sys.argv[1] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
169 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
170 |
if len(sys.argv) == 3: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
171 |
project = sys.argv[2] |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
172 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
173 |
project = 'Symbian2' |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
174 |
|
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
175 |
if filename.endswith('.lib') or filename.endswith('.dll'): |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
176 |
findpackageforlibrary(filename, project) |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
177 |
else: |
b61dd9190c0e
Added my python script findpackage.pl
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
178 |
findpackageforheader(filename, project) |