本文整理汇总了Python中pulp.devel.unit.util.touch函数的典型用法代码示例。如果您正苦于以下问题:Python touch函数的具体用法?Python touch怎么用?Python touch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了touch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_process_main_only_publish_directory_contents
def test_process_main_only_publish_directory_contents(self):
source_dir = os.path.join(self.working_directory, 'source')
master_dir = os.path.join(self.working_directory, 'master')
publish_dir = os.path.join(self.working_directory, 'publish', 'bar')
publish_dir += '/'
step = publish_step.AtomicDirectoryPublishStep(
source_dir, [('/', publish_dir)], master_dir, only_publish_directory_contents=True)
step.parent = Mock(timestamp=str(time.time()))
# create some files to test
sub_file = os.path.join(source_dir, 'bar.html')
touch(sub_file)
# create an existing file that will be maintained
existing_file = os.path.join(source_dir, 'bar.html')
touch(existing_file)
# Create an old directory to test
old_dir = os.path.join(master_dir, 'foo')
os.makedirs(old_dir)
step.process_main()
target_file = os.path.join(publish_dir, 'bar.html')
self.assertEquals(True, os.path.exists(target_file))
self.assertTrue(os.path.exists(existing_file))
self.assertEquals(1, len(os.listdir(master_dir)))
示例2: test_create_symlink_link_exists_not_link
def test_create_symlink_link_exists_not_link(self):
source_path = os.path.join(self.working_dir, 'source')
link_path = os.path.join(self.published_dir, 'link')
touch(source_path)
touch(link_path)
self.assertRaises(RuntimeError, PublishStep._create_symlink, source_path, link_path)
示例3: test_create_symlink
def test_create_symlink(self):
source_path = os.path.join(self.working_dir, "source")
link_path = os.path.join(self.published_dir, "link")
touch(source_path)
self.assertFalse(os.path.exists(link_path))
misc.create_symlink(source_path, link_path)
self.assertTrue(os.path.exists(link_path))
示例4: test_create_symlink_link_exists_not_link
def test_create_symlink_link_exists_not_link(self):
source_path = os.path.join(self.working_dir, "source")
link_path = os.path.join(self.published_dir, "link")
touch(source_path)
touch(link_path)
self.assertRaises(RuntimeError, misc.create_symlink, source_path, link_path)
示例5: existing_files_saved
def existing_files_saved(self):
existing_file = os.path.join(self.destination_dir, 'foo.txt')
touch(existing_file)
new_dir = os.path.join(self.source_dir, 'bar')
os.makedirs(new_dir)
installdistributor.PuppetModuleInstallDistributor.\
_move_to_destination_directory(self.source_dir, self.destination_dir)
self.assertTrue(os.path.exists(existing_file))
示例6: test_create_symlink_no_link_parent
def test_create_symlink_no_link_parent(self):
source_path = os.path.join(self.working_dir, 'source')
link_path = os.path.join(self.published_dir, 'foo/bar/baz/link')
touch(source_path)
self.assertFalse(os.path.exists(os.path.dirname(link_path)))
PublishStep._create_symlink(source_path, link_path)
self.assertTrue(os.path.exists(link_path))
示例7: test_clean_ophaned_leaf
def test_clean_ophaned_leaf(self):
"""
Test that an orphaned leaf is removed.
"""
leaf = os.path.join(self.publish_base, 'a', 'b', 'c', 'listing')
leaf_dir = os.path.dirname(leaf)
util.touch(leaf)
self.assertTrue(os.path.isfile(leaf))
migration.clean_simple_hosting_directories(leaf_dir, self.publish_base)
self.assertFalse(os.path.isdir(os.path.join(self.publish_base, 'a')))
示例8: test_walk_does_not_recognize_non_leaf
def test_walk_does_not_recognize_non_leaf(self, mock_clean):
"""
Test that non orphaned leafs are not cleaned.
"""
non_orphan = os.path.join(self.publish_base, 'not', 'orphan', 'listing')
other_file = os.path.join(self.publish_base, 'not', 'orphan', 'notlisting')
util.touch(non_orphan)
util.touch(other_file)
migration.walk_and_clean_directories(self.publish_base)
self.assertEqual(mock_clean.call_count, 0)
示例9: test_create_symlink_link_parent_bad_permissions
def test_create_symlink_link_parent_bad_permissions(self):
source_path = os.path.join(self.working_dir, 'source')
link_path = os.path.join(self.published_dir, 'foo/bar/baz/link')
touch(source_path)
os.makedirs(os.path.dirname(link_path))
os.chmod(os.path.dirname(link_path), 0000)
self.assertRaises(OSError, PublishStep._create_symlink, source_path, link_path)
os.chmod(os.path.dirname(link_path), 0777)
示例10: test_create_symlink_no_link_parent_with_permissions
def test_create_symlink_no_link_parent_with_permissions(self, mock_makedirs, mock_symlink):
source_path = os.path.join(self.working_dir, "source")
link_path = os.path.join(self.published_dir, "foo/bar/baz/link")
touch(source_path)
self.assertFalse(os.path.exists(os.path.dirname(link_path)))
misc.create_symlink(source_path, link_path, directory_permissions=0700)
mock_makedirs.assert_called_once_with(os.path.dirname(link_path), mode=0700)
mock_symlink.assert_called_once_with(source_path, link_path)
示例11: test_clean_with_concurrent_file_creation
def test_clean_with_concurrent_file_creation(self, mock_rmdir, mock_util):
"""
Clean directories when a dir cannot be removed during orphaned directory removal.
"""
mock_rmdir.side_effect = OSError()
listing_file_a = os.path.join(self.publish_base, 'a', 'listing')
updir = os.path.join(self.publish_base, 'a')
util.touch(listing_file_a)
old_symlink = os.path.join(self.publish_base, 'a', 'path_to_removed_symlink')
self.distributor.clean_simple_hosting_directories(old_symlink, self.publish_base)
mock_util.generate_listing_files.assert_called_once_with(updir, updir)
示例12: test_create_symlink_no_link_parent
def test_create_symlink_no_link_parent(self, mock_makedirs, mock_symlink):
source_path = os.path.join(self.working_dir, 'source')
link_path = os.path.join(self.published_dir, 'foo/bar/baz/link')
touch(source_path)
self.assertFalse(os.path.exists(os.path.dirname(link_path)))
misc.create_symlink(source_path, link_path)
mock_makedirs.assert_called_once_with(os.path.dirname(link_path), mode=0770)
mock_symlink.assert_called_once_with(source_path, link_path)
示例13: test_clear_directory
def test_clear_directory(self):
for file_name in ('one', 'two', 'three'):
touch(os.path.join(self.working_dir, file_name))
os.makedirs(os.path.join(self.working_dir, 'four'))
self.assertEqual(len(os.listdir(self.working_dir)), 4)
misc.clear_directory(self.working_dir, ['two'])
self.assertEqual(len(os.listdir(self.working_dir)), 1)
示例14: test_process_unit
def test_process_unit(self):
step = publish_steps.PublishImagesStep()
fake_image_filename = 'fake-zero-byte-image.qcow2'
touch(os.path.join(self.content_directory, fake_image_filename))
unit = Mock(unit_key={'image_checksum': 'd41d8cd98f00b204e9800998ecf8427e'},
storage_path=os.path.join(self.content_directory, fake_image_filename))
step.get_working_dir = Mock(return_value=self.publish_directory)
step.process_unit(unit)
# verify symlink
expected_symlink = os.path.join(self.publish_directory, 'web', fake_image_filename)
self.assertTrue(os.path.exists(expected_symlink))
示例15: test_create_symlink
def test_create_symlink(self):
source_path = os.path.join(self.working_dir, 'source')
link_path = os.path.join(self.published_dir, 'link')
touch(source_path)
self.assertFalse(os.path.exists(link_path))
PublishStep._create_symlink(source_path, link_path)
self.assertTrue(os.path.exists(link_path))
self.assertTrue(os.path.islink(link_path))
self.assertEqual(os.readlink(link_path), source_path)