2 # Copyright (c) 2016 Samsung Electronics Co., Ltd
4 # Licensed under the Flora License, Version 1.1 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://floralicense.org/license/
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
23 from urlgrabber import grabber
24 from tic.utils.error import TICError
25 from tic.utils import process
26 from tic.utils.file import copyfile
27 from tic.config import configmgr
29 def myurlgrab2(url, filename):
30 logger = logging.getLogger(__name__)
31 if url.startswith("file:/"):
32 filepath = "/%s" % url.replace("file:", "").lstrip('/')
33 if not os.path.exists(filepath):
34 raise TICError(configmgr.message['repo_not_found'] % url)
35 if url.endswith('.rpm'):
38 copyfile(filepath, os.path.dirname(filename))
39 logger.info('copy file ' + filepath)
42 with contextlib.closing(urllib2.urlopen(url)) as op:
43 with open(filename, 'w') as f:
45 logger.info('download file from %s' % str(url))
46 except urllib2.HTTPError as err:
48 msg = configmgr.message['repo_not_found'] % url
53 except urllib2.URLError as err:
55 raise TICError(configmgr.message['server_error'])
58 def myurlgrab(url, filename, proxies, progress_obj = None):
59 logger = logging.getLogger(__name__)
60 g = grabber.URLGrabber()
61 if url.startswith("file:/"):
62 filepath = "/%s" % url.replace("file:", "").lstrip('/')
63 if not os.path.exists(filepath):
64 raise TICError("URLGrabber error: can't find file %s" % url)
65 if url.endswith('.rpm'):
68 # untouch repometadata in source path
69 process.run(['cp', '-f', filepath, filename])
70 logger.info('copy file ' + filepath)
73 # cast url to str here, sometimes it can be unicode,
74 # but pycurl only accept str
75 filename = g.urlgrab(url=str(url),
77 ssl_verify_host=False,
78 ssl_verify_peer=False,
80 http_headers=(('Pragma', 'no-cache'),),
82 progress_obj=progress_obj)
83 logger.info('download file from ' + str(url))
84 except grabber.URLGrabError as err:
86 msg = 'The requested url was not found (%s)' % url
95 if __name__ == '__main__':