userland-fetch revision 137
199767f8919635c4928607450d9e0abb932109ceToomas Soome# CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome# The contents of this file are subject to the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Common Development and Distribution License (the "License").
199767f8919635c4928607450d9e0abb932109ceToomas Soome# You may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome# See the License for the specific language governing permissions
199767f8919635c4928607450d9e0abb932109ceToomas Soome# and limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome# When distributing Covered Code, include this CDDL HEADER in each
199767f8919635c4928607450d9e0abb932109ceToomas Soome# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome# If applicable, add the following below this CDDL HEADER, with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome# fields enclosed by brackets "[]" replaced with your own identifying
199767f8919635c4928607450d9e0abb932109ceToomas Soome# information: Portions Copyright [yyyy] [name of copyright owner]
199767f8919635c4928607450d9e0abb932109ceToomas Soome# CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome# fetch.py - a file download utility
199767f8919635c4928607450d9e0abb932109ceToomas Soome# A simple program similiar to wget(1), but handles local file copy, ignores
199767f8919635c4928607450d9e0abb932109ceToomas Soome# directories, and verifies file hashes.
199767f8919635c4928607450d9e0abb932109ceToomas Soome """ Function to decode and print IOError type exception """
199767f8919635c4928607450d9e0abb932109ceToomas Soome expr_bz = re.compile('.+\.bz2$', re.IGNORECASE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printIOError(e, "Can't open archive " + filename)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printIOError(e, "Can't open file " + filename + " for writing")
199767f8919635c4928607450d9e0abb932109ceToomas Soome # return the name of the file that we downloaded the data to.
199767f8919635c4928607450d9e0abb932109ceToomas Soome urls = [ base + '/' + file for base in search ]
199767f8919635c4928607450d9e0abb932109ceToomas Soome # filename should always be first
199767f8919635c4928607450d9e0abb932109ceToomas Soome # command line url is a fallback, so it's last
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "Usage: %s [-f|--file (file)] [-l|--link] [-h|--hash (hash)] [-s|--search (search-dir)] --url (url)" % (sys.argv[0].split('/')[-1])
199767f8919635c4928607450d9e0abb932109ceToomas Soome # FLUSH STDOUT
199767f8919635c4928607450d9e0abb932109ceToomas Soome sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome opts, args = getopt.getopt(sys.argv[1:], "f:h:ls:u:",
199767f8919635c4928607450d9e0abb932109ceToomas Soome for url in download_paths(search_list, file_arg, url_arg):
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "not found, skipping file copy"
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "\n copying..."
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "\n linking..."
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "\n downloading...",
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "failed"
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "\n validating...",
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "skipping (no hash)"
199767f8919635c4928607450d9e0abb932109ceToomas Soome print "corruption detected"