2015-02-01 02:22:23 +00:00
|
|
|
from __future__ import print_function
|
2015-01-02 10:44:41 +00:00
|
|
|
from os import path
|
2015-10-18 10:35:04 +00:00
|
|
|
import sys
|
2015-01-02 10:44:41 +00:00
|
|
|
import os
|
|
|
|
import tarfile
|
|
|
|
import shutil
|
2015-01-31 02:51:56 +00:00
|
|
|
import plac
|
2015-01-02 10:44:41 +00:00
|
|
|
|
2015-10-19 06:32:41 +00:00
|
|
|
from . import uget
|
|
|
|
|
2015-02-07 16:32:33 +00:00
|
|
|
# TODO: Read this from the same source as the setup
|
2015-10-13 02:46:17 +00:00
|
|
|
VERSION = '0.9.5'
|
2015-01-02 10:44:41 +00:00
|
|
|
|
2015-09-22 00:26:01 +00:00
|
|
|
AWS_STORE = 'https://s3-us-west-1.amazonaws.com/media.spacynlp.com'
|
2015-01-30 09:27:14 +00:00
|
|
|
|
2015-02-07 16:32:33 +00:00
|
|
|
ALL_DATA_DIR_URL = '%s/en_data_all-%s.tgz' % (AWS_STORE, VERSION)
|
2015-01-30 07:04:01 +00:00
|
|
|
|
2015-10-18 10:35:04 +00:00
|
|
|
DEST_DIR = path.join(path.dirname(path.abspath(__file__)), 'data')
|
2015-01-02 10:44:41 +00:00
|
|
|
|
2015-10-18 10:35:04 +00:00
|
|
|
|
2015-10-20 17:11:29 +00:00
|
|
|
def download_file(url, path):
|
|
|
|
return uget.download(url, path, console=sys.stdout)
|
2015-01-02 10:44:41 +00:00
|
|
|
|
2015-01-30 07:04:01 +00:00
|
|
|
|
2015-10-20 17:11:29 +00:00
|
|
|
def install_data(url, path, filename):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except FileExistsError:
|
|
|
|
pass
|
2015-01-17 05:21:17 +00:00
|
|
|
|
2015-10-20 17:11:29 +00:00
|
|
|
filename = download_file(url, os.path.join(path, filename))
|
|
|
|
t = tarfile.open(filename)
|
|
|
|
t.extractall(path)
|
2015-01-17 05:21:17 +00:00
|
|
|
|
|
|
|
|
2015-10-18 10:35:04 +00:00
|
|
|
@plac.annotations(
|
|
|
|
force=("Force overwrite", "flag", "f", bool),
|
|
|
|
)
|
|
|
|
def main(data_size='all', force=False):
|
|
|
|
if force and path.exists(DEST_DIR):
|
2015-04-12 05:04:10 +00:00
|
|
|
shutil.rmtree(DEST_DIR)
|
2015-10-18 10:35:04 +00:00
|
|
|
|
2015-10-20 17:11:29 +00:00
|
|
|
filename = ALL_DATA_DIR_URL.rsplit('/', 1)[1]
|
|
|
|
|
|
|
|
if os.path.exists(DEST_DIR):
|
|
|
|
# ugly hack to find out whether something other
|
|
|
|
# than the currently wanted file lives there
|
|
|
|
if len([f for f in os.listdir(DEST_DIR) if f != filename]):
|
|
|
|
print('data already installed at %s, overwrite with --force' % DEST_DIR)
|
|
|
|
sys.exit(1)
|
2015-10-18 10:35:04 +00:00
|
|
|
|
2015-10-20 17:11:29 +00:00
|
|
|
install_data(ALL_DATA_DIR_URL, DEST_DIR, filename)
|
2015-01-02 10:44:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-01-31 02:51:56 +00:00
|
|
|
plac.call(main)
|