def obtain(self, path, limit=None): path_for_dropbox = ensure_binary_string(path) logging.debug(u"Obtaining file: %s", path) metadata = self.list(path) if limit and metadata['bytes'] > limit: raise OverLimit("The response contains %d bytes data."\ % metadata['bytes']) res = self.client.get_file(path_for_dropbox) file_obj = StringIO(res.read()) file_obj.name = path return file_obj
def list(self, path, recursive=True): if path in self.cached_list: return self.cached_list[path] if recursive: result = self.list(path, recursive=False) if result['is_dir']: def _ls_rec(data): if data['is_dir']: data.update(self.list(data['path'], recursive=False)) traverse(_ls_rec, result) return result else: path_for_dropbox = ensure_binary_string(path) logging.debug(u"Listing metadata of: %s", path) result = self.client.metadata(path_for_dropbox) self.cached_list[path] = result return result
def move(self, from_path, to_path): from_path_for_dropbox = ensure_binary_string(from_path) to_path_for_dropbox = ensure_binary_string(to_path) logging.debug(u"Moving into: %s %s", from_path, to_path) return self.client.file_move(from_path_for_dropbox, to_path_for_dropbox)
def create_folder(self, path): path_for_dropbox = ensure_binary_string(path) logging.debug(u"Creating a directory: %s", path) return self.client.file_create_folder(path_for_dropbox)
def delete(self, path): path_for_dropbox = ensure_binary_string(path) logging.debug(u"Deleting file from Dropbox: %s", path) return self.client.file_delete(path_for_dropbox)
def put(self, path, file_obj, overwrite=True): path_for_dropbox = ensure_binary_string(path) logging.debug(u"Putting file to Dropbox: %s", path) return self.client.put_file(path_for_dropbox, file_obj, overwrite=overwrite)