97 results=soup.findAll('div', id='results') |
99 results=soup.findAll('div', id='results') |
98 pkgname='' |
100 pkgname='' |
99 try: |
101 try: |
100 temp=results[0].a.string |
102 temp=results[0].a.string |
101 fspos=temp.find('sf') |
103 fspos=temp.find('sf') |
|
104 if fspos == -1: |
|
105 raise |
102 temp=temp[fspos+3:] |
106 temp=temp[fspos+3:] |
103 pkgpos=temp.find('/') |
107 pkgpos=temp.find('/') |
|
108 if pkgpos == -1: |
|
109 raise |
104 temp=temp[pkgpos+1:] |
110 temp=temp[pkgpos+1:] |
105 |
111 |
106 endpkgpos=temp.find('/') |
112 endpkgpos=temp.find('/') |
|
113 if endpkgpos == -1: |
|
114 raise |
107 pkgname=temp[0:endpkgpos] |
115 pkgname=temp[0:endpkgpos] |
108 except: |
116 except: |
109 print 'error: file \'%s\' not found in opengrok' % filename |
117 print 'error: file \'%s\' not found in opengrok' % filename |
110 else: |
118 else: |
111 print 'first package with target %s: %s' % (searchterm,pkgname) |
119 print 'first package with target %s: %s' % (searchterm,pkgname) |
112 |
120 |
113 return True |
121 return pkgname |
114 |
122 |
115 def findpackageforheader(filename, project): |
123 def findpackageforheader(filename, project): |
116 searchterm=filename |
124 searchterm=filename |
117 searchurl = 'https://developer.symbian.org/xref/sfl/search?q=&defs=&refs=&path=%s&hist=&project=%%2F%s' |
125 searchurl = 'https://developer.symbian.org/xref/sfl/search?q=&defs=&refs=&path=%s&hist=&project=%%2F%s' |
118 url = searchurl % (searchterm, project) |
126 url = searchurl % (searchterm, project) |
151 pkgpos=temp.find('/') |
159 pkgpos=temp.find('/') |
152 temp=temp[pkgpos+1:] |
160 temp=temp[pkgpos+1:] |
153 |
161 |
154 endpkgpos=temp.find('/') |
162 endpkgpos=temp.find('/') |
155 pkgname=temp[0:endpkgpos] |
163 pkgname=temp[0:endpkgpos] |
|
164 |
|
165 if len(pkgname) == 0: |
|
166 raise |
156 except: |
167 except: |
157 print 'error: file \'%s\' not found in opengrok' % filename |
168 print 'error: file \'%s\' not found in opengrok' % filename |
158 else: |
169 else: |
159 print 'package:', pkgname |
170 print 'package:', pkgname |
160 |
171 |
161 return True |
172 return pkgname |
|
173 |
|
174 |
|
175 # we find the package owner by attempting to raise a bug for this package |
|
176 def findpackageowner(pkgname): |
|
177 pkgurl = 'http://developer.symbian.org/bugs/enter_bug.cgi?product=%s' |
|
178 url = pkgurl % pkgname |
|
179 |
|
180 req = urllib2.Request(url) |
|
181 |
|
182 response = urllib2.urlopen(req) |
|
183 |
|
184 doc=response.read() |
|
185 |
|
186 pos = doc.find('initialowners[0]') |
|
187 |
|
188 if pos != -1: |
|
189 email=doc[pos+20:pos+220] # 100 chars must be enough |
|
190 pos = email.find(';') |
|
191 email = email[0:pos-1] |
|
192 email = email.replace('\\x40', '@') |
162 |
193 |
|
194 return email |
|
195 |
|
196 # we find domain by scraping another page, god forbid they change the html |
|
197 def findpackagedomain(pkgname): |
|
198 url = 'http://developer.symbian.org/main/source/platform/index.php' |
|
199 |
|
200 req = urllib2.Request(url) |
|
201 |
|
202 response = urllib2.urlopen(req) |
|
203 |
|
204 doc=response.read() |
|
205 |
|
206 # BeatifulSoup chokes on some javascript, so we cut away everything before the <body> |
|
207 try: |
|
208 bodystart=doc.find('<body>') |
|
209 doc = doc[bodystart:] |
|
210 except: |
|
211 pass |
|
212 |
|
213 soup=BeautifulSoup(doc) |
|
214 |
|
215 # let's hope the HTML format never changes... |
|
216 results=soup.findAll('li') |
|
217 |
|
218 for result in results: |
|
219 try: |
|
220 temp = result.a.contents[0].lower() |
|
221 if temp.find(pkgname) != -1: |
|
222 return result.parent.parent.h3.a.contents[0] |
|
223 except: |
|
224 pass |
163 |
225 |
164 if len(sys.argv) < 2: |
226 if len(sys.argv) < 2: |
165 print 'usage: findpackage.py <filename> [project]' |
227 print 'usage: findpackage.py <filename> [project]' |
166 exit() |
228 exit() |
167 |
229 |
168 filename = sys.argv[1] |
230 filename = sys.argv[1] |
|
231 |
169 |
232 |
170 if len(sys.argv) == 3: |
233 if len(sys.argv) == 3: |
171 project = sys.argv[2] |
234 project = sys.argv[2] |
172 else: |
235 else: |
173 project = 'Symbian2' |
236 project = 'Symbian2' |
174 |
237 |
175 if filename.endswith('.lib') or filename.endswith('.dll'): |
238 if filename.endswith('.lib') or filename.endswith('.dll'): |
176 findpackageforlibrary(filename, project) |
239 pkgname=findpackageforlibrary(filename, project) |
177 else: |
240 else: |
178 findpackageforheader(filename, project) |
241 pkgname=findpackageforheader(filename, project) |
|
242 |
|
243 if len(pkgname) > 0: |
|
244 domain=findpackagedomain(pkgname) |
|
245 owner=findpackageowner(pkgname) |
|
246 |
|
247 print "domain:", domain |
|
248 print "owner:", owner |