def find(self, path): path = to_nimbus_path(path) path_obj = self.transactions_manager.find_inprogress_file(path) if not path_obj: try: path_obj = self.metadata.find(path) except PathException, err: #logger.debug('[get_resource] %s'%str(err)) return
def move(self, s_path, d_path): s_path = to_nimbus_path(s_path) d_path = to_nimbus_path(d_path) logger.debug('moving %s to %s ...'%(s_path, d_path)) mdf = self.metadata source = mdf.find(s_path) if mdf.exists(d_path): d_obj = mdf.find(d_path) if d_obj.is_file(): raise AlreadyExistsException('File %s is already exists!'%d_path) source.parent_dir_id = d_obj.item_id else: dst_path, new_name = os.path.split(d_path) source.name = new_name mdf.find(dst_path) #check existance mdf.update(source) logger.debug('%s is moved to %s!'%(s_path, d_path))
def move(self, s_path, d_path): s_path = to_nimbus_path(s_path) d_path = to_nimbus_path(d_path) logger.debug('moving %s to %s ...' % (s_path, d_path)) mdf = self.metadata source = mdf.find(s_path) if mdf.exists(d_path): d_obj = mdf.find(d_path) if d_obj.is_file(): raise AlreadyExistsException('File %s is already exists!' % d_path) source.parent_dir_id = d_obj.item_id else: dst_path, new_name = os.path.split(d_path) source.name = new_name mdf.find(dst_path) #check existance mdf.update(source) logger.debug('%s is moved to %s!' % (s_path, d_path))
def mkdir(self, path, recursive=False): path = to_nimbus_path(path) logger.debug('mkdir %s ...'%path) mdf = self.metadata if mdf.exists(path): raise AlreadyExistsException('Directory "%s" is already exists!'%path) base_path, new_dir = os.path.split(path) if not mdf.exists(base_path): if recursive: self.mkdir(base_path, recursive) else: raise PathException('Directory "%s" does not exists!'%base_path) new_dir_obj = DirectoryMD(name=new_dir) mdf.append(base_path, new_dir_obj)
def mkdir(self, path, recursive=False): path = to_nimbus_path(path) logger.debug('mkdir %s ...' % path) mdf = self.metadata if mdf.exists(path): raise AlreadyExistsException('Directory "%s" is already exists!' % path) base_path, new_dir = os.path.split(path) if not mdf.exists(base_path): if recursive: self.mkdir(base_path, recursive) else: raise PathException('Directory "%s" does not exists!' % base_path) new_dir_obj = DirectoryMD(name=new_dir) mdf.append(base_path, new_dir_obj)
def rmdir(self, path, recursive=False): path = to_nimbus_path(path) logger.debug('rmdir %s ...' % path) mdf = self.metadata dir_obj = mdf.find(path) if not dir_obj.is_dir(): raise NotDirectoryException('%s is a file!' % path) items = mdf.listdir(path) if items and not recursive: raise NotEmptyException('Directory "%s" is not empty!' % path) for item in items: full_path = '%s/%s' % (path, item.name) if item.is_file(): self.remove_file(full_path) else: self.rmdir(full_path, recursive) mdf.remove(dir_obj)
def rmdir(self, path, recursive=False): path = to_nimbus_path(path) logger.debug('rmdir %s ...'%path) mdf = self.metadata dir_obj = mdf.find(path) if not dir_obj.is_dir(): raise NotDirectoryException('%s is a file!'%path) items = mdf.listdir(path) if items and not recursive: raise NotEmptyException('Directory "%s" is not empty!'%path) for item in items: full_path = '%s/%s'%(path, item.name) if item.is_file(): self.remove_file(full_path) else: self.rmdir(full_path, recursive) mdf.remove(dir_obj)
def listdir(self, path='/'): path = to_nimbus_path(path) ret_lst = [] inc_tr_l = [] #try to find uploading files in @path (fully saved into data blocks cache) for is_upload, file_path, status, size, _ in self.transactions_manager.iterate_transactions(): if not is_upload: continue if status != Transaction.TS_LOCAL_SAVED: continue base_path, file_name = os.path.split(file_path) if base_path == path: ret_lst.append(self.__make_item_fs(FileMD(name=file_name, size=size))) inc_tr_l.append(file_name) items = self.metadata.listdir(path) for item in items: if item.name not in inc_tr_l: ret_lst.append(self.__make_item_fs(item)) return ret_lst
def listdir(self, path='/'): path = to_nimbus_path(path) ret_lst = [] inc_tr_l = [] #try to find uploading files in @path (fully saved into data blocks cache) for is_upload, file_path, status, size, _ in self.transactions_manager.iterate_transactions( ): if not is_upload: continue if status != Transaction.TS_LOCAL_SAVED: continue base_path, file_name = os.path.split(file_path) if base_path == path: ret_lst.append( self.__make_item_fs(FileMD(name=file_name, size=size))) inc_tr_l.append(file_name) items = self.metadata.listdir(path) for item in items: if item.name not in inc_tr_l: ret_lst.append(self.__make_item_fs(item)) return ret_lst
def open_file(self, file_path, for_write=False): file_path = to_nimbus_path(file_path) return SmartFileObject(file_path, for_write)
def remove_file(self, file_path): file_path = to_nimbus_path(file_path) logger.debug('removing file %s ...' % file_path) self.transactions_manager.remove_file(file_path) logger.debug('file %s is removed!' % file_path)
def remove_file(self, file_path): file_path = to_nimbus_path(file_path) logger.debug('removing file %s ...'%file_path) self.transactions_manager.remove_file(file_path) logger.debug('file %s is removed!'%file_path)