-#!/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')
def set(self, k, v):
"""Update timestamp with ``k``."""
fileno = os.open(self.cachef, os.O_RDWR | os.O_CREAT)
- with os.fdopen(fileno, 'wb+') as f:
+ with os.fdopen(fileno, 'w+') as f:
try:
fcntl.lockf(fileno, fcntl.LOCK_EX)
self._cache_init(f)
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)
version_is_sha1sum = len(self.version) == 40
if not version_is_sha1sum:
apis.insert(0, apis.pop())
+ reasons = ''
for api in apis:
url = api['url']
attr_path = api['attr_path']
self.commit_ts = ct
self.commit_ts_cache.set(url, ct)
return
- except Exception:
- pass
- raise self._error('Cannot fetch commit ts: {}'.format(url))
+ except Exception as e:
+ reasons += '\n' + (" {}: {}".format(url, e))
+ raise self._error('Cannot fetch commit ts:{}'.format(reasons))
def _init_commit_ts_remote_get(self, url, attrpath):
resp = self._make_request(url)
'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):