示例#1
0
 def search_archive_file(self, sf):
     """Search an archive (compressed) file"""
     ext = FileUtil.get_extension(sf.filename)
     if not ext:
         return
     if self.settings.debug:
         common.log('Searching {0} file {1}'.format(ext, sf))
     if ext in ('zip', 'jar', 'war', 'ear'):
         # handle zip files
         try:
             self.search_zip_file(sf)
         except zipfile.BadZipfile as e:
             if not ext == 'ear':
                 common.log('BadZipfile: {0!s}: {1}'.format(e, sf))
     elif ext in ('bz2', 'tar', 'tgz', 'gz') and \
          tarfile.is_tarfile(sf.relativepath):
         # handle tar files
         try:
             self.search_tar_file(sf, ext)
         except Exception as e:
             msg = 'Exception while searching a tar file {0}: {1!s}'
             common.log(msg.format(sf, e))
     else:
         msg = 'Searching archive file type "{0}" is unsupported at this time'
         common.log(msg.format(ext))
示例#2
0
 def is_archive_search_file(self, f):
     ext = FileUtil.get_extension(f)
     if self.settings.in_archiveextensions and \
         not ext in self.settings.in_archiveextensions:
         return False
     if self.settings.out_archiveextensions and \
         ext in self.settings.out_archiveextensions:
         return False
     if self.settings.in_archivefilepatterns and \
         not matches_any_pattern(f, self.settings.in_archivefilepatterns):
         return False
     if self.settings.out_archivefilepatterns and \
         matches_any_pattern(f, self.settings.out_archivefilepatterns):
         return False
     return True
示例#3
0
 def is_search_file(self, f):
     ext = FileUtil.get_extension(f)
     if self.settings.in_extensions and \
         not ext in self.settings.in_extensions:
         return False
     if self.settings.out_extensions and \
         ext in self.settings.out_extensions:
         return False
     if self.settings.in_filepatterns and \
         not matches_any_pattern(f, self.settings.in_filepatterns):
         return False
     if self.settings.out_filepatterns and \
         matches_any_pattern(f, self.settings.out_filepatterns):
         return False
     return True
示例#4
0
 def is_archive_search_file(self, f):
     if not self.filetypes.is_archive_file(f):
         return False
     ext = FileUtil.get_extension(f)
     if self.settings.in_archiveextensions and \
         not ext in self.settings.in_archiveextensions:
         return False
     if self.settings.out_archiveextensions and \
         ext in self.settings.out_archiveextensions:
         return False
     if self.settings.in_archivefilepatterns and \
         not matches_any_pattern(f, self.settings.in_archivefilepatterns):
         return False
     if self.settings.out_archivefilepatterns and \
         matches_any_pattern(f, self.settings.out_archivefilepatterns):
         return False
     return True
示例#5
0
 def is_search_file(self, sf):
     if self.settings.in_filetypes and \
         not sf.filetype in self.settings.in_filetypes:
         return False
     if self.settings.out_filetypes and \
        sf.filetype in self.settings.out_filetypes:
         return False
     ext = FileUtil.get_extension(sf.filename)
     if self.settings.in_extensions and \
         not ext in self.settings.in_extensions:
         return False
     if self.settings.out_extensions and \
         ext in self.settings.out_extensions:
         return False
     if self.settings.in_filepatterns and \
         not matches_any_pattern(sf.filename, self.settings.in_filepatterns):
         return False
     if self.settings.out_filepatterns and \
         matches_any_pattern(sf.filename, self.settings.out_filepatterns):
         return False
     return True
示例#6
0
 def search_archive_file(self, sf):
     """Search an archive (compressed) file"""
     ext = FileUtil.get_extension(sf.filename)
     if not ext: return
     if self.settings.debug:
         common.log('Searching {0} file {1}'.format(ext, sf))
     if ext in ('zip', 'jar', 'war', 'ear'):
         # handle zip files
         try:
             self.search_zip_file(sf)
         except zipfile.BadZipfile as e:
             if not ext == 'ear':
                 common.log('BadZipfile: {0!s}: {1}'.format(e, sf))
     elif ext in ('bz2', 'tar', 'tgz', 'gz') and \
          tarfile.is_tarfile(sf.relativepath):
         # handle tar files
         try:
             self.search_tar_file(sf, ext)
         except Exception as e:
             msg = 'Exception while searching a tar file {0}: {1!s}'
             common.log(msg.format(sf, e))
     else:
         msg = 'Searching archive file type "{0}" is unsupported at this time'
         common.log(msg.format(ext))
示例#7
0
 def is_searchable_file(self, f):
     """Return true if file is of a (known) searchable type"""
     return FileUtil.get_extension(f) in self.filetypes['searchable']
示例#8
0
 def is_code_file(self, f):
     """Return true if file is of a (known) code file type"""
     return FileUtil.get_extension(f) in self.filetypes['code']
示例#9
0
 def is_archive_file(self, f):
     """Return true if file is of a (known) archive file type"""
     return FileUtil.get_extension(f) in self.filetypes['archive']
示例#10
0
 def is_text_file(self, f):
     """Return true if file is of a (known) text file type"""
     return FileUtil.get_extension(f) in self.filetypes['text']
示例#11
0
 def is_searchable_file(self, f):
     """Return true if file is of a (known) searchable type"""
     return FileUtil.get_extension(f) in self.filetypes['searchable']
示例#12
0
 def is_archive_file(self, f):
     """Return true if file is of a (known) archive file type"""
     return FileUtil.get_extension(f) in self.filetypes['archive']
示例#13
0
 def test_get_extension_missing_extension(self):
     filename = 'filename.'
     self.assertEqual(FileUtil.get_extension(filename), '')
示例#14
0
 def is_text_file(self, f):
     """Return true if file is of a (known) text file type"""
     return FileUtil.get_extension(f) in self.filetypes['text']
示例#15
0
 def test_get_extension_hidden_file_no_extension(self):
     filename = '.hidden'
     self.assertEqual(FileUtil.get_extension(filename), '')
示例#16
0
 def test_get_extension_hidden_txt_file(self):
     filename = '.hidden.txt'
     self.assertEqual(FileUtil.get_extension(filename), 'txt')
示例#17
0
 def test_get_extension_no_extension(self):
     filename = 'filename'
     self.assertEqual(FileUtil.get_extension(filename), '')
示例#18
0
 def is_xml_file(self, f):
     """Return true if file is of a (known) xml file type"""
     return FileUtil.get_extension(f) in self.filetypes['xml']
示例#19
0
 def test_get_extension_has_txt_extension(self):
     filename = 'filename.txt'
     self.assertEqual(FileUtil.get_extension(filename), 'txt')