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.
23 from urlgrabber import grabber
24 from tic.utils.error import TICError, RepoError
25 from tic.utils import process
28 def myurlgrab(url, filename, proxies, progress_obj = None):
29 g = grabber.URLGrabber()
31 if url.startswith("file:/"):
32 filepath = "/%s" % url.replace("file:", "").lstrip('/')
33 if not os.path.exists(filepath):
34 raise RepoError("URLGrabber error: can't find file %s" % url)
35 if url.endswith('.rpm'):
38 # untouch repometadata in source path
39 process.run(['cp', '-f', filepath, filename])
42 # cast url to str here, sometimes it can be unicode,
43 # but pycurl only accept str
44 filename = g.urlgrab(url=str(url),
46 ssl_verify_host=False,
47 ssl_verify_peer=False,
49 http_headers=(('Pragma', 'no-cache'),),
51 progress_obj=progress_obj)
52 except grabber.URLGrabError as err:
54 msg = 'The requested url was not found (%s)' % url
63 if __name__ == '__main__':
65 full_url = 'file://home/shinchulwoo/project/tic_view.json'
66 filename = '/var/tmp/tic_view.json'
67 myurlgrab(full_url, filename, None)
69 full_url = 'https://download.tizen.org/snapshots/tizen/mobile/latest/repos/arm64-wayland/packages/repodata/repomd.xml'
70 filename = '/var/tmp/repomd.xml'
71 myurlgrab(full_url, filename, None)