# - S-Core Co., Ltd
import os
+import logging
+import urllib2
+import contextlib
from urlgrabber import grabber
from tic.utils.error import TICError, RepoError
from tic.utils import process
+from tic.utils.file import copyfile
+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
def myurlgrab(url, filename, proxies, progress_obj = None):
+ logger = logging.getLogger(__name__)
g = grabber.URLGrabber()
-
if url.startswith("file:/"):
filepath = "/%s" % url.replace("file:", "").lstrip('/')
if not os.path.exists(filepath):
else:
# untouch repometadata in source path
process.run(['cp', '-f', filepath, filename])
+ logger.info('copy file ' + filepath)
else:
try:
# cast url to str here, sometimes it can be unicode,
http_headers=(('Pragma', 'no-cache'),),
quote=0,
progress_obj=progress_obj)
+ logger.info('download file from ' + str(url))
except grabber.URLGrabError as err:
if err.code == 22:
msg = 'The requested url was not found (%s)' % url
return filename
if __name__ == '__main__':
- # file url
- full_url = 'file://home/shinchulwoo/project/tic_view.json'
- filename = '/var/tmp/tic_view.json'
- myurlgrab(full_url, filename, None)
- # http url
- full_url = 'https://download.tizen.org/snapshots/tizen/mobile/latest/repos/arm64-wayland/packages/repodata/repomd.xml'
- filename = '/var/tmp/repomd.xml'
- myurlgrab(full_url, filename, None)
-
-
+ pass
\ No newline at end of file