本文整理汇总了Python中yum_distributor.distributor.YumDistributor.handle_symlinks方法的典型用法代码示例。如果您正苦于以下问题:Python YumDistributor.handle_symlinks方法的具体用法?Python YumDistributor.handle_symlinks怎么用?Python YumDistributor.handle_symlinks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yum_distributor.distributor.YumDistributor
的用法示例。
在下文中一共展示了YumDistributor.handle_symlinks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_symlinks
# 需要导入模块: from yum_distributor.distributor import YumDistributor [as 别名]
# 或者: from yum_distributor.distributor.YumDistributor import handle_symlinks [as 别名]
def test_handle_symlinks(self):
distributor = YumDistributor()
units = []
symlink_dir = os.path.join(self.temp_dir, "symlinks")
num_links = 5
for index in range(0,num_links):
relpath = "file_%s.rpm" % (index)
sp = os.path.join(self.pkg_dir, relpath)
open(sp, "a") # Create an empty file
if index % 2 == 0:
# Ensure we can support symlinks in subdirs
relpath = os.path.join("a", "b", "c", relpath)
u = Unit("rpm", "unit_key_%s" % (index), {"relativepath":relpath}, sp)
units.append(u)
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertTrue(status)
self.assertEqual(len(errors), 0)
for u in units:
symlink_path = os.path.join(symlink_dir, u.metadata["relativepath"])
self.assertTrue(os.path.exists(symlink_path))
self.assertTrue(os.path.islink(symlink_path))
target = os.readlink(symlink_path)
self.assertEqual(target, u.storage_path)
# Test republish is successful
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertTrue(status)
self.assertEqual(len(errors), 0)
for u in units:
symlink_path = os.path.join(symlink_dir, u.metadata["relativepath"])
self.assertTrue(os.path.exists(symlink_path))
self.assertTrue(os.path.islink(symlink_path))
target = os.readlink(symlink_path)
self.assertEqual(target, u.storage_path)
# Simulate a package is deleted
os.unlink(units[0].storage_path)
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertFalse(status)
self.assertEqual(len(errors), 1)