本文整理汇总了Python中pulp.plugins.util.misc.create_symlink函数的典型用法代码示例。如果您正苦于以下问题:Python create_symlink函数的具体用法?Python create_symlink怎么用?Python create_symlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_symlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _publish_distribution_treeinfo
def _publish_distribution_treeinfo(self, distribution_unit):
"""
For a given AssociatedUnit for a distribution. Create the links for the treeinfo file
back to the treeinfo in the content.
:param distribution_unit: The unit for the distribution from which the list
of files to be published should be pulled from.
:type distribution_unit: pulp_rpm.plugins.db.models.Distribution
"""
distribution_unit_storage_path = distribution_unit._storage_path
src_treeinfo_path = None
treeinfo_file_name = None
for treeinfo in constants.TREE_INFO_LIST:
test_treeinfo_path = os.path.join(distribution_unit_storage_path, treeinfo)
if os.path.exists(test_treeinfo_path):
# we found the treeinfo file
src_treeinfo_path = test_treeinfo_path
treeinfo_file_name = treeinfo
break
if src_treeinfo_path is not None:
# create a symlink from content location to repo location.
symlink_treeinfo_path = os.path.join(self.get_working_dir(), treeinfo_file_name)
logger.debug("creating treeinfo symlink from %s to %s" % (src_treeinfo_path,
symlink_treeinfo_path))
plugin_misc.create_symlink(src_treeinfo_path, symlink_treeinfo_path)
示例2: _publish_distribution_files
def _publish_distribution_files(self, distribution_unit):
"""
For a given AssociatedUnit for a distribution. Create all the links back to the
content units that are referenced within the 'files' metadata section of the unit.
:param distribution_unit: The unit for the distribution from which the list
of files to be published should be pulled from.
:type distribution_unit: pulp_rpm.plugins.db.models.Distribution
"""
if not distribution_unit.files:
msg = "No distribution files found for unit %s" % distribution_unit
logger.warning(msg)
return
distro_files = distribution_unit.files
total_files = len(distro_files)
logger.debug("Found %s distribution files to symlink" % total_files)
source_path_dir = distribution_unit._storage_path
symlink_dir = self.get_working_dir()
for dfile in distro_files:
if dfile['relativepath'].startswith('repodata/'):
continue
source_path = os.path.join(source_path_dir, dfile['relativepath'])
symlink_path = os.path.join(symlink_dir, dfile['relativepath'])
plugin_misc.create_symlink(source_path, symlink_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: process_main
def process_main(self, item):
"""
Link the item to the Blob file.
:param item: The Blob to process
:type item: pulp_docker.plugins.models.Blob
"""
misc.create_symlink(item._storage_path,
os.path.join(self.get_blobs_directory(), item.unit_key['digest']))
示例5: test_create_symlink_no_source
def test_create_symlink_no_source(self):
"""Assert links are created, even if the source doesn't exist."""
source_path = os.path.join(self.working_dir, "source")
link_path = os.path.join(self.published_dir, "link")
self.assertFalse(os.path.exists(source_path))
self.assertFalse(os.path.exists(link_path))
misc.create_symlink(source_path, link_path)
self.assertTrue(os.path.lexists(link_path))
self.assertFalse(os.path.exists(source_path))
示例6: 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)
示例7: 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)
示例8: process_main
def process_main(self, item):
"""
Create the manifest tag links.
:param item: The tag to process
:type item: pulp_docker.plugins.models.Tag
"""
manifest = models.Manifest.objects.get(digest=item.manifest_digest)
misc.create_symlink(
manifest._storage_path,
os.path.join(self.parent.publish_manifests_step.get_manifests_directory(), item.name))
self._tag_names.add(item.name)
示例9: test_create_symlink_link_exists_and_is_correct
def test_create_symlink_link_exists_and_is_correct(self):
new_source_path = os.path.join(self.working_dir, "new_source")
link_path = os.path.join(self.published_dir, "link")
touch(new_source_path)
os.symlink(new_source_path, link_path)
self.assertEqual(os.readlink(link_path), new_source_path)
misc.create_symlink(new_source_path, link_path)
self.assertEqual(os.readlink(link_path), new_source_path)
示例10: process_main
def process_main(self, item):
"""
Link the unit to the image content directory and the package_dir
:param item: The Image to process
:type item: pulp_docker.common.models.Image
"""
self.redirect_context.add_unit_metadata(item)
target_base = os.path.join(self.get_web_directory(), item.unit_key['image_id'])
files = ['ancestry', 'json', 'layer']
for file_name in files:
misc.create_symlink(os.path.join(item.storage_path, file_name),
os.path.join(target_base, file_name))
示例11: process_main
def process_main(self, item=None):
"""
Link the unit to the image content directory and the package_dir
:param item: The unit to process
:type item: pulp_docker.plugins.db.models.DockerImage
"""
self.redirect_context.add_unit_metadata(item)
target_base = os.path.join(self.get_web_directory(), item.image_id)
files = ['ancestry', 'json', 'layer']
for file_name in files:
plugin_utils.create_symlink(os.path.join(item.storage_path, file_name),
os.path.join(target_base, file_name))
示例12: test_create_symlink_link_exists
def test_create_symlink_link_exists(self):
old_source_path = os.path.join(self.working_dir, "old_source")
new_source_path = os.path.join(self.working_dir, "new_source")
link_path = os.path.join(self.published_dir, "link")
touch(old_source_path)
touch(new_source_path)
os.symlink(old_source_path, link_path)
self.assertEqual(os.readlink(link_path), old_source_path)
link_path_with_slash = link_path + "/"
misc.create_symlink(new_source_path, link_path_with_slash)
self.assertEqual(os.readlink(link_path), new_source_path)
示例13: _create_symlink
def _create_symlink(source_path, link_path):
"""
Create a symlink from the link path to the source path.
If the link_path points to a directory that does not exist the directory
will be created first.
If we are overriding a current symlink with a new target - a debug message will be logged
If a file already exists at the location specified by link_path an exception will be raised
:param source_path: path of the source to link to
:type source_path: str
:param link_path: path of the link
:type link_path: str
"""
misc.create_symlink(source_path, link_path)
示例14: process_main
def process_main(self, item=None):
"""
Link the unit to the content directory and the package_dir
:param item: The item to process or none if this get_iterator is not defined
:type item: pulp_rpm.plugins.db.models.RPM or pulp_rpm.plugins.db.models.SRPM
"""
unit = item
source_path = unit._storage_path
destination_path = os.path.join(self.get_working_dir(), unit.filename)
plugin_misc.create_symlink(source_path, destination_path)
for package_dir in self.dist_step.package_dirs:
destination_path = os.path.join(package_dir, unit.filename)
plugin_misc.create_symlink(source_path, destination_path)
for context in (self.file_lists_context, self.other_context, self.primary_context):
context.add_unit_metadata(unit)
示例15: _publish_distribution_files
def _publish_distribution_files(self, distribution_unit):
"""
For a given AssociatedUnit for a distribution. Create all the links back to the
content units that are referenced within the 'files' metadata section of the unit.
:param distribution_unit: The unit for the distribution from which the list
of files to be published should be pulled from.
:type distribution_unit: pulp_rpm.plugins.db.models.Distribution
"""
if not distribution_unit.files:
msg = "No distribution files found for unit %s" % distribution_unit
logger.warning(msg)
return
# The files from `treeinfo` and `PULP_DISTRIBUTION.xml` are mashed into the
# files list on the unit. This is a hacky work-around to unmash them, filter
# out anything that is in the main repodata directory (which is potentially not
# safe, but was happening before I got here and we don't have time to fix this
# properly right now), and generate a new `PULP_DISTRIBUTION.xml` that doesn't
# reference files that don't exist in this publish.
pulp_distribution_file = False
distro_files = [f['relativepath'] for f in distribution_unit.files]
if constants.DISTRIBUTION_XML in distro_files:
distro_files.remove(constants.DISTRIBUTION_XML)
pulp_distribution_file = True
distro_files = filter(lambda f: not f.startswith('repodata/'), distro_files)
total_files = len(distro_files)
logger.debug("Found %s distribution files to symlink" % total_files)
source_path_dir = distribution_unit._storage_path
symlink_dir = self.get_working_dir()
for dfile in distro_files:
source_path = os.path.join(source_path_dir, dfile)
symlink_path = os.path.join(symlink_dir, dfile)
plugin_misc.create_symlink(source_path, symlink_path)
# Not all repositories have this file so this is only done if the upstream repo
# had the file.
if pulp_distribution_file:
xml_file_path = os.path.join(source_path_dir, constants.DISTRIBUTION_XML)
self._write_pulp_distribution_file(distro_files, xml_file_path)