def download_from_github(args):
if os.path.exists('dappled.yml'):
yml = ruamel.yaml.load(open('dappled.yml').read(), ruamel.yaml.RoundTripLoader)
else:
print('dappled.yml not found; please run "dappled init" first')
sys.exit()
if not yml.get('github'):
return False
github_repo = yml['github']
url = 'https://github.com/{owner}/{repo}/archive/{sha}.zip'.format(**github_repo)
filename, headers = urllib.urlretrieve(url)
with zipfile.ZipFile(filename) as zf:
prefix = None
for name in zf.namelist():
if prefix is None: # assume first entry is the directory name
prefix = name
continue
path = name.replace(prefix, '')
if path in ('dappled.yml', yml['filename'], 'environment.yml'):
continue
with open(path, 'wb') as f:
f.write(zf.read(name))
评论列表
文章目录