-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (c) 2018 Yousong Zhou <yszhou4tech@gmail.com>
#
import subprocess
import sys
import time
-import urllib2
+import urllib.request
TMPDIR = os.environ.get('TMP_DIR') or '/tmp'
TMPDIR_DL = os.path.join(TMPDIR, 'dl')
self.cache[k] = (ts, updated)
def _cache_flush(self, fout):
- cache = sorted(self.cache.iteritems(), cmp=lambda a, b: b[1][1] - a[1][1])
+ cache = sorted(self.cache.items(), key=lambda a: a[1][1])
cache = cache[:self.__cachen]
self.cache = {}
os.ftruncate(fout.fileno(), 0)
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'OpenWrt',
}
- req = urllib2.Request(url, headers=headers)
+ req = urllib.request.Request(url, headers=headers)
sslcontext = ssl._create_unverified_context()
- fileobj = urllib2.urlopen(req, context=sslcontext)
+ fileobj = urllib.request.urlopen(req, context=sslcontext)
return fileobj
def _error(self, msg):
parser.add_argument('--source', help='Source tarball filename')
parser.add_argument('--hash', help='Source tarball\'s expected sha256sum')
args = parser.parse_args()
- method = DownloadGitHubTarball(args)
try:
+ method = DownloadGitHubTarball(args)
method.download()
- except Exception:
- sys.stderr.write('download {} from {} failed\n'.format(args.source, args.url))
- raise
+ except Exception as ex:
+ sys.stderr.write('{}: Download from {} failed\n'.format(args.source, args.url))
+ sys.stderr.write('{}\n'.format(ex))
+ sys.exit(1)
if __name__ == '__main__':
main()