2015-12-06 18:39:41 +00:00
|
|
|
import os, shutil
|
2015-12-06 16:27:26 +00:00
|
|
|
from distutils.dir_util import copy_tree
|
2015-12-06 18:39:41 +00:00
|
|
|
from . import config, constants, shell
|
2015-12-04 08:48:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clone_public_data():
|
2015-12-06 16:15:04 +00:00
|
|
|
if os.path.isdir(constants.PUBLIC_DATA_DIR):
|
|
|
|
initial = os.getcwd()
|
|
|
|
go_to_data()
|
2015-12-06 18:39:41 +00:00
|
|
|
out, error = shell.call("git pull")
|
2015-12-06 16:15:04 +00:00
|
|
|
os.chdir(initial)
|
2015-12-06 18:39:41 +00:00
|
|
|
if error:
|
|
|
|
print("Error:", out)
|
|
|
|
return error
|
|
|
|
|
|
|
|
out, error = shell.call(
|
|
|
|
"git clone -b master --single-branch {} {}".format(
|
|
|
|
config.get('public_repo'),
|
|
|
|
constants.PUBLIC_DATA_DIR)
|
|
|
|
)
|
|
|
|
return error
|
2015-12-04 08:48:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clone_private_data():
|
2015-12-06 16:15:04 +00:00
|
|
|
exit_code = 0
|
|
|
|
if os.path.isdir(constants.PRIVATE_DATA_DIR):
|
|
|
|
initial = os.getcwd()
|
|
|
|
os.chdir(constants.PRIVATE_DATA_DIR)
|
2015-12-06 18:39:41 +00:00
|
|
|
out, error = shell.call("git pull")
|
2015-12-06 16:15:04 +00:00
|
|
|
os.chdir(initial)
|
2015-12-06 18:39:41 +00:00
|
|
|
if error:
|
|
|
|
print("Error:", out)
|
|
|
|
return error
|
2015-12-06 16:15:04 +00:00
|
|
|
else:
|
2015-12-06 18:39:41 +00:00
|
|
|
out, error = shell.call(
|
|
|
|
"git clone -b master --single-branch {} {}".format(
|
|
|
|
config.get('private_repo'),
|
|
|
|
constants.PRIVATE_DATA_DIR)
|
|
|
|
)
|
|
|
|
if error:
|
|
|
|
return error
|
2015-12-06 14:20:55 +00:00
|
|
|
|
2015-12-06 16:27:26 +00:00
|
|
|
copy_tree(
|
2015-12-06 14:20:55 +00:00
|
|
|
constants.PRIVATE_DATA_DIR,
|
|
|
|
constants.PUBLIC_DATA_DIR
|
|
|
|
)
|
2015-12-06 18:39:41 +00:00
|
|
|
return error
|
2015-12-06 16:15:04 +00:00
|
|
|
|
2015-12-05 23:25:26 +00:00
|
|
|
|
|
|
|
def has_data(data):
|
|
|
|
public_path = os.path.join(constants.PUBLIC_DATA_DIR, data)
|
|
|
|
private_path = os.path.join(constants.PRIVATE_DATA_DIR, data)
|
|
|
|
return os.path.isdir(public_path) or os.path.isdir(private_path)
|
2015-12-06 14:20:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def go_to_data(subdir=''):
|
|
|
|
path = os.path.join(constants.PUBLIC_DATA_DIR, subdir)
|
|
|
|
os.chdir(path)
|
|
|
|
return path
|
2015-12-06 18:39:41 +00:00
|
|
|
|
|
|
|
def clean():
|
|
|
|
shutil.rmtree(constants.PUBLIC_DATA_DIR)
|
|
|
|
shutil.rmtree(constants.PRIVATE_DATA_DIR)
|