author | William Roberts <williamr@symbian.org> |
Mon, 01 Feb 2010 12:11:48 +0000 | |
changeset 139 | 9baccbcc5509 |
parent 138 | 7b2d146ef884 |
child 140 | 55dd69d60bbc |
permissions | -rw-r--r-- |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
2 |
# Copyright (c) 2009 Symbian Foundation. |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
3 |
# All rights reserved. |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
8 |
# |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
9 |
# Initial Contributors: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
10 |
# Symbian Foundation - Initial contribution |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
11 |
# |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
12 |
# Description: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
13 |
# Script to download and unpack a Symbian PDK - assumes "7z" installed to unzip the files |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
14 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
15 |
import urllib2 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
16 |
import urllib |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
17 |
import os.path |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
18 |
import cookielib |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
19 |
import sys |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
20 |
import getpass |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
21 |
import re |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
22 |
from BeautifulSoup import BeautifulSoup |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
23 |
from optparse import OptionParser |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
24 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
25 |
user_agent = 'downloadkit.py script' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
26 |
headers = { 'User-Agent' : user_agent } |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
27 |
top_level_url = "http://developer.symbian.org" |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
28 |
download_list = [] |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
29 |
unzip_list = [] |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
30 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
31 |
username = '' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
32 |
password = '' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
33 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
34 |
COOKIEFILE = 'cookies.lwp' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
35 |
# the path and filename to save your cookies in |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
36 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
37 |
# importing cookielib worked |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
38 |
urlopen = urllib2.urlopen |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
39 |
Request = urllib2.Request |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
40 |
cj = cookielib.LWPCookieJar() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
41 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
42 |
# This is a subclass of FileCookieJar |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
43 |
# that has useful load and save methods |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
44 |
if os.path.isfile(COOKIEFILE): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
45 |
cj.load(COOKIEFILE) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
46 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
47 |
# Now we need to get our Cookie Jar |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
48 |
# installed in the opener; |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
49 |
# for fetching URLs |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
50 |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
51 |
urllib2.install_opener(opener) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
52 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
53 |
def login(prompt): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
54 |
global username |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
55 |
global password |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
56 |
loginurl = 'https://developer.symbian.org/main/user_profile/login.php' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
57 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
58 |
if prompt: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
59 |
print >> sys.stderr, 'username: ', |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
60 |
username=sys.stdin.readline().strip() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
61 |
password=getpass.getpass() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
62 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
63 |
values = {'username' : username, |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
64 |
'password' : password, |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
65 |
'submit': 'Login'} |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
66 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
67 |
headers = { 'User-Agent' : user_agent } |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
68 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
69 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
70 |
data = urllib.urlencode(values) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
71 |
req = urllib2.Request(loginurl, data, headers) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
72 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
73 |
response = urllib2.urlopen(req) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
74 |
doc=response.read() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
75 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
76 |
if doc.find('Please try again') != -1: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
77 |
print >> sys.stderr, 'Login failed' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
78 |
return False |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
79 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
80 |
cj.save(COOKIEFILE) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
81 |
return True |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
82 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
83 |
from threading import Thread |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
84 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
85 |
class unzipfile(Thread): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
86 |
def __init__ (self,filename,levels=1,deletelevels=0): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
87 |
Thread.__init__(self) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
88 |
self.filename = filename |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
89 |
self.levels = levels |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
90 |
self.deletelevels = deletelevels |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
91 |
self.status = -1 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
92 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
93 |
def unzip(self,filename,unziplevel,deletelevel): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
94 |
if unziplevel < 1: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
95 |
return 0 # do nothing |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
96 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
97 |
print " Unzipping " + filename |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
98 |
filelist = os.popen("7z x -y "+self.filename) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
99 |
subzips = [] |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
100 |
for line in filelist.readlines(): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
101 |
# Extracting src_oss_app_webuis.zip |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
102 |
match = re.match(r"^Extracting\s+(\S+.zip)$", line) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
103 |
if match is None: continue |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
104 |
subzips.append(match.group(1)) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
105 |
topstatus = filelist.close() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
106 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
107 |
if deletelevel > 0: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
108 |
print " Deleting " + filename |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
109 |
os.remove(filename) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
110 |
if unziplevel > 1 and len(subzips) > 0: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
111 |
print " Expanding %d zip files from %s" % (len(subzips), filename) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
112 |
for subzip in subzips: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
113 |
self.unzip(subzip, unziplevel-1, deletelevel-1) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
114 |
return topstatus |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
115 |
def run(self): |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
116 |
self.status = self.unzip(self.filename, self.levels, self.deletelevels) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
117 |
|
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
118 |
threadlist = [] |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
119 |
def schedule_unzip(filename, unziplevel, deletelevel): |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
120 |
global options |
139
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
121 |
if options.nounzip : |
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
122 |
return |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
123 |
if options.dryrun : |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
124 |
global unzip_list |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
125 |
if unziplevel > 0: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
126 |
unzip_list.append("7z x -y %s" % filename) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
127 |
if unziplevel > 1: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
128 |
unzip_list.append("# unzip recursively %d more times" % unziplevel-1) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
129 |
if deletelevel > 0: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
130 |
unzip_list.append("# delete %s" % filename) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
131 |
if deletelevel > 1: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
132 |
unzip_list.append("# delete zip files recursively %d more times" % deletelevel-1) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
133 |
return |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
134 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
135 |
unzipthread = unzipfile(filename, unziplevels, deletelevels) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
136 |
global threadlist |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
137 |
threadlist.append(unzipthread) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
138 |
unzipthread.start() |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
139 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
140 |
def complete_outstanding_unzips(): |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
141 |
global options |
139
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
142 |
if options.dryrun or options.nounzip: |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
143 |
return |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
144 |
print "Waiting for outstanding commands to finish..." |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
145 |
for thread in threadlist: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
146 |
thread.join() |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
147 |
|
128
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
148 |
def orderResults(x,y) : |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
149 |
def ranking(name) : |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
150 |
# 1st = release_metadata, build_BOM.zip (both small things!) |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
151 |
if re.match(r"(build_BOM|release_metadata)", name): |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
152 |
return 1000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
153 |
# 2nd = tools, binaries (required for execution and compilation) |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
154 |
elif re.match(r"(binaries_|tools_)", name): |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
155 |
return 2000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
156 |
# 3rd = rnd binaries, binary patches |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
157 |
elif re.match(r"(bin_)", name): |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
158 |
return 3000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
159 |
# 4th = sources |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
160 |
elif re.match(r"(src_sfl|src_oss)", name): |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
161 |
return 4000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
162 |
# 5rd = rnd sources, source patches (not sure we'd ever have those) |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
163 |
elif re.match(r"(src_)", name): |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
164 |
return 5000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
165 |
# Last, anything else |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
166 |
return 10000; |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
167 |
xtitle = x['title'] |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
168 |
ytitle = y['title'] |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
169 |
return cmp(ranking(xtitle)+cmp(xtitle,ytitle), ranking(ytitle)) |
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
170 |
|
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
171 |
def download_file(filename,url): |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
172 |
global options |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
173 |
if options.dryrun : |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
174 |
global download_list |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
175 |
download_info = "download %s %s" % (filename, url) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
176 |
download_list.append(download_info) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
177 |
return True |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
178 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
179 |
print 'Downloading ' + filename |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
180 |
global headers |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
181 |
req = urllib2.Request(url, None, headers) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
182 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
183 |
try: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
184 |
response = urllib2.urlopen(req) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
185 |
CHUNK = 128 * 1024 |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
186 |
first_chunk = True |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
187 |
fp = open(filename, 'wb') |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
188 |
while True: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
189 |
chunk = response.read(CHUNK) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
190 |
if not chunk: break |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
191 |
if first_chunk and chunk.find('<div id="sign_in_box">') != -1: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
192 |
# our urllib2 cookies have gone awol - login again |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
193 |
login(False) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
194 |
req = urllib2.Request(url, None, headers) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
195 |
response = urllib2.urlopen(req) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
196 |
chunk = response.read(CHUNK) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
197 |
fp.write(chunk) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
198 |
first_chunk = False |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
199 |
fp.close() |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
200 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
201 |
#handle errors |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
202 |
except urllib2.HTTPError, e: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
203 |
print "HTTP Error:",e.code , downloadurl |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
204 |
return False |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
205 |
except urllib2.URLError, e: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
206 |
print "URL Error:",e.reason , downloadurl |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
207 |
return False |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
208 |
return True |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
209 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
210 |
def downloadkit(version): |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
211 |
global headers |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
212 |
global options |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
213 |
urlbase = 'http://developer.symbian.org/main/tools_and_kits/downloads/' |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
214 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
215 |
viewid = 5 # default to Symbian^3 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
216 |
if version[0] == 2: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
217 |
viewid= 1 # Symbian^2 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
218 |
if version[0] == 3: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
219 |
viewid= 5 # Symbian^3 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
220 |
url = urlbase + ('view.php?id=%d'% viewid) + 'vId=' + version |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
221 |
|
125
c107e11c37e8
Mark all requests with the "downloadkit.py script" User Agent string, so that we can spot them in the HTTP logs
William Roberts <williamr@symbian.org>
parents:
124
diff
changeset
|
222 |
req = urllib2.Request(url, None, headers) |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
223 |
response = urllib2.urlopen(req) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
224 |
doc=response.read() |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
225 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
226 |
# BeatifulSoup chokes on some javascript, so we cut away everything before the <body> |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
227 |
try: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
228 |
bodystart=doc.find('<body>') |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
229 |
doc = doc[bodystart:] |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
230 |
except: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
231 |
pass |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
232 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
233 |
threadlist = [] |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
234 |
# let's hope the HTML format never changes... |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
235 |
# <a href='download.php?id=27&cid=60&iid=270' title='src_oss_mw.zip'> ...</a> |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
236 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
237 |
soup=BeautifulSoup(doc) |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
238 |
results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$")) |
128
249ca6c587b6
Changes to control the order of downloading, and hopefully the resulting unzipping (for patches in particular)
William Roberts <williamr@symbian.org>
parents:
127
diff
changeset
|
239 |
results.sort(orderResults) |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
240 |
for result in results: |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
241 |
downloadurl = urlbase + result['href'] |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
242 |
filename = result['title'] |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
243 |
|
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
244 |
if options.nosrc and re.match(r"(src_sfl|src_oss)", filename) : |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
245 |
continue # no snapshots of Mercurial source thanks... |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
246 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
247 |
if download_file(filename, downloadurl) != True : |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
248 |
continue # download failed |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
249 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
250 |
# unzip the file (if desired) |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
251 |
if re.match(r"patch", filename): |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
252 |
complete_outstanding_unzips() # ensure that the thing we are patching is completed first |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
253 |
|
127
c63eca238256
Make sure that tools_epoc.zip gets unpacked
William Roberts <williamr@symbian.org>
parents:
126
diff
changeset
|
254 |
if re.match(r"(bin|tools).*\.zip", filename): |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
255 |
schedule_unzip(filename, 1, 0) # unzip once, don't delete |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
256 |
elif re.match(r"src_.*\.zip", filename): |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
257 |
schedule_unzip(filename, 1, 1) # zip of zips, delete top level |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
258 |
elif re.match(r"build_BOM.zip", filename): |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
259 |
schedule_unzip(filename, 1, 1) # unpack then delete zip as it's not needed again |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
260 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
261 |
# wait for the unzipping threads to complete |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
262 |
complete_outstanding_unzips() |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
263 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
264 |
return 1 |
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
265 |
|
139
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
266 |
parser = OptionParser(usage="Usage: %prog [options] version", version="%prog 0.4") |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
267 |
parser.add_option("-n", "--dryrun", action="store_true", dest="dryrun", |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
268 |
help="print the files to be downloaded, the 7z commands, and the recommended deletions") |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
269 |
parser.add_option("--nosrc", action="store_true", dest="nosrc", |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
270 |
help="Don't download any of the source code available directly from Mercurial") |
139
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
271 |
parser.add_option("--nounzip", action="store_true", dest="nounzip", |
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
272 |
help="Just download, don't unzip or delete any files") |
9baccbcc5509
version 0.4 - added --nounzip option to suppress the unzipping and deletion
William Roberts <williamr@symbian.org>
parents:
138
diff
changeset
|
273 |
parser.set_defaults(dryrun=False, nosrc=False, nounzip=False) |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
274 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
275 |
(options, args) = parser.parse_args() |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
276 |
if len(args) != 1: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
277 |
parser.error("Must supply a PDK version, e.g. 3.0.e") |
124
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
278 |
|
b60a149520e7
Added downloadkit.py - script to download and unpack a PDK
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
279 |
login(True) |
138
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
280 |
downloadkit(args[0]) |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
281 |
|
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
282 |
if options.dryrun: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
283 |
print "# instructions for downloading kit " + args[0] |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
284 |
for download in download_list: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
285 |
print download |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
286 |
for command in unzip_list: |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
287 |
print command |
7b2d146ef884
version 0.3 - add command line processing, --dryrun option, --nosrc option
William Roberts <williamr@symbian.org>
parents:
128
diff
changeset
|
288 |