def clone_bundle(path, prefix=None, bundle_name=None): """ Clone the bundle (located at `path`) by creating a new environment at `prefix` (unless prefix is None or the prefix directory already exists) """ try: t = tarfile.open(path, 'r:*') meta = json.load(t.extractfile('info/index.json')) except tarfile.ReadError: raise RuntimeError('bad tar archive: %s' % path) except KeyError: raise RuntimeError("no archive 'info/index.json' in: %s" % (path)) if prefix and not isdir(prefix): for m in t.getmembers(): if m.path.startswith((BDP, 'info/')): continue t.extract(m, path=prefix) dists = discard_conda('-'.join(s.split()) for s in meta.get('depends', [])) actions = plan.ensure_linked_actions(dists, prefix) index = get_index() plan.display_actions(actions, index) plan.execute_actions(actions, index, verbose=True) bundle_dir = abspath( expanduser('~/bundles/%s' % (bundle_name or meta.get('bundle_name')))) for m in t.getmembers(): if m.path.startswith(BDP): targetpath = join(bundle_dir, m.path[len(BDP):]) t._extract_member(m, targetpath) t.close()
def clone_bundle(path, prefix=None, bundle_name=None): """ Clone the bundle (located at `path`) by creating a new environment at `prefix` (unless prefix is None or the prefix directory already exists) """ try: t = tarfile.open(path, 'r:*') meta = json.load(t.extractfile('info/index.json')) except tarfile.ReadError: raise RuntimeError('bad tar archive: %s' % path) except KeyError: raise RuntimeError("no archive 'info/index.json' in: %s" % (path)) if prefix and not isdir(prefix): for m in t.getmembers(): if m.path.startswith((BDP, 'info/')): continue t.extract(m, path=prefix) dists = discard_conda('-'.join(s.split()) for s in meta.get('depends', [])) actions = plan.ensure_linked_actions(dists, prefix) index = get_index() plan.display_actions(actions, index) plan.execute_actions(actions, index, verbose=True) bundle_dir = abspath(expanduser('~/bundles/%s' % (bundle_name or meta.get('bundle_name')))) for m in t.getmembers(): if m.path.startswith(BDP): targetpath = join(bundle_dir, m.path[len(BDP):]) t._extract_member(m, targetpath) t.close()
def clone_analysispackage(path, prefix=None, analysispackage_name=None, data_path=None): """ Clone the analysispackage (located at `path`) by creating a new environment at `prefix` (unless prefix is None or the prefix directory already exists) """ try: t = tarfile.open(path, 'r:*') meta = json.load(t.extractfile('info/index.json')) except tarfile.ReadError: raise RuntimeError('bad tar archive: %s' % path) except KeyError: raise RuntimeError("no archive 'info/index.json' in: %s" % (path)) if prefix and isdir(prefix): print("erasing old environment at %s" % prefix) shutil.rmtree(prefix) if prefix and not isdir(prefix): for m in t.getmembers(): if m.path.startswith((BDP, 'info/')): continue t.extract(m, path=prefix) dists = discard_conda('-'.join(s.split()) for s in meta.get('depends', [])) actions = plan.ensure_linked_actions(dists, prefix) index = get_index() plan.display_actions(actions, index) plan.execute_actions(actions, index, verbose=False) if not data_path: analysispackage_dir = abspath( expanduser( '~/analysispackages/%s' % (analysispackage_name or meta.get('analysispackage_name')))) else: analysispackage_dir = data_path for m in t.getmembers(): if m.path.startswith(BDP): targetpath = join(analysispackage_dir, m.path[len(BDP):]) t._extract_member(m, targetpath) with open(join(data_path, ".metadata.json"), "w+") as f: json.dump({'env': prefix}, f) t.close()
def clone_analysispackage(path, prefix=None, analysispackage_name=None, data_path=None): """ Clone the analysispackage (located at `path`) by creating a new environment at `prefix` (unless prefix is None or the prefix directory already exists) """ try: t = tarfile.open(path, 'r:*') meta = json.load(t.extractfile('info/index.json')) except tarfile.ReadError: raise RuntimeError('bad tar archive: %s' % path) except KeyError: raise RuntimeError("no archive 'info/index.json' in: %s" % (path)) if prefix and isdir(prefix): print ("erasing old environment at %s" % prefix) shutil.rmtree(prefix) if prefix and not isdir(prefix): for m in t.getmembers(): if m.path.startswith((BDP, 'info/')): continue t.extract(m, path=prefix) dists = discard_conda('-'.join(s.split()) for s in meta.get('depends', [])) actions = plan.ensure_linked_actions(dists, prefix) index = get_index() plan.display_actions(actions, index) plan.execute_actions(actions, index, verbose=False) if not data_path: analysispackage_dir = abspath(expanduser('~/analysispackages/%s' % (analysispackage_name or meta.get('analysispackage_name')))) else: analysispackage_dir = data_path for m in t.getmembers(): if m.path.startswith(BDP): targetpath = join(analysispackage_dir, m.path[len(BDP):]) t._extract_member(m, targetpath) with open(join(data_path, ".metadata.json"), "w+") as f: json.dump({'env' : prefix}, f) t.close()