userland-fetch revision 3770
911N/A# The contents of this file are subject to the terms of the 851N/A# Common Development and Distribution License (the "License"). 332N/A# You may not use this file except in compliance with the License. 332N/A# See the License for the specific language governing permissions 332N/A# and limitations under the License. 332N/A# When distributing Covered Code, include this CDDL HEADER in each 332N/A# If applicable, add the following below this CDDL HEADER, with the 332N/A# fields enclosed by brackets "[]" replaced with your own identifying 332N/A# information: Portions Copyright [yyyy] [name of copyright owner] 332N/A# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 332N/A# userland-fetch - a file download utility 332N/A# A simple program similiar to wget(1), but handles local file copy, ignores 332N/A# directories, and verifies file hashes. 911N/A """ Function to decode and print IOError type exception """ 332N/A """Given paths to a file and a detached PGP signature, verify that 493N/A the signature is valid for the file. Current configuration allows for 493N/A unrecognized keys to be downloaded as necessary.""" 332N/A # Find the root of the repo so that we can point GnuPG at the right 493N/A # configuration and keyring. # Skip the permissions warning: none of the information here is private, # so not having to worry about getting mercurial keeping the directory # unreadable is just simplest. # If the executable simply couldn't be found, just skip the # Only print GnuPG's output when there was a problem. """Given a file-like object and a hash string, verify that the hash matches the file contents.""" # force migration away from sha1 """Given a file path and a hash string, verify that the hash matches the """Given a file path and a hash string, verify that the hash matches the payload (uncompressed content) of the file.""" """Download the content at the given URL to the given filename (defaulting to the basename of the URL if not given. If 'quiet' is True, throw away any error messages. Returns the name of the file to which the content was donloaded.""" # 3xx, 4xx and 5xx (f|ht)tp codes designate unsuccessfull action # return the name of the file that we downloaded the data to. """Returns a list of URLs where the file 'filename' might be found, If 'filename' is None, then the list will simply contain 'url'. # filename should always be first # command line url is a fallback, so it's last """Attempts to download a file from a number of possible locations. Generates a list of paths where the file ends up on the local filesystem. This is a generator because while a download might be successful, the signature or hash may not validate, and the caller may want to try again from the next location. The 'link_arg' argument is a boolean which, when True, specifies that if the source is not a remote URL and not already found where it should be, to make a symlink to the source rather than copying it. print "Source %s..." %
url,
print "not found, skipping file copy" elif scheme in [
'http',
'https',
'ftp' ]:
print "\n downloading...",
print "Usage: %s [-f|--file (file)] [-l|--link] [-h|--hash (hash)] " \
"[-s|--search (search-dir)] [-S|--sigurl (signature-url)] --url (url)" % \
["file=", "link", "hash=", "search=", "sigurl=", "url="]) if opt in [
"-f",
"--file" ]:
elif opt in [
"-l",
"--link" ]:
elif opt in [
"-h",
"--hash" ]:
elif opt in [
"-s",
"--search" ]:
elif opt in [
"-S",
"--sigurl" ]:
elif opt in [
"-u",
"--url" ]:
print "\n validating signature...",
print "skipping (no signature URL)" # Put the signature file in the same directory as the # file we're downloading. # Validate with the first signature we find. print "failed (couldn't fetch signature)" print " validating hash...",
print "skipping (no hash)" # If the signature validated, then we assume # that the expected hash is just a typo, but we print "corruption detected" # An invalid hash shouldn't cause us to remove # the target file if the signature was valid.