class BundleService(): def __init__(self, user=None): self.client = RemoteBundleClient(settings.BUNDLE_SERVICE_URL, lambda command: get_user_token(user), verbose=1) def items(self): return _call_with_retries(lambda: self.client.search()) def item(self, uuid): return _call_with_retries(lambda: self.client.get_bundle_info(uuid)) def worksheets(self): return _call_with_retries(lambda: self.client.list_worksheets()) def create_worksheet(self, name): return _call_with_retries(lambda: self.client.new_worksheet(name)) def worksheet(self, uuid, interpreted=False): worksheet_info = _call_with_retries( lambda: self.client.get_worksheet_info( uuid, True ) ) if interpreted: interpreted_items = worksheet_util.interpret_items( worksheet_util.get_default_schemas(), worksheet_info['items'] ) worksheet_info['items'] = self.client.resolve_interpreted_items(interpreted_items['items']) return worksheet_info else: return worksheet_info def ls(self, uuid, path): return _call_with_retries(lambda: self.client.ls((uuid, path))) MAX_BYTES = 1024*1024 def read_file(self, uuid, path): fid = self.client.open_target((uuid, path)) try: while True: bytes = self.client.read_file(fid, BundleService.MAX_BYTES) yield bytes.data if len(bytes.data) < BundleService.MAX_BYTES: break finally: self.client.close_file(fid) def download_target(self, uuid, return_zip=False): target = (uuid, '') result_path, container_path = self.client.download_target(target=target, follow_symlinks=True, return_zip=return_zip) return (result_path, container_path) def http_status_from_exception(self, ex): # This is brittle. See https://github.com/codalab/codalab/issues/345. if type(ex) == UsageError: return 404 return 500
class BundleService(): def __init__(self): self.client = RemoteBundleClient(settings.BUNDLE_SERVICE_URL) def items(self): return _call_with_retries(lambda: self.client.search()) def item(self, uuid): return _call_with_retries(lambda: self.client.info(uuid)) def worksheets(self): return _call_with_retries(lambda: self.client.list_worksheets()) def worksheet(self, uuid): return _call_with_retries(lambda: self.client.worksheet_info(uuid)) def ls(self, uuid, path): return _call_with_retries(lambda: self.client.ls((uuid, path))) def http_status_from_exception(self, ex): # This is brittle. See https://github.com/codalab/codalab/issues/345. if type(ex) == UsageError: return 404 return 500
class BundleService(): def __init__(self): self.client = RemoteBundleClient(settings.BUNDLE_SERVICE_URL, lambda command: "") #TODO def items(self): return _call_with_retries(lambda: self.client.search()) def item(self, uuid): return _call_with_retries(lambda: self.client.info(uuid)) def worksheets(self): return _call_with_retries(lambda: self.client.list_worksheets()) def create_worksheet(self, name): return _call_with_retries(lambda: self.client.new_worksheet(name)) def worksheet(self, uuid): return _call_with_retries(lambda: self.client.worksheet_info(uuid)) def ls(self, uuid, path): strm = self.read_file(uuid, 'bat.txt') return _call_with_retries(lambda: self.client.ls((uuid, path))) MAX_BYTES = 1024*1024 def read_file(self, uuid, path): fid = self.client.open_target((uuid, path)) try: while True: bytes = self.client.read_file(fid, BundleService.MAX_BYTES) yield bytes.data if len(bytes.data) < BundleService.MAX_BYTES: break finally: self.client.close_file(fid) def http_status_from_exception(self, ex): # This is brittle. See https://github.com/codalab/codalab/issues/345. if type(ex) == UsageError: return 404 return 500
class BundleService(): def __init__(self): self.client = RemoteBundleClient(settings.BUNDLE_SERVICE_URL, lambda command: "") #TODO def items(self): return _call_with_retries(lambda: self.client.search()) def item(self, uuid): return _call_with_retries(lambda: self.client.info(uuid)) def worksheets(self): return _call_with_retries(lambda: self.client.list_worksheets()) def create_worksheet(self, name): return _call_with_retries(lambda: self.client.new_worksheet(name)) def worksheet(self, uuid): return _call_with_retries(lambda: self.client.worksheet_info(uuid)) def ls(self, uuid, path): strm = self.read_file(uuid, 'bat.txt') return _call_with_retries(lambda: self.client.ls((uuid, path))) MAX_BYTES = 1024 * 1024 def read_file(self, uuid, path): fid = self.client.open_target((uuid, path)) try: while True: bytes = self.client.read_file(fid, BundleService.MAX_BYTES) yield bytes.data if len(bytes.data) < BundleService.MAX_BYTES: break finally: self.client.close_file(fid) def http_status_from_exception(self, ex): # This is brittle. See https://github.com/codalab/codalab/issues/345. if type(ex) == UsageError: return 404 return 500
class BundleService(): def __init__(self, user=None): self.client = RemoteBundleClient( settings.BUNDLE_SERVICE_URL, lambda command: get_user_token(user), verbose=1) def items(self): return _call_with_retries(lambda: self.client.search()) def item(self, uuid): return _call_with_retries( lambda: self.client.get_bundle_info(uuid)) def worksheets(self): return _call_with_retries(lambda: self.client.list_worksheets()) def create_worksheet(self, name): return _call_with_retries(lambda: self.client.new_worksheet(name)) def worksheet(self, uuid, interpreted=False): worksheet_info = _call_with_retries( lambda: self.client.get_worksheet_info(uuid, True)) if interpreted: interpreted_items = worksheet_util.interpret_items( worksheet_util.get_default_schemas(), worksheet_info['items']) worksheet_info[ 'items'] = self.client.resolve_interpreted_items( interpreted_items['items']) return worksheet_info else: return worksheet_info def ls(self, uuid, path): return _call_with_retries(lambda: self.client.ls((uuid, path))) MAX_BYTES = 1024 * 1024 def read_file(self, uuid, path): fid = self.client.open_target((uuid, path)) try: while True: bytes = self.client.read_file(fid, BundleService.MAX_BYTES) yield bytes.data if len(bytes.data) < BundleService.MAX_BYTES: break finally: self.client.close_file(fid) def download_target(self, uuid, return_zip=False): target = (uuid, '') result_path, container_path = self.client.download_target( target=target, follow_symlinks=True, return_zip=return_zip) return (result_path, container_path) def http_status_from_exception(self, ex): # This is brittle. See https://github.com/codalab/codalab/issues/345. if type(ex) == UsageError: return 404 return 500