def uploadStoreitemRecursive(cls, path, remote_location=None, remote_branch=None, cache_dir='.store.upload.cache', depth=-1, check_path=True): # todo: check branch name # assert remote_branch not in cls.special_branches assert depth >= 0 or depth == -1 assert os.path.exists(path) if check_path: assert cls.is_legal_path_to_upload(path) remote_location = remote_location or default_remote_location assert remote_branch if os.path.exists(cache_dir): shutil.rmtree(cache_dir) target_dir = cache_dir + '/target' store_dir = cache_dir + '/stores' os.makedirs(target_dir) copy_fsitem(path, target_dir) path = target_dir + '/' + os.path.basename(path) return cls._uploadStoreitemRecursive(path, remote_location, remote_branch, cache_dir=store_dir, depth=depth, check_path=check_path)
def export(cls, path, remote_branch, remote_location=default_remote_location, name=None, cache_dir='.tmp', overwrite=False): if os.path.exists(cache_dir): shutil.rmtree(cache_dir) def _export_dir(obj, path, cache_dir): for p in obj.iter_contentpath(): copy_fsitem(p, path) more = obj.morefile.copy() # obj.rmself() for nm, br in more.items(): br_cache_dir = cache_dir + '/' + br cls.export(path, remote_location=remote_location, remote_branch=br, name=nm, cache_dir=br_cache_dir, overwrite=overwrite) this_dir = cache_dir + '/.this' obj = StoreItem.pull(remote_location=remote_location, remote_branch=remote_branch, path=this_dir) name = name or remote_branch.split(cls.delimiter)[-1] if isinstance(obj, StoreFolder): if not os.path.exists(path): os.makedirs(path) assert os.path.isdir(path) path = path + '/' + name if os.path.exists(path): if overwrite: shutil.rmtree(path) else: raise Exception( "Can't export to %s because path already existed and overwrite is not True" ) os.mkdir(path) _export_dir(obj, path, cache_dir) else: assert isinstance(obj, StoreFile) if os.path.exists(path): assert os.path.isdir(path) if name: path = path + '/' + name ps = obj.iter_contentpath() ps.sort() p = ps[0] # path=path+'/'+os.path.basename(p) copy_fsitem(p, path) else: for p in obj.iter_contentpath(): copy_fsitem(p, path)
def _export_dir(obj, path, cache_dir): for p in obj.iter_contentpath(): copy_fsitem(p, path) more = obj.morefile.copy() # obj.rmself() for nm, br in more.items(): br_cache_dir = cache_dir + '/' + br cls.export(path, remote_location=remote_location, remote_branch=br, name=nm, cache_dir=br_cache_dir, overwrite=overwrite)