2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
24 from urlgrabber import grabber
25 from tic.utils.error import TICError, RepoError
26 from tic.utils import process
29 def myurlgrab(url, filename, proxies, progress_obj = None):
30 logger = logging.getLogger(__name__)
31 g = grabber.URLGrabber()
33 if url.startswith("file:/"):
34 filepath = "/%s" % url.replace("file:", "").lstrip('/')
35 if not os.path.exists(filepath):
36 raise RepoError("URLGrabber error: can't find file %s" % url)
37 if url.endswith('.rpm'):
40 # untouch repometadata in source path
41 process.run(['cp', '-f', filepath, filename])
42 logger.info('copy file ' + filepath)
45 # cast url to str here, sometimes it can be unicode,
46 # but pycurl only accept str
47 filename = g.urlgrab(url=str(url),
49 ssl_verify_host=False,
50 ssl_verify_peer=False,
52 http_headers=(('Pragma', 'no-cache'),),
54 progress_obj=progress_obj)
55 logger.info('download file from ' + str(url))
56 except grabber.URLGrabError as err:
58 msg = 'The requested url was not found (%s)' % url
67 if __name__ == '__main__':
69 full_url = 'file://home/shinchulwoo/project/tic_view.json'
70 filename = '/var/tmp/tic_view.json'
71 myurlgrab(full_url, filename, None)
73 full_url = 'https://download.tizen.org/snapshots/tizen/mobile/latest/repos/arm64-wayland/packages/repodata/repomd.xml'
74 filename = '/var/tmp/repomd.xml'
75 myurlgrab(full_url, filename, None)