def download_fzf_binary(plat, arch, overwrite=False, access_token=None):
bin_path = fzf_windows_bin_path if plat == 'windows' else fzf_bin_path
if overwrite or not os.path.isfile(bin_path):
asset = get_fzf_binary_url(plat, arch, access_token)
url, ext = asset
if access_token:
url = '{0}?access_token={1}'.format(url, access_token)
try:
r = urllib2.urlopen(url)
except urllib2.HTTPError as e:
if e.code == 403 and e.info().get('X-RateLimit-Remaining') == 0:
raise RuntimeError(
'GitHub rate limit reached. To increate the limit use '
'-g/--github-access-token option.\n ' + str(e)
)
elif e.code == 401 and access_token:
raise RuntimeError('Invalid GitHub access token.')
raise
extract(r, ext, bin_path)
r.close()
mode = os.stat(bin_path).st_mode
if not (mode & 0o111):
os.chmod(bin_path, mode | 0o111)
评论列表
文章目录