Skip to content

Commit

Permalink
Merge pull request #249 from Shougo/dl-kaoriya-vim
Browse files Browse the repository at this point in the history
Use the latest KaoriYa Vim on AppVeyor (Issue #248)
  • Loading branch information
Shougo committed Apr 10, 2016
2 parents 9269f38 + 9d1bfea commit b05d302
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/appveyor.bat
Expand Up @@ -106,7 +106,7 @@ goto :eof
:: ----------------------------------------------------------------------
:: Install Vim and themis
echo Downloading Vim
appveyor DownloadFile https://github.com/koron/vim-kaoriya/releases/download/v7.4.1655-20160326/vim74-kaoriya-win%BIT%-20160326.zip -FileName vim.zip
py tools\dl-kaoriya-vim.py --arch win%BIT% --filename vim.zip
echo Installing Vim
7z x vim.zip > nul
git clone -q https://github.com/thinca/vim-themis.git themis --depth=1
Expand Down
60 changes: 60 additions & 0 deletions tools/dl-kaoriya-vim.py
@@ -0,0 +1,60 @@
#!/usr/bin/python3

# Download the latest KaoriYa Vim from the GitHub release

import argparse
import calendar
import io
import json
import os
import sys
import time
import urllib.request, urllib.error

# Repository Name
repo_name = 'koron/vim-kaoriya'
gh_release_url = 'https://api.github.com/repos/' + repo_name + '/releases/latest'

# Parse arguments
parser = argparse.ArgumentParser(
description='Download the latest KaoriYa Vim from the GitHub release')
parser.add_argument('-f', '--force', action='store_true',
help='overwrite the download file')
parser.add_argument('-n', '--filename', type=str, action='store',
help='filename to save')
parser.add_argument('-a', '--arch', type=str, action='store',
choices=['all', 'win32', 'win64'], default='all',
help='architecture to download')
args = parser.parse_args()

if args.filename and args.arch == 'all':
parser.error('-a must be specified when you specify -n.')

# Get information of GitHub release
# see: https://developer.github.com/v3/repos/releases/
try:
response = urllib.request.urlopen(gh_release_url)
except urllib.error.HTTPError:
print('GitHub release not found.', out=sys.stderr)
exit(1)

rel_info = json.load(io.StringIO(str(response.read(), 'utf-8')))
print('Last release:', rel_info['name'])
print('Created at:', rel_info['created_at'])

# Download the files
for asset in rel_info['assets']:
if args.filename:
name = args.filename
else:
name = asset['name']
if args.arch != 'all' and asset['name'].find(args.arch) < 0:
continue
if os.path.isfile(name) and not args.force:
print('File exists:', name)
continue
print('Downloading to:', name)
urllib.request.urlretrieve(asset['browser_download_url'], name)
# Set timestamp
asset_time = time.strptime(asset['updated_at'], '%Y-%m-%dT%H:%M:%SZ')
os.utime(name, times=(time.time(), calendar.timegm(asset_time)))

0 comments on commit b05d302

Please sign in to comment.