Python os.path 模块,lexists() 实例源码

我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用os.path.lexists()

项目:myDotFiles    作者:GuidoFe    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:myDotFiles    作者:GuidoFe    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:arch-setup-i3wm    作者:i-PUSH    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:arch-setup-i3wm    作者:i-PUSH    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:pbtranscript    作者:PacificBiosciences    | 项目源码 | 文件源码
def mkdir(path):
    """Create a directory if it does not pre-exist,
    otherwise, pass."""
    if not op.exists(path) and not op.lexists(path):
        try:
            os.makedirs(path)
        except OSError as e:
            # "File exists error" can happen when python
            # fails to syncronize with NFS or multiple
            # processes are trying to make the same dir.
            if e.errno == 17:
                pass
            else:
                raise OSError(e)
项目:pbtranscript    作者:PacificBiosciences    | 项目源码 | 文件源码
def ln(src, dst):
    """if src and dst are identical, pass. Otherwise, create dst, a soft
    symbolic link pointing to src."""
    if realpath(src) != realpath(dst):
        if op.exists(dst) or op.lexists(dst):
            os.remove(dst)
        logging.debug("Creating a symbolic link {dst} pointing to {src}".
                      format(dst=dst, src=src))
        os.symlink(realpath(src), realpath(dst))
项目:dotfiles    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:my-dots    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:my-dots    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:quanttyo    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:quanttyo    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:bookletchoir    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import mkdir

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            mkdir(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:bookletchoir    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:sixense    作者:a0726h77    | 项目源码 | 文件源码
def GetDirectory(multiple=False, selected=None, sep=None, **kwargs):
    """Prompt the user for a directory.

    This will raise a Zenity Directory Selection Dialog.  It will return a 
    list with the selected directories or None if the user hit cancel.

    multiple - True to allow the user to select multiple directories.
    selected - Path to the directory to be selected on startup.
    sep - Token to use as the path separator when parsing Zenity's return 
          string.
    kwargs - Optional command line parameters for Zenity such as height,
             width, etc."""

    args = ['--directory']
    if multiple:
        args.append('--multiple')
    if selected:
        if not path.lexists(selected):
            raise ValueError("File %s does not exist!" % selected)
        args.append('--filename=%s' % selected)
    if sep:
        args.append('--separator=%s' % sep)

    for generic_args in kwargs_helper(kwargs):
        args.append('--%s=%s' % generic_args)

    p = run_zenity('--file-selection', *args)

    if p.wait() == 0:
        return p.stdout.read().strip().split('|')
项目:sixense    作者:a0726h77    | 项目源码 | 文件源码
def GetDirectory(multiple=False, selected=None, sep=None, **kwargs):
    """Prompt the user for a directory.

    This will raise a Zenity Directory Selection Dialog.  It will return a 
    list with the selected directories or None if the user hit cancel.

    multiple - True to allow the user to select multiple directories.
    selected - Path to the directory to be selected on startup.
    sep - Token to use as the path separator when parsing Zenity's return 
          string.
    kwargs - Optional command line parameters for Zenity such as height,
             width, etc."""

    args = ['--directory']
    if multiple:
        args.append('--multiple')
    if selected:
        if not path.lexists(selected):
            raise ValueError("File %s does not exist!" % selected)
        args.append('--filename=%s' % selected)
    if sep:
        args.append('--separator=%s' % sep)

    for generic_args in kwargs_helper(kwargs):
        args.append('--%s=%s' % generic_args)

    p = run_zenity('--file-selection', *args)

    if p.wait() == 0:
        return p.stdout.read().strip().split('|')
项目:dotfiles    作者:leolanavo    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:leolanavo    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:francoiscote    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:francoiscote    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:bryanbecker    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:bryanbecker    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:RustyHook    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:RustyHook    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:wrfxpy    作者:openwfm    | 项目源码 | 文件源码
def symlink_unless_exists(link_tgt, link_loc):
    """
    Create a symlink at link_loc pointing to link_tgt unless file already exists.

    :param link_tgt: link target
    :param link_loc: link location
    """
    if not osp.lexists(link_loc):
        os.symlink(link_tgt, link_loc)
项目:ansible-provider-docs    作者:alibaba    | 项目源码 | 文件源码
def tests(self):
        return {
            # file testing
            'is_dir': isdir,
            'is_file': isfile,
            'is_link': islink,
            'exists': exists,
            'link_exists': lexists,

            # path testing
            'is_abs': isabs,
            'is_same_file': samefile,
            'is_mount': ismount,
        }
项目:dotfiles    作者:randomn4me    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:randomn4me    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:AlphaGSM    作者:SectorAlpha    | 项目源码 | 文件源码
def ensureabsent(path):
    """ If path exists remove it whether it's a file or a folder """
    if exists(path):
        if israwdir(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
项目:AlphaGSM    作者:SectorAlpha    | 项目源码 | 文件源码
def removeuneeded(old,target,rel,entry,skip):
    """ Remove an entry that isn't needed by new if it's from old 

            If there where any issues this returns True otherwise it returns False.
            """
    oldentry=joinpath(old,entry)
    targetentry=joinpath(target,entry)
    relentry=joinpath(rel,entry)
    matchentry=relentry
    if israwdir(targetentry):
        matchentry+="/"
    # only remove if was from old entries. Leave anything else behind (assume it was created by the game)
    # things in skip are treated as if not in old or new even if they actually are
    if exists(oldentry) and not matchespatterns(matchentry,skip):
        # old and target but no new so remove or if changed append .~local, 
        if israwdir(targetentry):
            if isdir(old):
                # target and old dirs but no new so need to recurse
                if checkandcleartrees(relentry,targetentry,oldentry,skip):
                    # target and old both dirs and target now empty
                    os.rmdir(targetentry)
                else:
                    print("WARNING: directory {0} from old isn't wanted in new but some files weren't removed".format(targetentry))
                    return True
            else:
                # target is dir but old isn't
                ensureabsent(targetentry+LOCALSUFFIX)
                os.rename(targetentry,targetentry+LOCALSUFFIX)
                print("WARNING: file from old version is folder in local but isn't wanted in new.\nRenamed to '{0}".format(targetentry+LOCALSUFFIX))
                return True
        elif islink(targetentry) or checkfiles(targetentry,oldentry):
            # link or unchanged file
            os.remove(targetentry)
        else:
            # not dir and not link and changed so rename
            ensureabsent(targetentry+LOCALSUFFIX)
            os.rename(targetentry,targetentry+LOCALSUFFIX)
            print("WARNING: File from old version has been changed in local but isn't wanted in new.\nRenamed to '{0}".format(targetentry+LOCALSUFFIX))
            return True
    return False
项目:dotfiles    作者:ildyria    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists
        from os import makedirs

        dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(dirname):
            makedirs(dirname)
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:dotfiles    作者:ildyria    | 项目源码 | 文件源码
def execute(self):
        from os.path import join, expanduser, lexists

        fname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
        if not lexists(fname):
            open(fname, 'a').close()
        else:
            self.fm.notify("file/directory exists!", bad=True)
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def tests(self):
        return {
            # file testing
            'is_dir'  : isdir,
            'is_file' : isfile,
            'is_link' : islink,
            'exists' : exists,
            'link_exists' : lexists,

            # path testing
            'is_abs' : isabs,
            'is_same_file' : samefile,
            'is_mount' : ismount,
        }
项目:niceman    作者:ReproNim    | 项目源码 | 文件源码
def _resolve_file(self, path):
        """Given a path, return path of the repository it belongs to"""
        # very naive just to get a ball rolling
        if not isabs(path):
            raise ValueError("ATM operating on full paths, got %s" % path)
        dirpath = path if isdir(path) else dirname(path)

        # quick check first
        if dirpath in self._known_repos:
            return self._known_repos[dirpath]

        # it could still be a subdirectory known to the repository known above it
        for repo in self._known_repos.values():
            # XXX this design is nohow accounts for some fancy cases where
            # someone could use GIT_TREE and other trickery to have out of the
            # directory checkout.  May be some time we would get there but
            # for now
            # should be ok

            # could be less efficient than some str manipulations but ok for now
            if os.path.commonprefix((repo.path, path)) != repo.path:
                continue

            # could be less efficient than some str manipulations but ok for now
            # since we rely on a strict check (must be registered within the repo)
            if repo.owns_path(path):
                return repo

        # ok -- if it is not among known repos, we need to 'sniff' around
        # if there is a repository at that path
        for Shim in self.SHIMS:
            lgr.log(5, "Trying %s for path %s", Shim, path)
            shim = Shim.get_at_dirpath(self._session, dirpath) \
                if lexists(dirpath) else None
            if shim:
                # so there is one nearby -- record it
                self._known_repos[shim.path] = shim
                # but it might still not to know about the file
                if shim.owns_path(path):
                    return shim
                # if not -- just keep going to the next candidate repository
        return None