+def myurlgrab2(url, filename):
+ logger = logging.getLogger(__name__)
+ if url.startswith("file:/"):
+ filepath = "/%s" % url.replace("file:", "").lstrip('/')
+ if not os.path.exists(filepath):
+ raise RepoError("URLGrabber error: can't find file %s" % url)
+ if url.endswith('.rpm'):
+ return filepath
+ else:
+ copyfile(filepath, filename)
+ logger.info('copy file ' + filepath)
+ else:
+ try:
+ with contextlib.closing(urllib2.urlopen(url)) as op:
+ with open(filename, 'w') as f:
+ f.write(op.read())
+ logger.info('download file from ' + str(url))
+ except urllib2.HTTPError as err:
+ if err.code == 404:
+ msg = 'The requested url was not found (%s)' % url
+ else:
+ msg = str(err)
+ raise TICError(msg)
+ return filename