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


Python os.symlink方法代码示例

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


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

示例1: _get_symbolic_link_path

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def _get_symbolic_link_path(self, original_file_path):
		"""
		Get path to local symbolic link since mothur might act odd else.

		@param original_file_path:
		@type original_file_path: str | unicode

		@return: Local path
		@rtype: str | unicode
		"""
		assert isinstance(original_file_path, basestring)
		basename = os.path.basename(original_file_path)
		new_path = os.path.join(self._tmp_dir, basename)
		os.symlink(original_file_path, new_path)
		# return new_path
		return basename 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:18,代码来源:mgcluster.py

示例2: test_fix_rpath

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_fix_rpath():
    # Test wheels which have an @rpath dependency
    # Also verifies the delocated libraries signature
    with InTemporaryDirectory():
        # The module was set to expect its dependency in the libs/ directory
        os.symlink(DATA_PATH, 'libs')

        stray_lib = realpath('libs/libextfunc_rpath.dylib')
        with InWheel(RPATH_WHEEL):
            # dep_mod can vary depending the Python version used to build
            # the test wheel
            dep_mod = 'fakepkg/subpkg/module2.so'
        dep_path = '@rpath/libextfunc_rpath.dylib'

        assert_equal(
            delocate_wheel(RPATH_WHEEL, 'tmp.whl'),
            {stray_lib: {dep_mod: dep_path}},
        )
        with InWheel('tmp.whl'):
            check_call(['codesign', '--verify',
                        'fakepkg/.dylibs/libextfunc_rpath.dylib']) 
开发者ID:matthew-brett,项目名称:delocate,代码行数:23,代码来源:test_wheelies.py

示例3: test_copyfile_symlink_follow

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_copyfile_symlink_follow(smb_share):
    src_filename = "%s\\source.txt" % smb_share
    src_link = "%s\\source-link.txt" % smb_share
    dst_filename = "%s\\target.txt" % smb_share

    with open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    symlink(src_filename, src_link)
    actual = copyfile(src_link, dst_filename)
    assert actual == dst_filename

    with open_file(dst_filename, mode='r') as fd:
        assert fd.read() == u"content"

    assert not islink(dst_filename) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:18,代码来源:test_smbclient_shutil.py

示例4: test_copyfile_symlink_dont_follow

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_copyfile_symlink_dont_follow(smb_share):
    src_filename = "%s\\source.txt" % smb_share
    src_link = "%s\\source-link.txt" % smb_share
    dst_filename = "%s\\target.txt" % smb_share

    with open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    symlink(src_filename, src_link)
    actual = copyfile(src_link, dst_filename, follow_symlinks=False)
    assert actual == dst_filename

    with open_file(dst_filename, mode='r') as fd:
        assert fd.read() == u"content"

    assert islink(dst_filename)
    assert readlink(dst_filename) == ntpath.normpath(src_filename) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:19,代码来源:test_smbclient_shutil.py

