import urllib2
import contextlib
from urlgrabber import grabber
-from tic.utils.error import TICError, RepoError
+from tic.utils.error import TICError
from tic.utils import process
from tic.utils.file import copyfile
+from tic.config import configmgr
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)
+ raise TICError(configmgr.message['repo_not_found'] % url)
if url.endswith('.rpm'):
return filepath
else:
- copyfile(filepath, filename)
+ copyfile(filepath, os.path.dirname(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))
+ logger.info('download file from %s' % str(url))
except urllib2.HTTPError as err:
if err.code == 404:
- msg = 'The requested url was not found (%s)' % url
+ msg = configmgr.message['repo_not_found'] % url
else:
msg = str(err)
+ logger.info(err)
raise TICError(msg)
+ except urllib2.URLError as err:
+ logger.info(err)
+ raise TICError(configmgr.message['server_error'])
return filename
def myurlgrab(url, filename, proxies, progress_obj = None):
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)
+ raise TICError("URLGrabber error: can't find file %s" % url)
if url.endswith('.rpm'):
return filepath
else: