Ejemplo n.º 1
0
 def testMerge(self):
     file1 = FileData('switch_root', 'sbin/switch_root')
     file1.set_checksum('sha256', '123abc456def')
     file1.extattrs = '-rwxr-xr-x|1000|1000|14408|1'
     file2 = FileData('switch_root', 'sbin/switch_root')
     file2.add_checksums({
         'SHA1': '12345abcde',
         'MD5': '1ff38cc592c4c5d0c8e3ca38be8f1eb1'
     })
     file2.set_checksum('sha256', '123abc456def')
     file2.extattrs = '-rwxr-xr-x|1000|1000|14408|1'
     file2.date = '2012-02-02'
     file2.file_type = 'binary'
     file2.short_file_type = 'BINARY'
     file2.licenses = ['MIT', 'GPL']
     file2.license_expressions = ['MIT or GPL']
     file2.copyrights = ['copyrights']
     file2.authors = ['author1', 'author2']
     file2.packages = ['package1', 'package2']
     file2.urls = ['url1', 'url2']
     file2.origins.add_notice_to_origins(
         'scanning', Notice('something happened', 'error'))
     file3 = FileData('switch_root', 'sbin/switch_root')
     file3.set_checksum('sha1', '456def123abc')
     file4 = FileData('e2image', 'sbin/e2image')
     self.assertFalse(file1.merge(file4))
     self.assertTrue(file1.merge(file3))
     self.assertEqual(file1.checksum, '123abc456def')
     self.assertEqual(file1.extattrs, '-rwxr-xr-x|1000|1000|14408|1')
     self.assertFalse(file1.merge('astring'))
     self.assertTrue(file1.merge(file2))
     self.assertEqual(file1.checksums, {
         'sha1': '12345abcde',
         'md5': '1ff38cc592c4c5d0c8e3ca38be8f1eb1'
     })
     self.assertEqual(file1.date, '2012-02-02')
     self.assertEqual(file1.file_type, 'binary')
     self.assertEqual(file1.short_file_type, 'BINARY')
     self.assertEqual(file1.licenses, ['MIT', 'GPL'])
     self.assertEqual(file1.license_expressions, ['MIT or GPL'])
     self.assertEqual(file1.copyrights, ['copyrights'])
     self.assertEqual(file1.authors, ['author1', 'author2'])
     self.assertEqual(file1.packages, ['package1', 'package2'])
     self.assertEqual(file1.urls, ['url1', 'url2'])
     self.assertEqual(len(file1.origins.origins), 1)
     self.assertEqual(file1.origins.origins[0].origin_str, 'scanning')
     self.assertEqual(len(file1.origins.origins[0].notices), 1)
     self.assertEqual(file1.origins.origins[0].notices[0].message,
                      'something happened')
Ejemplo n.º 2
0
 def add_files(self):
     '''Get all the files present in a layer and store
     them as a list of FileData objects'''
     fs_path = rootfs.get_untar_dir(self.__tar_file)
     hash_file = os.path.join(os.path.dirname(fs_path),
                              self.__fs_hash) + '.txt'
     pattern = re.compile(r'([\w\-|]+)\s+(.+)')
     with open(hash_file) as f:
         content = f.readlines()
     for line in content:
         m = pattern.search(line)
         if m:
             # m.group(2) contains the file path
             # m.group(1) contains the extattrs and checksum
             file_data = FileData(os.path.basename(m.group(2)),
                                  os.path.relpath(m.group(2), '.'))
             # attrs_tuple contains (extattrs, '|', checksum)
             attrs_tuple = m.group(1).rpartition('|')
             file_data.set_checksum('sha256', attrs_tuple[2])
             file_data.extattrs = attrs_tuple[0]
             self.add_file(file_data)
Ejemplo n.º 3
0
 def testExtAttrs(self):
     file = FileData('test.txt', 'usr/abc/test.txt')
     file.extattrs = '-rw-r--r--|1000|1000|19|1'
     self.assertEqual(file.extattrs, '-rw-r--r--|1000|1000|19|1')