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


Python posixpath.split函数代码示例

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


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

示例1: write_latex

def write_latex(outdir,images,prefix,query_image):
  otex=posixpath.join(outdir,'{}.tex'.format(prefix))
  with open(otex,'w') as f:
    print(r'''\documentclass{article}
\usepackage{graphicx}
\usepackage{fullpage}
\usepackage{paralist}
\usepackage{multirow}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amssymb,amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}''',file=f)
    x=query_image
    pname=posixpath.join(outdir,'{}query{}'.format(prefix,posixpath.splitext(x)[1]))
    shutil.copyfile(x,pname)
    print(r'''\begin{figure}[h]
\centering
\includegraphics[width=2.0in]{%s}
\caption{query} \label{fig:%s}
\end{figure}''' % (posixpath.split(pname)[1],prefix+'query'),file=f)
    print(r'\begin{figure}',file=f)
    for i,x in enumerate(images):
      pname=posixpath.join(outdir,'{}{:03}{}'.format(prefix,i,posixpath.splitext(x)[1]))
      shutil.copyfile(x,pname)
      print(r'''\begin{minipage}[b]{.5\linewidth}
\centering \includegraphics[width=1.0in]{%s}
\subcaption{A subfigure}\label{fig:%s}
\end{minipage}''' % (posixpath.split(pname)[1],prefix+str(i)),file=f)
    print(r'\end{figure}',file=f)
    print(r'''\end{document}''',file=f)
开发者ID:CV-IP,项目名称:opensurfaces,代码行数:32,代码来源:gist.py

示例2: __init__

    def __init__(self, cmpFullPath, includes):
        self.cmpFullPath = cmpFullPath
        cppPath = cmpFullPath[cmpFullPath.index('/src/scripts/cmp')+len('/src/scripts'):].replace('/cmp/', '/cpp/').replace('.cmp', '.cpp')
        self.cppFullPath = bindir() + cppPath
        self.hFullPath = self.cppFullPath.replace('.cpp', '.h')
        self.cmpFilename = posixpath.split(self.cmpFullPath)[1]
        self.cppFilename = posixpath.split(self.cppFullPath)[1]
        self.hFilename = posixpath.split(self.hFullPath)[1]
        
        self.cppExists, self.cppModTime = check_file(self.cppFullPath)
        self.cmpExists, self.cmpModTime = check_file(self.cmpFullPath)
        self.hExists, self.hModTime = check_file(self.hFullPath)

        if (self.cppExists):
            self.cppOutputOld, self.cppSourceOld, self.cppSourceOldHash = read_cpp_file(self.cppFullPath)
            self.cppSourceOldHashActual = md5.new(self.cppSourceOld).hexdigest()

        if (self.hExists):
            self.hOutputOld, self.hSourceOld, self.hSourceOldHash = read_cpp_file(self.hFullPath)
            self.hSourceOldHashActual = md5.new(self.hSourceOld).hexdigest()

        self._compile(includes)

        self.cppOutput = TEMPLATE % (self.cppFilename, self.cmpFilename, license_text('//', self.cppFullPath), self.cppSourceHash, self.cppSource)

        if (self.hSource is not None):
            self.hOutput = TEMPLATE % (self.hFilename, self.cmpFilename, license_text('//', self.hFullPath), self.hSourceHash, self.hSource)
开发者ID:lachlanorr,项目名称:gaen,代码行数:27,代码来源:codegen.py

示例3: StatAsync

  def StatAsync(self, path):

    def get_child_versions(path):
      return dict((e['name'], e['id'])
                  for e in local_git_util.ListDir(path, self._commit))

    def get_file_version(dir, filename):
      try:
        return next(e['id'] for e in local_git_util.ListDir(dir, self._commit)
                    if e['name'] == filename)
      except StopIteration:
        raise FileNotFoundError('%s not found in revision %s' %
                                (path, self._commit))

    dir, filename = posixpath.split(path)
    if path == '':
      version = local_git_util.GetRootTree(self._commit)
      child_versions = get_child_versions('')
    elif IsDirectory(path):
      parent_dir, stat_dir = posixpath.split(dir)
      version = get_file_version(parent_dir, stat_dir)
      child_versions = get_child_versions(dir)
    else:
      version = get_file_version(dir, filename)
      child_versions = None

    #print 'Accessing local git for stat on %s (%s)' % (path, version)
    return Future(value=StatInfo(version, child_versions))
