Python os.path.lexists() Examples

The following are code examples for showing how to use os.path.lexists(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: myDotFiles   Author: GuidoFe   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 2
Project: myDotFiles   Author: GuidoFe   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 3
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 4
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 5
Project: pbtranscript   Author: PacificBiosciences   File: Utils.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 6
Project: pbtranscript   Author: PacificBiosciences   File: Utils.py    (license) View Source Project 5 votes vote down vote up
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)) 
Example 7
Project: dotfiles   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 8
Project: dotfiles   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 9
Project: my-dots   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 10
Project: my-dots   Author: maotora   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 11
Project: dotfiles   Author: quanttyo   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 12
Project: dotfiles   Author: quanttyo   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 13
Project: dotfiles   Author: bookletchoir   File: commands.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 14
Project: dotfiles   Author: bookletchoir   File: commands.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 15
Project: sixense   Author: a0726h77   File: PyZenity.py    (license) View Source Project 5 votes vote down vote up
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('|') 
Example 16
Project: sixense   Author: a0726h77   File: PyZenity.py    (license) View Source Project 5 votes vote down vote up
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('|') 
Example 17
Project: dotfiles   Author: leolanavo   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 18
Project: dotfiles   Author: leolanavo   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 19
Project: dotfiles   Author: francoiscote   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 20
Project: dotfiles   Author: francoiscote   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 21
Project: dotfiles   Author: bryanbecker   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 22
Project: dotfiles   Author: bryanbecker   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 23
Project: dotfiles   Author: RustyHook   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 24
Project: dotfiles   Author: RustyHook   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 25
Project: wrfxpy   Author: openwfm   File: utils.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 26
Project: ansible-provider-docs   Author: alibaba   File: files.py    (license) View Source Project 5 votes vote down vote up
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,
        } 
Example 27
Project: dotfiles   Author: randomn4me   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 28
Project: dotfiles   Author: randomn4me   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 29
Project: AlphaGSM   Author: SectorAlpha   File: updatefs.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 30
Project: AlphaGSM   Author: SectorAlpha   File: updatefs.py    (license) View Source Project 5 votes vote down vote up
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 
Example 31
Project: dotfiles   Author: ildyria   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 32
Project: dotfiles   Author: ildyria   File: commands_full.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 33
Project: DevOps   Author: YoLoveLife   File: files.py    (license) View Source Project 4 votes vote down vote up
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,
        } 
Example 34
Project: niceman   Author: ReproNim   File: vcs.py    (license) View Source Project 4 votes vote down vote up
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