本文整理匯總了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)