def list_objects(workspace_path): workspace_client = get_workspace_client() response = workspace_client.list(workspace_path) # This case is necessary when we list an empty dir in the workspace. # TODO(andrewmchen): We should make our API respond with a json with 'objects' field even # in this case. if 'objects' not in response: return [] objects = response['objects'] return [WorkspaceFileInfo.from_json(f) for f in objects]
def import_workspace(source_path, target_path, language, fmt, is_overwrite): workspace_client = get_workspace_client() with open(source_path, 'r') as f: content = b64encode(f.read()) workspace_client.import_workspace( target_path, fmt, language, content, is_overwrite)
def export_workspace(source_path, target_path, fmt, is_overwrite): if os.path.exists(target_path) and not is_overwrite: raise LocalFileExistsException() workspace_client = get_workspace_client() output = workspace_client.export_workspace(source_path, fmt) content = output['content'] # Will overwrite target_path. with open(target_path, 'wb') as f: decoded = b64decode(content) f.write(decoded)
def export_workspace(source_path, target_path, fmt, is_overwrite): """ Faithfully exports the source_path to the target_path. Does not attempt to do any munging of the target_path if it is a directory. """ if os.path.exists(target_path) and not is_overwrite: raise LocalFileExistsException('Target {} already exists.'.format(target_path)) workspace_client = get_workspace_client() output = workspace_client.export_workspace(source_path, fmt) content = output['content'] # Will overwrite target_path. with open(target_path, 'wb') as f: decoded = b64decode(content) f.write(decoded)
def mkdirs(workspace_path): workspace_client = get_workspace_client() workspace_client.mkdirs(workspace_path)
def get_status(workspace_path): workspace_client = get_workspace_client() return WorkspaceFileInfo.from_json(workspace_client.get_status(workspace_path))
def delete(workspace_path, is_recursive): workspace_client = get_workspace_client() workspace_client.delete(workspace_path, is_recursive)