Python os.path.lexists() Examples

The following are code examples for showing how to use os.path.lexists(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: wrfxpy   Author: openwfm   File: utils.py    MIT License 6 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
    """

    logging.info('Linking %s -> %s' % (link_loc, link_tgt))
    if osp.isfile(link_tgt):
        if not osp.lexists(link_loc):
            os.symlink(link_tgt, link_loc)
        else:
            logging.warning('Link %s already exists' % link_loc)
    else:
        logging.error('Link target %s does not exist' % link_tgt) 
Example 2
Project: MyDotfiles   Author: Sup3r-Us3r   File: commands_full.py    GNU General Public License v3.0 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 3
Project: MyDotfiles   Author: Sup3r-Us3r   File: commands_full.py    GNU General Public License v3.0 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 4
Project: DotFiles   Author: LoneWolf38   File: commands_full.py    GNU General Public License v3.0 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 5
Project: DotFiles   Author: LoneWolf38   File: commands_full.py    GNU General Public License v3.0 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 6
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    GNU General Public License v3.0 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 7
Project: arch-setup-i3wm   Author: i-PUSH   File: commands_full.py    GNU General Public License v3.0 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 8
Project: dotfiles   Author: taigacute   File: commands_full.py    MIT License 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 9
Project: dotfiles   Author: taigacute   File: commands_full.py    MIT License 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 10
Project: PyFlow   Author: wonderworks-software   File: PathLib.py    Apache License 2.0 5 votes vote down vote up
def lexists(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"})):
        '''Return True if path refers to an existing path. Returns True for broken symbolic links. Equivalent to exists() on platforms lacking os.lstat().'''
        return osPath.lexists(path) 
Example 11
Project: AiDevOps   Author: Moniter123   File: files.py    GNU General Public License v2.0 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 12
Project: dotFiles   Author: auteiy   File: commands_full.py    MIT License 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 13
Project: dotFiles   Author: auteiy   File: commands_full.py    MIT License 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 14
Project: dotfiles   Author: foo-dogsquared   File: commands_full.py    MIT License 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 15
Project: dotfiles   Author: foo-dogsquared   File: commands_full.py    MIT License 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 16
Project: orger   Author: karlicoss   File: atomic_append.py    MIT License 5 votes vote down vote up
def assert_not_edited(path: Path):
    vim = '.' + path.name + '.swp'
    emacs = '.#' + path.name
    for x in [vim, emacs]:
        lf = path.parent / x
        if lexists(lf): # lexist is necessary because emacs uses symlink for lock file
            raise RuntimeError('File is being edited: {}'.format(lf)) 
Example 17
Project: mri_segmentation   Author: spencerimp   File: fslinstaller.py    Apache License 2.0 4 votes vote down vote up
def slash_applications_links(self):
        '''Create symlinks to FSLView (and qassistant) in /Applications'''
        from os import path

        MsgUser.message("Creating Application links...")
        results = {}
        apps = ['fslview.app', 'assistant.app' ]
        for app in apps:
            app_location = '/'.join(('/Applications', app))
            app_target = '/'.join((self.location, 'fsl', 'bin', app))
            create_link = False
            MsgUser.debug("Looking for existing link %s" % (app_location) )
            if path.lexists( app_location ):
                MsgUser.debug("Is a link: %s; realpath: %s" % (path.islink(app_location), path.realpath(app_location)))
                if path.islink( app_location ):
                    MsgUser.debug("A link already exists.")
                    if path.realpath( app_location ) != app_target:
                        MsgUser.debug("Deleting old (incorrect) link %s" % (app_location))
                        result = run_cmd("rm " + app_location, as_root=self.sudo)
                        if result.status == FslIResult.SUCCESS:
                            create_link = True
                        else:
                            MsgUser.debug("Unable to remove broken link to %s (%s)." % (app_target, result.message))
                            results[app] = FslIResult(False, FslIResult.WARN, 'Unable to remove broken link to %s' % (app_target))
                    else:
                        MsgUser.debug("Link is correct, skipping.")
                else:
                    MsgUser.debug("%s doesn't look like a symlink, so let's not delete it." % (app_location))
                    results[app] = FslIResult(False, FslIResult.WARN, "%s is not a link, I won't delete it. You" % (app_location))
            else:
                MsgUser.debug('Create a link for %s' % (app))
                create_link = True
            MsgUser.debug('Looking for %s (create_link is %s)' %(app_target, create_link))
            if create_link:
                if path.exists( app_target ):
                    result = run_cmd("ln -s %s %s" % (app_target, app_location ), as_root=self.sudo)
                    if result.status != FslIResult.SUCCESS:
                        MsgUser.debug("Unable to create link to %s (%s)" % (app_target, result.message))
                        results[app] = FslIResult(False, FslIResult.WARN, 'Unable to remove broken link to %s' % (app_target))
                else:
                    results[app] = FslIResult(False, FslIResult.WARN, 'Unable to find application %s to link to' % (app_target))
            else:
                results[app] = FslIResult(True, FslIResult.WARN, "Application %s already linked." % (app))
        return results