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