示例5: test_copymode_local_to_local_symlink_dont_follow

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_copymode_local_to_local_symlink_dont_follow(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    expected = "chmod: follow_symlinks unavailable on this platform"
    with pytest.raises(NotImplementedError, match=re.escape(expected)):
        copymode(src_link, dst_link, follow_symlinks=False) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:23,代码来源:test_smbclient_shutil.py

示例6: test_copystat_local_to_local_symlink_dont_follow_fail

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_copystat_local_to_local_symlink_dont_follow_fail(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    expected = "follow_symlinks unavailable on this platform"
    with pytest.raises(NotImplementedError, match=re.escape(expected)):
        copystat(src_link, dst_link, follow_symlinks=False) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:23,代码来源:test_smbclient_shutil.py

示例7: test_copytree_with_broken_symlink_fail

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_copytree_with_broken_symlink_fail(smb_share):
    src_dirname = "%s\\source" % smb_share
    dst_dirname = "%s\\target" % smb_share

    mkdir(src_dirname)
    symlink("%s\\dir" % src_dirname, "%s\\link" % src_dirname, target_is_directory=True)
    symlink("%s\\file.txt" % src_dirname, "%s\\link.txt" % src_dirname)

    with pytest.raises(shutil.Error) as actual:
        copytree(src_dirname, dst_dirname)

    assert len(actual.value.args[0]) == 2
    err1 = actual.value.args[0][0]
    err2 = actual.value.args[0][1]

    assert err1[0] == "%s\\link" % src_dirname
    assert err1[1] == "%s\\link" % dst_dirname
    assert "No such file or directory" in err1[2]

    assert err2[0] == "%s\\link.txt" % src_dirname
    assert err2[1] == "%s\\link.txt" % dst_dirname
    assert "No such file or directory" in err2[2] 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:24,代码来源:test_smbclient_shutil.py

示例8: test_rmtree

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_rmtree(smb_share):
    mkdir("%s\\dir2" % smb_share)
    mkdir("%s\\dir2\\dir3" % smb_share)

    with open_file("%s\\dir2\\dir3\\file1" % smb_share, mode='w') as fd:
        fd.write(u"content")

    with open_file("%s\\dir2\\file2" % smb_share, mode='w') as fd:
        fd.write(u"content")

    if os.name == "nt" or os.environ.get('SMB_FORCE', False):
        # File symlink
        symlink("%s\\dir2\\file2" % smb_share, "%s\\dir2\\file3" % smb_share)
        symlink("missing", "%s\\dir2\\file3-broken" % smb_share)

        # Dir symlink
        symlink("%s\\dir2\\dir3" % smb_share, "%s\\dir2\\dir-link" % smb_share)
        symlink("missing", "%s\\dir2\\dir-link-broken" % smb_share, target_is_directory=True)

    assert exists("%s\\dir2" % smb_share) is True

    rmtree("%s\\dir2" % smb_share)

    assert exists("%s\\dir2" % smb_share) is False 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:26,代码来源:test_smbclient_shutil.py

示例9: test_rmtree_symlink_as_dir

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def test_rmtree_symlink_as_dir(smb_share):
    src_dirname = "%s\\dir" % smb_share
    dst_dirname = "%s\\target" % smb_share
    mkdir(src_dirname)
    symlink("dir", dst_dirname)

    expected = "Cannot call rmtree on a symbolic link"
    with pytest.raises(OSError, match=re.escape(expected)):
        rmtree(dst_dirname)

    assert exists(src_dirname)
    assert exists(dst_dirname)

    rmtree(dst_dirname, ignore_errors=True)

    callback_args = []

    def callback(*args):
        callback_args.append(args)

    rmtree(dst_dirname, onerror=callback)
    assert len(callback_args) == 1
    assert callback_args[0][0].__name__ == 'islink'
    assert callback_args[0][1] == dst_dirname
    assert isinstance(callback_args[0][2][1], OSError) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:27,代码来源:test_smbclient_shutil.py

示例10: _find_link_target

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def _find_link_target(self, tarinfo):
        """Find the target member of a symlink or hardlink member in the
           archive.
        """
        if tarinfo.issym():
            # Always search the entire archive.
            linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
            limit = None
        else:
            # Search the archive before the link, because a hard link is
            # just a reference to an already archived file.
            linkname = tarinfo.linkname
            limit = tarinfo

        member = self._getmember(linkname, tarinfo=limit, normalize=True)
        if member is None:
            raise KeyError("linkname %r not found" % linkname)
        return member 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:tarfile.py

示例11: fake_ciftify_work_dir

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def fake_ciftify_work_dir():
    '''link in files to mode a ciftify work dir so that qc pages can be generated'''
    with ciftify.utils.TempDir() as ciftify_wd:
        # create a temp outputdir
        subject = "sub-50005"
        surfs_dir = os.path.join(ciftify_wd, subject, 'MNINonLinear', 'fsaverage_LR32k')
        run(['mkdir', '-p', surfs_dir])
        os.symlink(left_surface, os.path.join(surfs_dir, 'sub-50005.L.midthickness.32k_fs_LR.surf.gii'))
        os.symlink(right_surface, os.path.join(surfs_dir, 'sub-50005.R.midthickness.32k_fs_LR.surf.gii'))
        for hemi in ['L', 'R']:
            old_path = os.path.join(ciftify.config.find_ciftify_global(),
                'HCP_S1200_GroupAvg_v1',
                'S1200.{}.very_inflated_MSMAll.32k_fs_LR.surf.gii'.format(hemi))
            new_path = os.path.join(surfs_dir,
            'sub-50005.{}.very_inflated.32k_fs_LR.surf.gii'.format(hemi))
            os.symlink(old_path, new_path)
        yield ciftify_wd 
开发者ID:edickie,项目名称:ciftify,代码行数:19,代码来源:test_ciftify_pint_vertices.py

示例12: prepare_dataset

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def prepare_dataset(scene_ids, out_dir):
    root_img = os.path.join(out_dir, 'img')
    root_cor = os.path.join(out_dir, 'label_cor')
    os.makedirs(root_img, exist_ok=True)
    os.makedirs(root_cor, exist_ok=True)
    for scene_id in tqdm(scene_ids):
        source_img_root = os.path.join(args.in_root, scene_id, 'rgb')
        source_cor_root = os.path.join(args.in_root, scene_id, 'layout')
        for fname in os.listdir(source_cor_root):
            room_id = fname.split('_')[0]
            source_img_path = os.path.join(args.in_root, scene_id, 'rgb', room_id + '_rgb_rawlight.png')
            source_cor_path = os.path.join(args.in_root, scene_id, 'layout', room_id + '_layout.txt')
            target_img_path = os.path.join(root_img, '%s_%s.png' % (scene_id, room_id))
            target_cor_path = os.path.join(root_cor, '%s_%s.txt' % (scene_id, room_id))
            assert os.path.isfile(source_img_path)
            assert os.path.isfile(source_cor_path)
            os.symlink(source_img_path, target_img_path)
            os.symlink(source_cor_path, target_cor_path) 
开发者ID:sunset1995,项目名称:HorizonNet,代码行数:20,代码来源:structured3d_prepare_dataset.py

示例13: symlink

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def symlink(parser, cmd, args):
    """
    Set up symlinks for (a subset of) the pwny apps.
    """

    parser.add_argument(
        'apps',
        nargs=argparse.REMAINDER,
        help='Which apps to create symlinks for.'
    )
    args = parser.parse_args(args)

    base_dir, pwny_main = os.path.split(sys.argv[0])

    for app_name, config in MAIN_FUNCTIONS.items():
        if not config['symlink'] or (args.apps and app_name not in args.apps):
            continue
        dest = os.path.join(base_dir, app_name)
        if not os.path.exists(dest):
            print('Creating symlink %s' % dest)
            os.symlink(pwny_main, dest)
        else:
            print('Not creating symlink %s (file already exists)' % dest) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:25,代码来源:main.py

示例14: create_link

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def create_link(dataset_dir):
    dirs = {}
    dirs['trainA'] = os.path.join(dataset_dir, 'ltrainA')
    dirs['trainB'] = os.path.join(dataset_dir, 'ltrainB')
    dirs['testA'] = os.path.join(dataset_dir, 'ltestA')
    dirs['testB'] = os.path.join(dataset_dir, 'ltestB')
    mkdir(dirs.values())

    for key in dirs:
        try:
            os.remove(os.path.join(dirs[key], 'Link'))
        except:
            pass
        os.symlink(os.path.abspath(os.path.join(dataset_dir, key)),
                   os.path.join(dirs[key], 'Link'))

    return dirs 
开发者ID:arnab39,项目名称:cycleGAN-PyTorch,代码行数:19,代码来源:utils.py

示例15: links_setup

# 需要导入模块: import os [as 别名]
# 或者: from os import symlink [as 别名]
def links_setup(install_dir):
    if sys.platform == 'win32':
        _create_shortcut(
            os.path.join(install_dir, 'examples'),
            os.path.join(SIMNIBSDIR, 'examples')
        )
        _create_shortcut(
            os.path.join(install_dir, 'simnibs'),
            os.path.join(SIMNIBSDIR)
        )
    else:
        lnk = os.path.join(install_dir, 'examples')
        if os.path.islink(lnk):
            os.remove(lnk)
        os.symlink(os.path.join(SIMNIBSDIR, 'examples'), lnk)
        lnk = os.path.join(install_dir, 'simnibs')
        if os.path.islink(lnk):
            os.remove(lnk)
        os.symlink(SIMNIBSDIR, lnk) 
开发者ID:simnibs,项目名称:simnibs,代码行数:21,代码来源:postinstall_simnibs.py


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