def filter_by_ignore_extension(self, target, output, extensions): """ Specific filter for selected exuensions :param str target: target list :param str output: output list :param list extensions: filtered extensions :return: None """ try: target_file = self.__config.get(target) output_file = self.__config.get(output) dirlist = filesystem.read(target_file) dirlist = [i.strip() for i in dirlist] pattern = '^(' for ext in extensions: pattern += '(?!\.{0})'.format(ext) pattern += '.)*$' newlist = filesystem.filter_file_lines(dirlist, pattern) filesystem.makefile(output_file) filesystem.writelist(output_file, newlist, '\n') self.__counter = len(newlist) except (CoreSystemError, FileSystemError) as error: raise ReaderError(error)
def filter_by_extension(self, target, output, extensions): """ Filter list by multiple extensions :param str target: target list :param str output: output list :param list extensions: filtered extensions :return: None """ try: target_file = self.__config.get(target) output_file = self.__config.get(output) dirlist = filesystem.read(target_file) dirlist = [i.strip() for i in dirlist] pattern = '.*\.' + '|.*\.'.join(extensions) newlist = filesystem.filter_file_lines(dirlist, pattern) filesystem.makefile(output_file) filesystem.writelist(output_file, newlist, '\n') self.__counter = len(newlist) except (CoreSystemError, FileSystemError) as error: raise ReaderError(error)
def record(cls, dirname, filename, resultset, separator=''): """ Record data process :param str dirname: report directory :param str filename: report filename :param list resultset: report result :param str separator: result separator :raise Exception :return: None """ try: filename = "".join((dirname, filesystem.sep, filename, cls.EXTENSION_SET)) filename = filesystem.makefile(filename) filesystem.writelist(filename, resultset, separator) tpl.info(key='report', plugin=cls.PLUGIN_NAME, dest=filesystem.getabsname(filename)) except FileSystemError as error: raise Exception(error)