当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.perform_recursive_inventory方法代码示例

本文整理汇总了Python中inventory.Inventory.perform_recursive_inventory方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.perform_recursive_inventory方法的具体用法?Python Inventory.perform_recursive_inventory怎么用?Python Inventory.perform_recursive_inventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


在下文中一共展示了Inventory.perform_recursive_inventory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_detect_changes_and_update

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import perform_recursive_inventory [as 别名]
    def test_detect_changes_and_update(self):
        fs_path = self.create_test_data()
        inventories = Inventory.perform_recursive_inventory(os.path.dirname(fs_path), self.base_path)
        for inventory in inventories:
            inventory.write(self.inventory_base_path)

        # Nothing changes
        self.assertEqual([], self.inventory_manager.detect_change(fs_path).inventory_diffs)

        # Add a directory and new file
        dir4_path = os.path.join(fs_path, 'dir4')
        os.mkdir(dir4_path)
        self.create_test_file(os.path.join(dir4_path, 'file5.txt'))
        # Remove a directory
        shutil.rmtree(os.path.join(fs_path, 'dir3'))
        # Add a file
        self.create_test_file(os.path.join(fs_path, 'file6.txt'))
        # Remove a file
        os.remove(os.path.join(fs_path, 'file1.txt'))
        # Change a file
        self.create_test_file(os.path.join(fs_path, 'dir1/file3.txt'), contents='test')

        inventory_report = self.inventory_manager.detect_change(fs_path)
        self.assertIsNone(inventory_report.applied_timestamp)
        rel_path = os.path.relpath(fs_path, self.base_path)
        self.assertInventoryDiffEqual({
            'path': rel_path,
            'directories_missing_from_fs': ['dir3'],
            'directories_missing_from_inventory': ['dir4'],
            'files_missing_from_fs': {'file1.txt': hashlib.sha256('file1.txt'.encode('utf-8')).hexdigest()},
            'files_missing_from_inventory': {'file6.txt': hashlib.sha256('file6.txt'.encode('utf-8')).hexdigest()},
            'file_fixity_mismatch': {}
        }, self._find_inventory_diff(inventory_report.inventory_diffs, rel_path))

        dir4_rel_path = os.path.join(rel_path, 'dir4')
        self.assertInventoryDiffEqual({
            'path': dir4_rel_path,
            'directories_missing_from_fs': [],
            'directories_missing_from_inventory': [],
            'files_missing_from_fs': {},
            'files_missing_from_inventory': {'file5.txt': hashlib.sha256('file5.txt'.encode('utf-8')).hexdigest()},
            'file_fixity_mismatch': {}
        }, self._find_inventory_diff(inventory_report.inventory_diffs, dir4_rel_path))

        dir1_rel_path = os.path.join(rel_path, 'dir1')
        self.assertInventoryDiffEqual({
            'path': dir1_rel_path,
            'directories_missing_from_fs': [],
            'directories_missing_from_inventory': [],
            'files_missing_from_fs': {},
            'files_missing_from_inventory': {},
            'file_fixity_mismatch': {'file3.txt': (hashlib.sha256('file3.txt'.encode('utf-8')).hexdigest(),
                                                   hashlib.sha256('test'.encode('utf-8')).hexdigest())}
        }, self._find_inventory_diff(inventory_report.inventory_diffs, dir1_rel_path))

        self.inventory_manager.update_inventory(inventory_report)
        # Nothing changes
        self.assertEqual([], self.inventory_manager.detect_change(fs_path).inventory_diffs)
开发者ID:gwu-libraries,项目名称:inventory,代码行数:60,代码来源:test_inventory_manager.py

示例2: detect_change

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import perform_recursive_inventory [as 别名]
 def detect_change(self, path):
     log.info('Detecting changes for %s', path)
     inventory_diffs = []
     fs_inventories = Inventory.perform_recursive_inventory(path, self.base_fs_path,
                                                            fixity_threads=self.fixity_threads)
     # If path is not base path, check parent non-recursively to make sure added/deleted directory handled.
     if path != self.base_fs_path:
         fs_inventories.append(
             Inventory.perform_inventory(os.path.dirname(path), self.base_fs_path,
                                         fixity_threads=self.fixity_threads))
     for fs_inventory in fs_inventories:
         try:
             inventory_inventory = Inventory.read(fs_inventory.path, self.base_inventory_path)
         except FileNotFoundError:
             inventory_inventory = Inventory(fs_inventory.path)
         inventory_diff = InventoryDiff.generate_inventory_diff(fs_inventory, inventory_inventory)
         if inventory_diff.has_diffs():
             inventory_diffs.append(inventory_diff)
     return InventoryReport(path, inventory_diffs)
开发者ID:gwu-libraries,项目名称:inventory,代码行数:21,代码来源:audit_tool.py


注:本文中的inventory.Inventory.perform_recursive_inventory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。