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


Python posixpath.abspath函数代码示例

本文整理汇总了Python中posixpath.abspath函数的典型用法代码示例。如果您正苦于以下问题:Python abspath函数的具体用法?Python abspath怎么用?Python abspath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_abspath

    def test_abspath(self):
        self.assert_("foo" in posixpath.abspath("foo"))

        # Issue 3426: check that abspath retuns unicode when the arg is unicode
        # and str when it's str, with both ASCII and non-ASCII cwds
        saved_cwd = os.getcwd()
        cwds = ['cwd']
        try:
            cwds.append(u'\xe7w\xf0'.encode(sys.getfilesystemencoding()
                                            or 'ascii'))
        except UnicodeEncodeError:
            pass # the cwd can't be encoded -- test with ascii cwd only
        for cwd in cwds:
            try:
                os.mkdir(cwd)
                os.chdir(cwd)
                for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
                    self.assertTrue(isinstance(posixpath.abspath(path), str))
                for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
                    self.assertTrue(isinstance(posixpath.abspath(upath), unicode))
            finally:
                os.chdir(saved_cwd)
                os.rmdir(cwd)

        self.assertRaises(TypeError, posixpath.abspath)
开发者ID:DecipherOne,项目名称:Troglodyte,代码行数:25,代码来源:test_posixpath.py

示例2: should_skip

def should_skip(filename, config, path=''):
    """Returns True if the file and/or folder should be skipped based on the passed in settings."""
    os_path = os.path.join(path, filename)

    normalized_path = os_path.replace('\\', '/')
    if normalized_path[1:2] == ':':
        normalized_path = normalized_path[2:]

    if path and config['safety_excludes']:
        check_exclude = '/' + filename.replace('\\', '/') + '/'
        if path and os.path.basename(path) in ('lib', ):
            check_exclude = '/' + os.path.basename(path) + check_exclude
        if safety_exclude_re.search(check_exclude):
            return True

    for skip_path in config['skip']:
        if posixpath.abspath(normalized_path) == posixpath.abspath(skip_path.replace('\\', '/')):
            return True

    position = os.path.split(filename)
    while position[1]:
        if position[1] in config['skip']:
            return True
        position = os.path.split(position[0])

    for glob in config['skip_glob']:
        if fnmatch.fnmatch(filename, glob) or fnmatch.fnmatch('/' + filename, glob):
            return True

    if not (os.path.isfile(os_path) or os.path.isdir(os_path) or os.path.islink(os_path)):
        return True

    return False
开发者ID:timothycrosley,项目名称:isort,代码行数:33,代码来源:settings.py

示例3: _relpath

    def _relpath(path, start=None):
        """Return a relative version of a path.

        Implementation by James Gardner in his BareNecessities
        package, under MIT licence.

        With a fix for Windows where posixpath.sep (and functions like
        join) use the Unix slash not the Windows slash.
        """
        import posixpath
        if start is None:
            start = posixpath.curdir
        else:
            start = start.replace(os.path.sep, posixpath.sep)
        if not path:
            raise ValueError("no path specified")
        else:
            path = path.replace(os.path.sep, posixpath.sep)
        start_list = posixpath.abspath(start).split(posixpath.sep)
        path_list = posixpath.abspath(path).split(posixpath.sep)
        # Work out how much of the filepath is shared by start and path.
        i = len(posixpath.commonprefix([start_list, path_list]))
        rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return posixpath.curdir.replace(posixpath.sep, os.path.sep)
        return posixpath.join(*rel_list).replace(posixpath.sep, os.path.sep)
开发者ID:DavidCain,项目名称:biopython,代码行数:26,代码来源:_paml.py

示例4: calculate_environment_for_directory

    def calculate_environment_for_directory(self, path):
        dir_path = posixpath.dirname(posixpath.abspath(path))
        env = {}

        for d, args in self.environment_for_directory:
            if posixpath.abspath(d) in dir_path:
                env.update(args)

        return env
开发者ID:aioupload,项目名称:dexy,代码行数:9,代码来源:parser.py

示例5: calculate_default_args_for_directory

    def calculate_default_args_for_directory(self, path):
        dir_path = posixpath.dirname(posixpath.abspath(path))
        default_kwargs = {}

        for d, args in self.default_args_for_directory:
            if posixpath.abspath(d) in dir_path:
                default_kwargs.update(args)

        return default_kwargs
