Python os.path.lexists() Examples
The following are 6
code examples of os.path.lexists().
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: populate-browser-history.py From promnesia with MIT License | 6 votes |
def merge(merged: Path, chunk: Path): logger = get_logger() logger.info(f"Merging {chunk} into {merged}") if lexists(merged): logger.info("DB size before: %s items %d bytes", entries(merged), merged.stat().st_size) else: logger.info(f"DB doesn't exist yet: {merged}") candidates = [] for ff in [chrome, firefox, firefox_phone]: res = sqlite(chunk, f"SELECT * FROM {ff.detector}", method=subprocess.run, stdout=DEVNULL, stderr=DEVNULL) if res.returncode == 0: candidates.append(ff) assert len(candidates) == 1 merger = candidates[0] merge_browser(merged=merged, chunk=chunk, schema=merger.schema, schema_check=merger.schema_check, query=merger.query) logger.info("DB size after : %s items %d bytes", entries(merged), merged.stat().st_size)
Example #2
Source File: pundle.py From pundler with BSD 2-Clause "Simplified" License | 5 votes |
def fixate(): "puts activation code to usercustomize.py for user" print_message('Fixate') import site userdir = site.getusersitepackages() if not userdir: raise PundleException('Can`t fixate due user have not site package directory') try: makedirs(userdir) except OSError: pass template = FIXATE_TEMPLATE.replace('op.dirname(__file__)', "'%s'" % op.abspath(op.dirname(__file__))) usercustomize_file = op.join(userdir, 'usercustomize.py') print_message('Will edit %s file' % usercustomize_file) if op.exists(usercustomize_file): content = open(usercustomize_file).read() if '# pundle user customization start' in content: regex = re.compile(r'\n# pundle user customization start.*# pundle user customization end\n', re.DOTALL) content, res = regex.subn(template, content) open(usercustomize_file, 'w').write(content) else: open(usercustomize_file, 'a').write(content) else: open(usercustomize_file, 'w').write(template) link_file = op.join(userdir, 'pundle.py') if op.lexists(link_file): print_message('Remove exist link to pundle') os.unlink(link_file) print_message('Create link to pundle %s' % link_file) os.symlink(op.abspath(__file__), link_file) print_message('Complete')
Example #3
Source File: PathLib.py From PyFlow with Apache License 2.0 | 5 votes |
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 #4
Source File: __init__.py From pylada-light with GNU General Public License v3.0 | 5 votes |
def prep_symlink(outdir, workdir, filename=None): """ Creates a symlink between outdir and workdir. If outdir and workdir are the same directory, then bails out. Both directories should exist prior to call. If filename is None, then creates a symlink to workdir in outdir called ``workdir``. Otherwise, creates a symlink in workdir called filename. If a link ``filename`` already exists, deletes it first. """ from os import remove, symlink from os.path import samefile, lexists, abspath, join from ..misc import chdir if samefile(outdir, workdir): return if filename is None: with chdir(workdir): if lexists('workdir'): try: remove('workdir') except OSError: pass try: symlink(abspath(workdir), abspath(join(outdir, 'workdir'))) except OSError: pass return with chdir(workdir): if lexists(filename): try: remove(filename) except OSError: pass try: symlink(abspath(join(outdir, filename)), abspath(join(workdir, filename))) except OSError: pass
Example #5
Source File: indexer_test.py From promnesia with MIT License | 5 votes |
def _test_merge_all_from(tdir): merge_all_from = backup_db.merge_all_from # type: ignore mdir = join(tdir, 'merged') mkdir(mdir) mfile = join(mdir, 'merged.sql') get_chrome_history_backup(tdir) merge_all_from(mfile, join(tdir, 'backup'), None) first = join(tdir, "backup/20180415/History") second = join(tdir, "backup/20180417/History") # should be removed assert not lexists(first) assert not lexists(second) import promnesia.sources.chrome as chrome_ex hist = history(W(chrome_ex.extract, mfile)) assert len(hist) > 0 older = hist['github.com/orgzly/orgzly-android/issues'] assert any(v.dt.date() < date(year=2018, month=1, day=17) for v in older) # in particular, "2018-01-16 19:56:56" newer = hist['en.wikipedia.org/wiki/Notice_and_take_down'] assert any(v.dt.date() >= date(year=2018, month=4, day=16) for v in newer) # from implicit db newest = hist['feedly.com/i/discover'] assert any(v.dt.date() >= date(year=2018, month=9, day=27) for v in newest)
Example #6
Source File: cli.py From pdoc with GNU Affero General Public License v3.0 | 5 votes |
def _quit_if_exists(m: pdoc.Module, ext: str): if args.force: return paths = [module_path(m, ext)] if m.is_package: # If package, make sure the dir doesn't exist either paths.append(path.dirname(paths[0])) for pth in paths: if path.lexists(pth): print("File '%s' already exists. Delete it, or run with --force" % pth, file=sys.stderr) sys.exit(1)