开发者ID:AlinaGlavan,项目名称:chromium,代码行数:28,代码来源:local_git_file_system.py

示例4: walk

    def walk(self, path, refresh=False):
        """
        Directory tree generator, like os.walk

        Generator version of what is in s3fs, which yields a flattened list of
        files
        """
        path = path.replace('s3://', '')
        directories = set()
        files = set()

        for key in list(self.fs._ls(path, refresh=refresh)):
            path = key['Key']
            if key['StorageClass'] == 'DIRECTORY':
                directories.add(path)
            elif key['StorageClass'] == 'BUCKET':
                pass
            else:
                files.add(path)

        # s3fs creates duplicate 'DIRECTORY' entries
        files = sorted([posixpath.split(f)[1] for f in files
                        if f not in directories])
        directories = sorted([posixpath.split(x)[1]
                              for x in directories])

        yield path, directories, files

        for directory in directories:
            for tup in self.walk(directory, refresh=refresh):
                yield tup
开发者ID:CodingCat,项目名称:arrow,代码行数:31,代码来源:filesystem.py

示例5: makedirs

def makedirs(name, mode=0o777, exist_ok=False):
    """makedirs(path [, mode=0o777][, exist_ok=False])

    Super-mkdir; create a leaf directory and all intermediate ones.
    Works like mkdir, except that any intermediate path segment (not
    just the rightmost) will be created if it does not exist. If the
    target directory with the same mode as we specified already exists,
    raises an OSError if exist_ok is False, otherwise no exception is
    raised.  This is recursive.

    """
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs(head, mode, exist_ok)
        except OSError as e:
            # be happy if someone already created the path
            if e.errno != errno.EEXIST:
                raise
        if tail == curdir:           # xxx/newdir/. exists if xxx/newdir exists
            return
    try:
        mkdir(name, mode)
    except OSError as e:
        import stat as st
        if not (e.errno == errno.EEXIST and exist_ok and path.isdir(name) and
                st.S_IMODE(lstat(name).st_mode) == _get_masked_mode(mode)):
            raise
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:30,代码来源:os.py

示例6: get_template

def get_template(archivist, context):
    """Return the correct Jinja2 Template object for this archetype."""
    templates = []

    # Most specific to least specific. Does the archetype request a
    # custom template? Note that config values may be a list, or a
    # single string.
    t = context.get('template')
    if is_sequence(t):
        templates.extend(t)
    elif t:
        templates.append(t)

    # Next, we'll look for templates specific to the itemtype, crawling up the
    # hierarchy for fallbacks.
    if 'itemtype' in context:
        templates.append(context['itemtype'])
        (root, _) = path.split(context['itemtype'])
        while root:
            templates.append(root)
            (root, _) = path.split(root)

    # Does the siteconfig specify a default template?
    t = archivist.siteconfig.get('default_template')
    if is_sequence(t):
        templates.extend(t)
    elif t:
        templates.append(t)

    # If no configured default, fall back to "emergency" default.
    templates.append(Template(fallback_template))

    return archivist.jinja.select_template(templates)
开发者ID:veselosky,项目名称:bluebucket,代码行数:33,代码来源:page_to_html.py

示例7: lookup

    def lookup(self, path=None,inode=None, inode_id=None):
        dbh=DB.DBO(self.case)
        if path:
            dir,name = posixpath.split(path)
            if not name:
                dir,name = posixpath.split(path[:-1])
            if dir == '/':
                dir = ''

            dbh.check_index('file','path', 200)
            dbh.check_index('file','name', 200)
            dbh.execute("select inode,inode_id from file where path=%r and (name=%r or name=concat(%r,'/')) limit 1", (dir+'/',name,name))
            res = dbh.fetch()
            if not res:
                raise RuntimeError("VFS path not found %s/%s" % (dir,name))
            return path, res["inode"], res['inode_id']
        
        elif inode_id:
            dbh.check_index('inode','inode_id')
            dbh.execute("select mtime, inode.inode, concat(path,name) as path from inode left join file on inode.inode_id=file.inode_id where inode.inode_id=%r order by file.status limit 1", inode_id)
            res = dbh.fetch()
            if not res: raise IOError("Inode ID %s not found" % inode_id)
            self.mtime = res['mtime']
            return res['path'],res['inode'], inode_id

        else:
            dbh.check_index('file','inode')
            dbh.execute("select inode.inode_id,concat(path,name) as path from file join inode on inode.inode_id = file.inode_id where inode.inode=%r order by file.status limit 1", inode)
            res = dbh.fetch()
            if not res:
                raise RuntimeError("VFS Inode %s not known" % inode)
            return res["path"], inode, res['inode_id']
