17 # fields enclosed by brackets "[]" replaced with your own identifying |
17 # fields enclosed by brackets "[]" replaced with your own identifying |
18 # information: Portions Copyright [yyyy] [name of copyright owner] |
18 # information: Portions Copyright [yyyy] [name of copyright owner] |
19 # |
19 # |
20 # CDDL HEADER END |
20 # CDDL HEADER END |
21 # |
21 # |
22 # Copyright (c) 2010, Oracle and/or it's affiliates. All rights reserved. |
22 # Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
23 # |
23 # |
24 # |
24 # |
25 # fetch.py - a file download utility |
25 # fetch.py - a file download utility |
26 # |
26 # |
27 # A simple program similiar to wget(1), but handles local file copy, ignores |
27 # A simple program similiar to wget(1), but handles local file copy, ignores |
156 scheme, path = splittype(url) |
153 scheme, path = splittype(url) |
157 name = file_arg |
154 name = file_arg |
158 |
155 |
159 if scheme in [ None, 'file' ]: |
156 if scheme in [ None, 'file' ]: |
160 if os.path.exists(path) == False: |
157 if os.path.exists(path) == False: |
161 print "not found, skipping" |
158 print "not found, skipping file copy" |
162 continue |
159 continue |
163 elif name != path: |
160 elif name != path: |
164 if link_arg == False: |
161 if link_arg == False: |
165 print "copying...", |
162 print "\n copying..." |
166 shutil.copy2(path, name) |
163 shutil.copy2(path, name) |
167 else: |
164 else: |
168 print "linking...", |
165 print "\n linking..." |
169 os.symlink(path, name) |
166 os.symlink(path, name) |
170 else: |
167 else: |
171 pass |
168 pass |
172 elif scheme in [ 'http', 'https', 'ftp' ]: |
169 elif scheme in [ 'http', 'https', 'ftp' ]: |
173 print "downloading...", |
170 print "\n downloading...", |
174 name = download(url, file_arg) |
171 name = download(url, file_arg) |
175 if name == None: |
172 if name == None: |
176 print "failed" |
173 print "failed" |
177 continue |
174 continue |
178 |
175 |
179 print "validating...", |
176 print "\n validating...", |
180 if validate(name, hash_arg): |
177 if hash_arg == None: |
|
178 print "skipping (no hash)" |
|
179 sys.exit(0) |
|
180 |
|
181 realhash = validate(name, hash_arg) |
|
182 if realhash == hash_arg: |
181 print "ok" |
183 print "ok" |
182 sys.exit(0) |
184 sys.exit(0) |
183 else: |
185 else: |
184 print "corrupt" |
186 print "corruption detected" |
|
187 print " expected: %s" % hash_arg |
|
188 print " actual: %s" % realhash |
185 |
189 |
186 try: |
190 try: |
187 os.remove(name) |
191 os.remove(name) |
188 except OSError: |
192 except OSError: |
189 pass |
193 pass |