开发者ID:aioupload,项目名称:dexy,代码行数:9,代码来源:parser.py

示例6: relpath

 def relpath(path, start=curdir):
     """Return a relative version of a path"""
     if not path:
         raise ValueError("no path specified")
     
     start_list = abspath(start).split(sep)
     path_list = abspath(path).split(sep)
     # Work out how much of the filepath is shared by start and path.
     i = len(commonprefix([start_list, path_list]))
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
     return curdir if not rel_list else join(*rel_list)
开发者ID:achuwilson,项目名称:openrave,代码行数:11,代码来源:misc.py

示例7: get_view_dir

def get_view_dir(args_view):
    caller_dir = posixpath.abspath('.')
    view_dir = posixpath.abspath(args_view)
    os.chdir(view_dir)
    view_dir = posixpath.abspath('')
    while not dir_has_rspec(view_dir):
        os.chdir('..')
        if view_dir == posixpath.abspath(''):
            logging.userErrorExit('ctx could not find an rspec in the supplied argument or any subdirectory')
        view_dir = posixpath.abspath('')
    return view_dir
开发者ID:arnognulf,项目名称:contexo,代码行数:11,代码来源:ctx2_common.py

示例8: relpath

 def relpath(path, start=posixpath.curdir):   # NOQA
     """Return a relative version of a path"""
     if not path:
         raise ValueError("no path specified")
     start_list = posixpath.abspath(start).split(posixpath.sep)
     path_list = posixpath.abspath(path).split(posixpath.sep)
     # Work out how much of the filepath is shared by start and path.
     i = len(posixpath.commonprefix([start_list, path_list]))
     rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
     if not rel_list:
         return posixpath.curdir
     return posixpath.join(*rel_list)
开发者ID:kevin-zhangsen,项目名称:badam,代码行数:12,代码来源:py3.py

示例9: posix_relpath

    def posix_relpath(path, start):
        sep = posixpath.sep
        start_list = [x for x in posixpath.abspath(start).split(sep) if x]
        path_list = [x for x in posixpath.abspath(path).split(sep) if x]

        # Work out how much of the filepath is shared by start and path.
        i = len(posixpath.commonprefix([start_list, path_list]))

        rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return posixpath.curdir
        return posixpath.join(*rel_list)
开发者ID:croach,项目名称:Frozen-Flask,代码行数:12,代码来源:__init__.py

示例10: relpath

def relpath(path, start=curdir):
    """Return a relative version of a path, backport to python2.4 from 2.6"""
    """http://www.saltycrane.com/blog/2010/03/ospathrelpath-source-code-python-25/ """
    if not path:
        raise ValueError("no path specified")
    start_list = posixpath.abspath(start).split(sep)
    path_list = posixpath.abspath(path).split(sep)
    # Work out how much of the filepath is shared by start and path.
    i = len(posixpath.commonprefix([start_list, path_list]))
    rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
    if not rel_list:
        return curdir
    return join(*rel_list)
开发者ID:floe,项目名称:pubMunch,代码行数:13,代码来源:util.py

示例11: relpath

def relpath(path, start=posixpath.curdir):
  """
  Return a relative filepath to path from the current directory or an optional start point.
  """
  if not path:
    raise ValueError("no path specified")
  start_list = posixpath.abspath(start).split(posixpath.sep)
  path_list = posixpath.abspath(path).split(posixpath.sep)
  # Work out how much of the filepath is shared by start and path.
  common = len(posixpath.commonprefix([start_list, path_list]))
  rel_list = [posixpath.pardir] * (len(start_list) - common) + path_list[common:]
  if not rel_list:
    return posixpath.curdir
  return posixpath.join(*rel_list)
开发者ID:azatoth,项目名称:buck,代码行数:14,代码来源:buck.py

示例12: relpath_unix

 def relpath_unix(self, path, start="."):
     # Relpath implementation directly ripped and modified from Python 2.6 source.
     sep="/"
     
     if not path:
         raise ValueError("no path specified")
     
     start_list = posixpath.abspath(start).split(sep)
     path_list = posixpath.abspath(path).split(sep)
     # Work out how much of the filepath is shared by start and path.
     i = len(self.commonprefix([start_list, path_list]))
     rel_list = [".."] * (len(start_list)-i) + path_list[i:]
     if not rel_list:
         return "."
     return posixpath.join(*rel_list)