开发者ID:arkem,项目名称:pyflag,代码行数:32,代码来源:FileSystem.py

示例8: makedirs

def makedirs(name, mode=0o777, exist_ok=False):
    """makedirs(name [, mode=0o777][, exist_ok=False])

    Super-mkdir; create a leaf directory and all intermediate ones.  Works like
    mkdir, except that any intermediate path segment (not just the rightmost)
    will be created if it does not exist. If the target directory already
    exists, raise an OSError if exist_ok is False. Otherwise no exception is
    raised.  This is recursive.

    """
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs(head, exist_ok=exist_ok)
        except FileExistsError:
            # Defeats race condition when another thread created the path
            pass
        cdir = curdir
        if isinstance(tail, bytes):
            cdir = bytes(curdir, 'ASCII')
        if tail == cdir:           # xxx/newdir/. exists if xxx/newdir exists
            return
    try:
        mkdir(name, mode)
    except OSError:
        # Cannot rely on checking for EEXIST, since the operating system
        # could give priority to other errors like EACCES or EROFS
        if not exist_ok or not path.isdir(name):
            raise
开发者ID:Daetalus,项目名称:cpython,代码行数:31,代码来源:os.py

示例9: renames

def renames(old, new):
    """renames(old, new)

    Super-rename; create directories as necessary and delete any left
    empty.  Works like rename, except creation of any intermediate
    directories needed to make the new pathname good is attempted
    first.  After the rename, directories corresponding to rightmost
    path segments of the old name will be pruned way until either the
    whole path is consumed or a nonempty directory is found.

    Note: this function can fail with the new directory structure made
    if you lack permissions needed to unlink the leaf directory or
    file.

    """
    head, tail = path.split(new)
    if head and tail and not path.exists(head):
        makedirs(head)
    rename(old, new)
    head, tail = path.split(old)
    if head and tail:
        try:
            removedirs(head)
        except error:
            pass
开发者ID:develersrl,项目名称:dspython,代码行数:25,代码来源:os.py

示例10: lookup

    def lookup(self, path=None, inode=None, inode_id=None):
        dbh=DB.DBO(self.case)
        if path:
            dir,name = posixpath.split(path)
            if not name:
                dir,name = posixpath.split(path[:-1])
            if dir == '/':
                dir = ''

            dbh.execute("select inode_id from vfs "
                        "where path=%r and name=%r and "
                        "not isnull(inode_id) limit 1", (dir,name,name))
            res = dbh.fetch()
            if not res:
                raise RuntimeError("VFS path not found %s/%s" % (dir,name))
            return res['inode_id']
        
        elif inode_id:
            dbh.execute("select inode_id, concat(path,'/',name) as path from vfs  "
                        "where vfs.inode_id=%r limit 1", inode_id)
            res = dbh.fetch()
            if not res: raise IOError("Inode ID %s not found" % inode_id)
            return res['path']

        else:
            dbh.execute("select vfs.inode_id, concat(path,'/',name) as path from vfs "
                        "where urn=%r limit 1", inode)
            res = dbh.fetch()
            if not res:
                raise RuntimeError("VFS Inode %s not known" % inode)
            return res["path"], res['inode_id']
开发者ID:py4n6,项目名称:pyflag,代码行数:31,代码来源:FileSystem.py

示例11: makedirs

def makedirs(name, mode=0o777, exist_ok=False):
    """makedirs(name [, mode=0o777][, exist_ok=False])

    Super-mkdir; create a leaf directory and all intermediate ones.  Works like
    mkdir, except that any intermediate path segment (not just the rightmost)
    will be created if it does not exist. If the target directory already
    exists, raise an OSError if exist_ok is False. Otherwise no exception is
    raised.  This is recursive.

    """
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs(head, mode, exist_ok)
        except FileExistsError:
            # be happy if someone already created the path
            pass
        cdir = curdir
        if isinstance(tail, bytes):
            cdir = bytes(curdir, 'ASCII')
        if tail == cdir:           # xxx/newdir/. exists if xxx/newdir exists
            return
    try:
        mkdir(name, mode)
    except OSError as e:
        if not exist_ok or e.errno != errno.EEXIST or not path.isdir(name):
            raise
