Python os.path.islink() Examples
The following are 30
code examples of os.path.islink().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os.path
, or try the search function
.
Example #1
Source File: fun.py From bazarr with GNU General Public License v3.0 | 6 votes |
def is_git_dir(d): """ This is taken from the git setup.c:is_git_directory function. @throws WorkTreeRepositoryUnsupported if it sees a worktree directory. It's quite hacky to do that here, but at least clearly indicates that we don't support it. There is the unlikely danger to throw if we see directories which just look like a worktree dir, but are none.""" if osp.isdir(d): if osp.isdir(osp.join(d, 'objects')) and osp.isdir(osp.join(d, 'refs')): headref = osp.join(d, 'HEAD') return osp.isfile(headref) or \ (osp.islink(headref) and os.readlink(headref).startswith('refs')) elif (osp.isfile(osp.join(d, 'gitdir')) and osp.isfile(osp.join(d, 'commondir')) and osp.isfile(osp.join(d, 'gitfile'))): raise WorkTreeRepositoryUnsupported(d) return False
Example #2
Source File: fileutils.py From clonedigger with GNU General Public License v3.0 | 6 votes |
def remove_dead_links(directory, verbose=0): """recursivly traverse directory and remove all dead links :type directory: str :param directory: directory to cleanup :type verbose: bool :param verbose: flag indicating wether information about deleted links should be printed to stderr, default to False """ def _remove_dead_link(_, directory, fnames): """walk handler""" for filename in fnames: src = join(directory, filename) if islink(src) and not exists(src): if verbose: print('remove dead link', src) remove(src) walk(directory, _remove_dead_link, None)
Example #3
Source File: ApplicationParser.py From nfi with GNU General Public License v3.0 | 6 votes |
def scan_single_app(self, approot_path, app): #print "[APP]: " + app.get_packagename() if self.outqueue != None: self.outqueue.put("[APP]: " + app.get_packagename()) store_app = self.exstore.create_application( app.get_packagename(), app.get_canonicalname()) rootdir = store_app.add_directory(approot_path) store_app.add_root_stats( os.stat(approot_path) ) for f in listdir(approot_path): filepath = join(approot_path,f) if isdir(filepath): dirobject = rootdir.add_dir(f) self.scan_single_app_dir(filepath, app, dirobject, store_app) elif islink(filepath): if filepath.endswith("lib"): store_app.set_library_path(self.read_link(filepath)) elif isfile(filepath): store_app.totalfiles += 1 rootdir.add_file(self.handle_file(f,approot_path,app)) return
Example #4
Source File: ApplicationParser.py From nfi with GNU General Public License v3.0 | 6 votes |
def scan_single_app_dir(self, dirroot, app, dirobject, store_app): for f in listdir(dirroot): filepath = join(dirroot,f) if isdir(filepath): subdirobject = dirobject.add_dir(f) self.scan_single_app_dir(filepath, app, subdirobject, store_app) elif islink(filepath): """Skip for now""" continue elif isfile(filepath): try: dirobject.add_file(self.handle_file(f, dirroot, app)) store_app.totalfiles += 1 except: print("Error handling file %(fname)s" % {'fname': join(dirroot,f)}) return
Example #5
Source File: helper.py From macke with Apache License 2.0 | 6 votes |
def get_fuzz_outdirs(macke_directory): fuzzdir = path.join(macke_directory, "fuzzer") if not path.isdir(path.join(macke_directory, "fuzzer")): return [] result = [] prefix = "fuzz_out_" for f in listdir(fuzzdir): if not f.startswith(prefix): continue fpath = path.join(fuzzdir, f) function = f[len(prefix):] if path.islink(fpath) or not path.isdir(fpath): continue result.append((function, fpath)) return result
Example #6
Source File: _thesis_helpers.py From ibeis with Apache License 2.0 | 6 votes |
def __init__(self, dbname=None): self.ibs = None self.expt_results = {} if isdir(dbname) or islink(dbname): dpath = abspath(dbname) else: dpath = None self.dbname = dbname self.dname = None self.dpath = dpath self.species_nice = dbname_to_species_nice(dbname) if self.dpath is None and dbname is not None: self.dname = self.dbname link_dname = ut.get_argval('--link', default='link') self.dpath = join(self.base_dpath, link_dname, self.dname)
Example #7
Source File: __init__.py From fbs with GNU General Public License v3.0 | 6 votes |
def clean(): """ Remove previous build outputs """ try: rmtree(path('target')) except FileNotFoundError: return except OSError: # In a docker container, target/ may be mounted so we can't delete it. # Delete its contents instead: for f in listdir(path('target')): fpath = join(path('target'), f) if isdir(fpath): rmtree(fpath, ignore_errors=True) elif isfile(fpath): remove(fpath) elif islink(fpath): unlink(fpath)
Example #8
Source File: plat_other.py From pipeline with MIT License | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, str(uid)) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #9
Source File: linux_network.py From igcollect with MIT License | 6 votes |
def get_interfaces(self): for dev in listdir(self._scn): dev_path = join(self._scn, dev) if not (islink(dev_path) or isdir(dev_path)): # Skip regular files continue if not self.included_types: # Send metrics for all devices self.netdev_stat[dev] = {} continue for i_type in self.included_types: checks = self.NET_TYPES[i_type] results = [] for check, arg in zip(checks[::2], checks[1::2]): results.append(check(self, dev, arg)) if False not in results: self.netdev_stat[dev] = {}
Example #10
Source File: setup.py From pyrqlite with MIT License | 6 votes |
def run(self): testpath = 'src/test' buildlink = 'build/lib/test' if isdir(dirname(buildlink)): if islink(buildlink): os.unlink(buildlink) os.symlink(relpath(testpath, dirname(buildlink)), buildlink) testpath = buildlink try: os.environ['EPYTHON'] = 'python{}.{}'.format(sys.version_info.major, sys.version_info.minor) subprocess.check_call(['py.test', '-v', testpath, '-s', '--cov-report=html', '--cov-report=term-missing'] + (['-k', self.match] if self.match else []) + ['--cov={}'.format(p) for p in find_packages(dirname(testpath), exclude=['test'])]) finally: if islink(buildlink): os.unlink(buildlink)
Example #11
Source File: install.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _link(src, dst, linktype=LINK_HARD): if linktype == LINK_HARD: if on_win: win_hard_link(src, dst) else: os.link(src, dst) elif linktype == LINK_SOFT: if on_win: win_soft_link(src, dst) else: os.symlink(src, dst) elif linktype == LINK_COPY: # copy relative symlinks as symlinks if not on_win and islink(src) and not os.readlink(src).startswith('/'): os.symlink(os.readlink(src), dst) else: shutil.copy2(src, dst) else: raise Exception("Did not expect linktype=%r" % linktype)
Example #12
Source File: repo.py From walle-web with Apache License 2.0 | 6 votes |
def is_git_dir(self): ''' 判断是否为git目录 @param path: @return: ''' d = self.path + '/.git' if osp.isdir(d): if osp.isdir(osp.join(d, 'objects')) and osp.isdir(osp.join(d, 'refs')): headref = osp.join(d, 'HEAD') return osp.isfile(headref) or \ (osp.islink(headref) and os.readlink(headref).startswith('refs')) elif (osp.isfile(osp.join(d, 'gitdir')) and osp.isfile(osp.join(d, 'commondir')) and osp.isfile(osp.join(d, 'gitfile'))): return False return False
Example #13
Source File: create.py From cloudify-manager-blueprints with Apache License 2.0 | 6 votes |
def _configure_dbus(rest_venv): # link dbus-python-1.1.1-9.el7.x86_64 to the venv for `cfy status` # (module in pypi is very old) site_packages = 'lib64/python2.7/site-packages' dbus_relative_path = join(site_packages, 'dbus') dbuslib = join('/usr', dbus_relative_path) dbus_glib_bindings = join('/usr', site_packages, '_dbus_glib_bindings.so') dbus_bindings = join('/usr', site_packages, '_dbus_bindings.so') if isdir(dbuslib): dbus_venv_path = join(rest_venv, dbus_relative_path) if not islink(dbus_venv_path): utils.ln(source=dbuslib, target=dbus_venv_path, params='-sf') utils.ln(source=dbus_bindings, target=dbus_venv_path, params='-sf') if not islink(join(rest_venv, site_packages)): utils.ln(source=dbus_glib_bindings, target=join( rest_venv, site_packages), params='-sf') else: ctx.logger.warn( 'Could not find dbus install, cfy status will not work')
Example #14
Source File: plat_other.py From FileManager with MIT License | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, text_type(uid).encode('ascii')) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #15
Source File: plat_other.py From Snu-Photo-Manager with GNU Lesser General Public License v3.0 | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, text_type(uid).encode('ascii')) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #16
Source File: helper.py From macke with Apache License 2.0 | 5 votes |
def append_to_registry_from_fuzzdir(registry, macke_directory): for (function, fpath) in get_fuzz_outdirs(macke_directory): errordir = path.join(fpath, "macke_errors") # sanity check if path.islink(errordir) or not path.isdir(errordir): continue registry.create_from_dir(errordir, function)
Example #17
Source File: setup.py From detectron2 with Apache License 2.0 | 5 votes |
def get_model_zoo_configs() -> List[str]: """ Return a list of configs to include in package for model zoo. Copy over these configs inside detectron2/model_zoo. """ # Use absolute paths while symlinking. source_configs_dir = path.join(path.dirname(path.realpath(__file__)), "configs") destination = path.join( path.dirname(path.realpath(__file__)), "detectron2", "model_zoo", "configs" ) # Symlink the config directory inside package to have a cleaner pip install. # Remove stale symlink/directory from a previous build. if path.exists(source_configs_dir): if path.islink(destination): os.unlink(destination) elif path.isdir(destination): shutil.rmtree(destination) if not path.exists(destination): try: os.symlink(source_configs_dir, destination) except OSError: # Fall back to copying if symlink fails: ex. on Windows. shutil.copytree(source_configs_dir, destination) config_paths = glob.glob("configs/**/*.yaml", recursive=True) return config_paths
Example #18
Source File: filepath.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def islink(path): return False
Example #19
Source File: bundle.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def add_file(t, path, f): t.add(path, f) if islink(path): link = os.readlink(path) if link.startswith('/'): warn.append('found symlink to absolute path: %s -> %s' % (f, link)) elif isfile(path): if path.endswith('.egg-link'): warn.append('found egg link: %s' % f)
Example #20
Source File: filepath.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def islink(self): st = self.statinfo if not st: self.restat(False) st = self.statinfo if not st: return False return S_ISLNK(st[ST_MODE])
Example #21
Source File: PathLib.py From PyFlow with Apache License 2.0 | 5 votes |
def isDir(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"})): '''Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.''' return osPath.isdir(path)
Example #22
Source File: utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def create_evokeds_links(subject, windows): fol = utils.make_dir(op.join(MMVT_DIR, subject, 'evokes')) for window_fname in windows: new_window_fname = op.join(fol, utils.namebase_with_ext(window_fname)) if op.isfile(new_window_fname) or op.islink(new_window_fname): continue utils.make_link(window_fname, new_window_fname)
Example #23
Source File: utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def is_link(link_path): if is_windows(): try: from src.mmvt_addon.scripts import windows_utils as wu sc = wu.MSShortcut('{}.lnk'.format(link_path)) real_folder_path = op.join(sc.localBasePath, sc.commonPathSuffix) return op.isdir(real_folder_path) except: return False else: return op.islink(link_path)
Example #24
Source File: setup_utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def is_link(link_path): if is_windows(): link_fname = link_path if link_path[-4:] == '.lnk' else '{}.lnk'.format(link_path) if not op.isfile(link_fname): return False try: from src.mmvt_addon.scripts import windows_utils as wu sc = wu.MSShortcut(link_fname) real_folder_path = op.join(sc.localBasePath, sc.commonPathSuffix) return op.isdir(real_folder_path) except: # print(traceback.format_exc()) return False else: return op.islink(link_path)
Example #25
Source File: setup_utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def create_folder_link(real_fol, link_fol, overwrite=True): ret = False if not overwrite and is_link(link_fol): print('The link {} is already exist'.format(link_fol)) ret = True else: if is_windows(): try: if not op.isdir(real_fol): print('The target is not a directory!!') return import winshell from win32com.client import Dispatch path = '{}.lnk'.format(link_fol) shell = Dispatch('WScript.Shell') shortcut = shell.CreateShortCut(path) shortcut.Targetpath = real_fol shortcut.save() ret = True except: print("Can't create a link to the folder {}!".format(real_fol)) ret = False else: if overwrite and op.islink(link_fol): os.remove(link_fol) try: os.symlink(real_fol, link_fol) ret = op.islink(link_fol) except: print('Problem with creating {} link to {}'.format(link_fol, real_fol)) ret = False return ret
Example #26
Source File: hnn_panel.py From mmvt with GNU General Public License v3.0 | 5 votes |
def set_hnn_folder(self, context): hnn_folder = op.abspath(bpy.path.abspath(bpy.context.scene.hnn_folder)) if not op.isdir(hnn_folder): return hnn_link = op.join(mu.get_links_dir(), 'hnn') if op.islink(hnn_link): os.remove(hnn_link) try: os.symlink(hnn_folder, hnn_link) except: print('set_hnn_folder: Error in creating hnn link!') init_hnn_files()
Example #27
Source File: mmvt_utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def make_dir(fol): try: if not op.isdir(fol) and not op.islink(fol): os.makedirs(fol) except: pass if not op.isdir(fol): print('!!! Error! {} was not created !!!'.format(fol)) return fol
Example #28
Source File: mmvt_utils.py From mmvt with GNU General Public License v3.0 | 5 votes |
def copy_file(src, dst): if src != dst: if op.islink(dst): dst = os.readlink(dst) elif op.islink(get_parent_fol(dst)): fol = os.readlink(get_parent_fol(dst)) dst = op.join(fol, namebase_with_ext(dst)) try: if src != dst: shutil.copyfile(src, dst) except: print_last_error_line()
Example #29
Source File: linux_network.py From igcollect with MIT License | 5 votes |
def _check_symlink(self, dev, symlink): return islink(join(self._scn, dev, symlink))
Example #30
Source File: local.py From py with MIT License | 5 votes |
def islink(self): st = self.path.lstat() return S_ISLNK(self._osstatresult.st_mode)