本文整理汇总了Python中util.unlink函数的典型用法代码示例。如果您正苦于以下问题:Python unlink函数的具体用法?Python unlink怎么用?Python unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testlock
def testlock(self):
"""return id of locker if lock is valid, else None.
If old-style lock, we cannot tell what machine locker is on.
with new-style lock, if locker is on this machine, we can
see if locker is alive. If locker is on this machine but
not alive, we can safely break lock.
The lock file is only deleted when None is returned.
"""
locker = util.readlock(self.f)
try:
host, pid = locker.split(":", 1)
except ValueError:
return locker
if host != lock._host:
return locker
try:
pid = int(pid)
except ValueError:
return locker
if util.testpid(pid):
return locker
# if locker dead, break lock. must do this with another lock
# held, or can race and break valid lock.
try:
l = lock(self.f + '.break', timeout=0)
util.unlink(self.f)
l.release()
except error.LockError:
return locker
示例2: upgrade
def upgrade(self, version, force = False):
if not mkdir(self.path):
return version
if self.updater == "bukkitdev":
uver, urlh = self.__bukkitdev_info()
elif self.updater == "bukkitdl":
uver, urlh = self.__bukkitdl_info()
elif self.updater == "github":
uver, urlh = self.__github_info()
elif self.updater == "jenkins":
uver, urlh = self.__jenkins_info()
else:
log.error("%s: package upgrade failed: invalid updater `%s'",
self.package, self.updater)
return version
if not urlh:
log.error("%s: package upgrade failed", self.package)
return version
out = os.path.join(self.path, "%s.%s" % (self.package, self.type))
if uver and uver == version and not force:
log.info("%s: package already up-to-date", self.package)
return version
if not self.dryrun and not download(urlh, out):
return version
log.info("%s: package upgraded: %s -> %s", self.package, version, uver)
if self.dryrun or (self.type != "zip"):
return uver
if len(self.extract) < 1:
return uver
zf = ZipFile(out, "r")
nl = zf.namelist()
for path in self.extract:
if not path.endswith("/") and path in nl:
zf.extract(path, self.path)
continue
for zpath in nl:
if zpath.endswith("/"):
continue
if not zpath.startswith(path):
continue
zf.extract(zpath, self.path)
zf.close()
unlink(out)
return uver
示例3: kill
def kill(server):
log.info("%s: fake server stopping...", server)
pidfile = FakeServer.pidfile(server)
fp = util.fopen(pidfile, "r")
if not fp:
return False
try:
pid = int(fp.read())
except:
pid = 0
fp.close()
util.unlink(pidfile)
if not pid:
return False
try:
os.kill(pid, SIGINT)
except Exception, msg:
log.error("Failed to kill process (%d): %s", pid, msg)
return False
示例4: link
def link(self, args):
"""
Actually deploy the configuration by linking the correct spot to the original file.
@param args: The parsed arguments from the command-line.
"""
if args.dry:
print(str(self.source) + " -> " + str(self.destination))
return
if not self.src_exists:
return
if self.dst_exists_before:
if args.replace:
if self.dst_is_link_before:
util.unlink(self.destination)
elif self.dst_is_file_before:
util.remove(self.destination)
elif self.dst_is_dir_before:
util.remove_dir(self.destination)
else:
#SUS should never get here.
raise Exception("WTF is this shit")
else:
# File already exists and isn't going to be replaced.
return
else:
#This is some weird nonsense conserning broken links
if self.dst_is_link_before:
util.unlink(self.destination)
if args.copy:
util.copy(self.source, self.destination)
else:
util.link(self.source, self.destination)
示例5: remove
def remove(self, list, unlink=False):
if unlink:
for f in list:
try:
util.unlink(self._repo.wjoin(f))
except OSError, inst:
if inst.errno != errno.ENOENT:
raise
示例6: applyupdates
def applyupdates(repo, action, wctx, mctx):
"apply the merge action list to the working directory"
updated, merged, removed, unresolved = 0, 0, 0, 0
ms = mergestate(repo)
ms.reset(wctx.parents()[0].node())
moves = []
action.sort(actioncmp)
# prescan for merges
for a in action:
f, m = a[:2]
if m == 'm': # merge
f2, fd, flags, move = a[2:]
repo.ui.debug(_("preserving %s for resolve of %s\n") % (f, fd))
fcl = wctx[f]
fco = mctx[f2]
fca = fcl.ancestor(fco) or repo.filectx(f, fileid=nullrev)
ms.add(fcl, fco, fca, fd, flags)
if f != fd and move:
moves.append(f)
# remove renamed files after safely stored
for f in moves:
if util.lexists(repo.wjoin(f)):
repo.ui.debug(_("removing %s\n") % f)
os.unlink(repo.wjoin(f))
audit_path = util.path_auditor(repo.root)
for a in action:
f, m = a[:2]
if f and f[0] == "/":
continue
if m == "r": # remove
repo.ui.note(_("removing %s\n") % f)
audit_path(f)
try:
util.unlink(repo.wjoin(f))
except OSError, inst:
if inst.errno != errno.ENOENT:
repo.ui.warn(_("update failed to remove %s: %s!\n") %
(f, inst.strerror))
removed += 1
elif m == "m": # merge
f2, fd, flags, move = a[2:]
r = ms.resolve(fd, wctx, mctx)
if r > 0:
unresolved += 1
else:
if r is None:
updated += 1
else:
merged += 1
util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags)
if f != fd and move and util.lexists(repo.wjoin(f)):
repo.ui.debug(_("removing %s\n") % f)
os.unlink(repo.wjoin(f))
示例7: test_raise_exceptions
def test_raise_exceptions(self):
"""Test that exceptions raised by a task are propagated"""
m = util.Manager()
m.add_slave(IMP.parallel.LocalSlave())
c = m.get_context()
c.add_task(tasks.error_task)
self.assertRaises(IMP.parallel.RemoteError, list,
c.get_results_unordered())
util.unlink("slave0.output")
示例8: test_pass_exceptions
def test_pass_exceptions(self):
"""Test that exceptions can be passed to and from tasks"""
m = util.Manager()
m.add_slave(IMP.parallel.LocalSlave())
c = m.get_context()
c.add_task(tasks.SimpleTask(IndexError("test")))
results = list(c.get_results_unordered())
self.assertIsInstance(results[0], IndexError)
util.unlink("slave0.output")
示例9: test_startup
def test_startup(self):
"""Test context startup callable"""
m = util.Manager(output='startup%d.out')
m.add_slave(IMP.parallel.LocalSlave())
c = m.get_context(startup=tasks.SimpleTask(("foo", "bar")))
c.add_task(tasks.simple_func)
c.add_task(tasks.simple_func)
results = list(c.get_results_unordered())
self.assertEqual(results, [('foo', 'bar'), ('foo', 'bar')])
util.unlink("startup0.out")
示例10: release
def release(self):
if self.held > 1:
self.held -= 1
elif self.held == 1:
self.held = 0
if self.releasefn:
self.releasefn()
try:
util.unlink(self.f)
except OSError:
pass
示例11: test_simple
def test_simple(self):
"""Test that slave tasks can start up and communicate"""
m = util.Manager(output='simple%d.out')
m.add_slave(IMP.parallel.LocalSlave())
c = m.get_context()
for i in range(10):
c.add_task(tasks.SimpleTask(i))
results = list(c.get_results_unordered())
results.sort()
self.assertEqual(results, list(range(10)))
util.unlink("simple0.out")
示例12: close
def close(self):
'''commit the transaction'''
self.count -= 1
if self.count != 0:
return
self.file.close()
self.entries = []
if self.after:
self.after()
if os.path.isfile(self.journal):
util.unlink(self.journal)
self.journal = None
示例13: __call__
def __call__(self, path, mode="r", text=False, atomictemp=False,
notindexed=False):
'''Open ``path`` file, which is relative to vfs root.
Newly created directories are marked as "not to be indexed by
the content indexing service", if ``notindexed`` is specified
for "write" mode access.
'''
if self._audit:
r = util.checkosfilename(path)
if r:
raise util.Abort("%s: %r" % (r, path))
self.audit(path)
f = self.join(path)
if not text and "b" not in mode:
mode += "b" # for that other OS
nlink = -1
if mode not in ('r', 'rb'):
dirname, basename = util.split(f)
# If basename is empty, then the path is malformed because it points
# to a directory. Let the posixfile() call below raise IOError.
if basename:
if atomictemp:
util.ensuredirs(dirname, self.createmode, notindexed)
return util.atomictempfile(f, mode, self.createmode)
try:
if 'w' in mode:
util.unlink(f)
nlink = 0
else:
# nlinks() may behave differently for files on Windows
# shares if the file is open.
fd = util.posixfile(f)
nlink = util.nlinks(f)
if nlink < 1:
nlink = 2 # force mktempcopy (issue1922)
fd.close()
except (OSError, IOError) as e:
if e.errno != errno.ENOENT:
raise
nlink = 0
util.ensuredirs(dirname, self.createmode, notindexed)
if nlink > 0:
if self._trustnlink is None:
self._trustnlink = nlink > 1 or util.checknlink(f)
if nlink > 1 or not self._trustnlink:
util.rename(util.mktempcopy(f), f)
fp = util.posixfile(f, mode)
if nlink == 0:
self._fixfilemode(f)
return fp
示例14: test_startup_heartbeat
def test_startup_heartbeat(self):
"""Make sure that startup failures cause a timeout"""
def empty_task():
pass
m = util.Manager(python="/path/does/not/exist")
m.heartbeat_timeout = 0.1
m.add_slave(IMP.parallel.LocalSlave())
c = m.get_context()
c.add_task(empty_task)
self.assertRaises(IMP.parallel.NetworkError, list,
c.get_results_unordered())
util.unlink('slave0.output')
示例15: release
def release(self):
"""release the lock and execute callback function if any
If the lock have been aquired multiple time, the actual release is
delayed to the last relase call."""
if self.held > 1:
self.held -= 1
elif self.held == 1:
self.held = 0
if self.releasefn:
self.releasefn()
try:
util.unlink(self.f)
except OSError:
pass
for callback in self.postrelease:
callback()