开发者ID:ztane,项目名称:jython3,代码行数:29,代码来源:os.py

示例12: test_split

    def test_split(self):
        self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar"))
        self.assertEqual(posixpath.split("/"), ("/", ""))
        self.assertEqual(posixpath.split("foo"), ("", "foo"))
        self.assertEqual(posixpath.split("////foo"), ("////", "foo"))
        self.assertEqual(posixpath.split("//foo//bar"), ("//foo", "bar"))

        self.assertRaises(TypeError, posixpath.split)
开发者ID:CaoYouXin,项目名称:myfirstapicloudapp,代码行数:8,代码来源:test_posixpath.py

示例13: connect

    def connect(self, identifier=None, active=False):
        '''
        POST initial survey content to kobocat and create a new project.
        store results in self.asset._deployment_data.
        '''
        # If no identifier was provided, construct one using
        # `settings.KOBOCAT_URL` and the uid of the asset
        if not identifier:
            # Use the external URL here; the internal URL will be substituted
            # in when appropriate
            if not settings.KOBOCAT_URL or not settings.KOBOCAT_INTERNAL_URL:
                raise ImproperlyConfigured(
                    'Both KOBOCAT_URL and KOBOCAT_INTERNAL_URL must be '
                    'configured before using KobocatDeploymentBackend'
                )
            server = settings.KOBOCAT_URL
            username = self.asset.owner.username
            id_string = self.asset.uid
            identifier = '{server}/{username}/forms/{id_string}'.format(
                server=server,
                username=username,
                id_string=id_string,
            )
        else:
            # Parse the provided identifier, which is expected to follow the
            # format http://kobocat_server/username/forms/id_string
            parsed_identifier = urlparse.urlparse(identifier)
            server = u'{}://{}'.format(
                parsed_identifier.scheme, parsed_identifier.netloc)
            path_head, path_tail = posixpath.split(parsed_identifier.path)
            id_string = path_tail
            path_head, path_tail = posixpath.split(path_head)
            if path_tail != 'forms':
                raise Exception('The identifier is not properly formatted.')
            path_head, path_tail = posixpath.split(path_head)
            if path_tail != self.asset.owner.username:
                raise Exception(
                    'The username in the identifier does not match the owner '
                    'of this asset.'
                )
            if path_head != '/':
                raise Exception('The identifier is not properly formatted.')

        url = self.external_to_internal_url(u'{}/api/v1/forms'.format(server))
        csv_io = self.to_csv_io(self.asset.to_xls_io(versioned=True), id_string)
        valid_xlsform_csv_repr = csv_io.getvalue()
        payload = {
            u'text_xls_form': valid_xlsform_csv_repr,
            u'downloadable': active
        }
        json_response = self._kobocat_request('POST', url, payload)
        self.store_data({
            'backend': 'kobocat',
            'identifier': self.internal_to_external_url(identifier),
            'active': json_response['downloadable'],
            'backend_response': json_response,
            'version': self.asset.version_id,
        })
开发者ID:abhishekricky,项目名称:kpi,代码行数:58,代码来源:kobocat_backend.py

示例14: _generate_file_diff

 def _generate_file_diff(self, buf):
         change = None
         if self.src_kind == svn.core.svn_node_none:
             change = "add"
         elif self.tgt_kind == svn.core.svn_node_none:
             change = "delete"
         tgt_base, tgt_path = vcspath.split(self.tgt_path)
         src_base, src_path = vcspath.split(self.src_path)
         self._generate_node_diff(
             buf, change, tgt_path, tgt_base, src_path, src_base)
开发者ID:rhodecode,项目名称:rhodecode-vcsserver,代码行数:10,代码来源:svn.py

示例15: renames

def renames(old, new):
    head, tail = path.split(new)
    if head and tail and not path.exists(head):
        makedirs(head)
    rename(old, new)
    head, tail = path.split(old)
    if head and tail:
        try:
            removedirs(head)
        except error:
            pass
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:11,代码来源:os.py


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