开发者ID:bupt007,项目名称:fimap,代码行数:15,代码来源:baseClass.py

示例13: update_config_file

def update_config_file(dryrun=False):
    for site, site_config in config.sites.items():
        redis_processes = [
            (x, site_config.processes[x]) for x in site_config.processes if site_config.processes[x]["type"] == "redis"
        ]
        template_path = site_config["redis"]["template"]
        print redis_processes
        for process_name, process in redis_processes:
            working_directoy = posixpath.normpath(posixpath.join(env.path, "..", "data", "redis", process_name))
            log_directory = posixpath.normpath(posixpath.join(env.path, "..", "log", "redis"))
            run("mkdir -p " + working_directoy)
            run("mkdir -p " + log_directory)
            context_dict = site_config
            context_dict.update(
                {
                    "site": site,
                    "working_directory": working_directoy,
                    "log_directory": log_directory,
                    "process_name": process_name,
                    "socket": process["socket"],
                }
            )
            path = posixpath.abspath(
                posixpath.join(site_config["deployment"]["path"], "..", "config", process_name + ".conf")
            )
            output = render_template(template_path, context_dict)
            if dryrun:
                print path + ":"
                print output
            else:
                put(StringIO.StringIO(output), path)
开发者ID:justzx2011,项目名称:dploi-fabric,代码行数:31,代码来源:redis.py

示例14: _apply_regex_rule

    def _apply_regex_rule(self, rule_name, rule, cat_name, cat_path, settings):
        accepted_flags = {
            'a': re.ASCII,
            'i': re.IGNORECASE,
            'l': re.LOCALE,
            'x': re.VERBOSE
        }
        flags = sum([accepted_flags[f] for f in rule.get('flags', [])])

        pattern = None
        try:
            pattern = re.compile(rule['pattern'], flags)
        except KeyError:
            raise InvalidRegexFilter(cat_name, rule_name)

        actions = []

        rename = rule.get('rename', None)
        for root, dirs, files in os.walk(self._path):
            if posixpath.abspath(root) == self._repo_path:
                continue

            for file_name in files:
                file_name = posixpath.relpath(posixpath.join(root, file_name), self._path)

                match = pattern.match(file_name)
                if match:
                    new_name = file_name
                    if rename:
                        new_name = rename.format(**match.groupdict())

                    new_name = posixpath.join(cat_path, new_name)
                    actions.append(('mv', posixpath.join(self._path, file_name), new_name))

        return actions
开发者ID:asgeir,项目名称:old-school-projects,代码行数:35,代码来源:repository.py

示例15: test_relpath_bytes

    def test_relpath_bytes(self) -> None:
        real_getcwdb = os.getcwdb
        # mypy: can't modify os directly
        setattr(os, 'getcwdb', lambda: br"/home/user/bar")
        try:
            curdir = os.path.split(os.getcwdb())[-1]
            self.assertRaises(ValueError, posixpath.relpath, b"")
            self.assertEqual(posixpath.relpath(b"a"), b"a")
            self.assertEqual(posixpath.relpath(posixpath.abspath(b"a")), b"a")
            self.assertEqual(posixpath.relpath(b"a/b"), b"a/b")
            self.assertEqual(posixpath.relpath(b"../a/b"), b"../a/b")
            self.assertEqual(posixpath.relpath(b"a", b"../b"),
                             b"../"+curdir+b"/a")
            self.assertEqual(posixpath.relpath(b"a/b", b"../c"),
                             b"../"+curdir+b"/a/b")
            self.assertEqual(posixpath.relpath(b"a", b"b/c"), b"../../a")
            self.assertEqual(posixpath.relpath(b"a", b"a"), b".")
            self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x/y/z"), b'../../../foo/bar/bat')
            self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/foo/bar"), b'bat')
            self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/"), b'foo/bar/bat')
            self.assertEqual(posixpath.relpath(b"/", b"/foo/bar/bat"), b'../../..')
            self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo/bar/bat')
            self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../../x')
            self.assertEqual(posixpath.relpath(b"/", b"/"), b'.')
            self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.')
            self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.')

            self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
            self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")
        finally:
            setattr(os, 'getcwdb', real_getcwdb)
开发者ID:kivipe,项目名称:mypy,代码行数:31,代码来源:test_posixpath.py


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