def __list(self, path, excludes, recursive, retry): files_list = self.__get_dir_list(path, retry) files = [] for file_list in files_list: ftp_file = FtpListParser(self.get_platform(), file_list) file_path = self.get_platform().join(path, ftp_file.get_name()) file_type = '' if ftp_file.get_type() == 'd': file_type = FileObject.DIRECTORY elif ftp_file.get_type() == 'l': file_type = FileObject.LINK elif ftp_file.get_type() == 's': file_type = FileObject.SOCKET elif ftp_file.get_type() == 'c': file_type = FileObject.CHARCTER_DEVICE elif ftp_file.get_type() == 'p': file_type = FileObject.PIPE elif ftp_file.get_type() == 'b': file_type = FileObject.BLOCK_DEVICE elif ftp_file.get_type() == 'D': file_type = FileObject.DOOR else: file_type = FileObject.FILE if not (excludes is not None and excludes.match(path, ftp_file.get_name(), file_type)): resfile = FileObject(self.get_platform(), file_path, file_type, ftp_file.get_mode(), ftp_file.get_date(), '', '', ftp_file.get_owner(), ftp_file.get_group()) children = [] if ftp_file.get_type() == 'd' and recursive: children = self.__list(file_path, excludes, True, retry) for child in children: resfile.add_child(child) files.append(resfile) return files
def __list(self, path, excludes = None, recursive = False, retry = 1): if False == Validator.validate_non_empty_string(path): raise InvalidParameterError('path', 'should be a not empty string') if excludes.__class__ != FileSet and excludes != None: raise InvalidParameterError('excludes', 'should be instance of FileSet') if recursive.__class__ != bool: raise InvalidParameterError('recursive', 'should be a bool') if retry.__class__ != int: raise InvalidParameterError('retry', 'should be a bool') #trim the '/' or '\' from the end of path path = self.get_platform().trim_path(path) if not os.path.exists(path): raise FileNotExistsError, 'file or directory does not exist' #test if path is relative if self.get_platform().is_relative(path) : path = self.__root + path if not os.path.isdir(path): recursive = False if os.path.isfile(path): file_type = FileObject.FILE else: file_type = FileObject.LINK if Platform.PLATFORM_WINDOWS == self.get_platform().get_platform(): user_id = "" group_id = "" else: user_id = os.stat(path).st_uid group_id = os.stat(path).st_gid return FileObject(self.get_platform(), path, file_type, os.stat(path).st_mode & 0777 , time.localtime(os.path.getmtime(path)), time.localtime(os.path.getctime(path)), time.localtime(os.path.getatime(path)), user_id, group_id) else: if Platform.PLATFORM_WINDOWS == self.get_platform().get_platform(): user_id = "" group_id = "" else: user_id = os.stat(path).st_uid group_id = os.stat(path).st_gid file = FileObject(self.get_platform(), path, FileObject.DIRECTORY, os.stat(path).st_mode & 0777 , time.localtime(os.path.getmtime(path)), time.localtime(os.path.getctime(path)), time.localtime(os.path.getatime(path)), user_id, group_id) if recursive or inspect.stack()[1][3] == 'list': cont_list = os.listdir(path) for item in cont_list: new_path = path + self.get_platform().get_separator() + item base_name = self.get_platform().basename(new_path) parent_name = self.get_platform().dirname(new_path) if os.path.isfile(new_path): _type = FileObject.FILE else: _type = FileObject.DIRECTORY if not (excludes and excludes.match(parent_name, base_name, _type)): file.add_child(self.__list(new_path, excludes, recursive, retry)) return file