本文整理汇总了Python中portage.locks.lockfile函数的典型用法代码示例。如果您正苦于以下问题:Python lockfile函数的具体用法?Python lockfile怎么用?Python lockfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lockfile函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getUnreadItems
def getUnreadItems(self, repoid, update=False):
"""
Determine if there are unread relevant items in news.repoid.unread.
If there are unread items return their number.
If update is specified, updateNewsItems( repoid ) will be called to
check for new items.
"""
if update:
self.updateItems(repoid)
unread_filename = self._unread_filename(repoid)
unread_lock = None
try:
unread_lock = lockfile(unread_filename, wantnewlockfile=1)
except (InvalidLocation, OperationNotPermitted, PermissionDenied):
pass
try:
try:
return len(grabfile(unread_filename))
except PermissionDenied:
return 0
finally:
if unread_lock:
unlockfile(unread_lock)
开发者ID:nullishzero,项目名称:Portage,代码行数:25,代码来源:news.py
示例2: populate
def populate(self, getbinpkgs=0):
"populates the binarytree"
if self._populating:
return
from portage.locks import lockfile, unlockfile
pkgindex_lock = None
try:
if os.access(self.pkgdir, os.W_OK):
pkgindex_lock = lockfile(self._pkgindex_file,
wantnewlockfile=1)
self._populating = True
self._populate(getbinpkgs)
finally:
if pkgindex_lock:
unlockfile(pkgindex_lock)
self._populating = False
开发者ID:Neuvoo,项目名称:legacy-portage,代码行数:17,代码来源:bintree.py
示例3: populate
def populate(self, getbinpkgs=0, getbinpkgsonly=None):
"populates the binarytree"
if getbinpkgsonly is not None:
warnings.warn(
"portage.dbapi.bintree.binarytree.populate(): " + \
"getbinpkgsonly parameter is deprecated",
DeprecationWarning, stacklevel=2)
if self._populating:
return
from portage.locks import lockfile, unlockfile
pkgindex_lock = None
try:
if os.access(self.pkgdir, os.W_OK):
pkgindex_lock = lockfile(self._pkgindex_file,
wantnewlockfile=1)
self._populating = True
self._populate(getbinpkgs)
finally:
if pkgindex_lock:
unlockfile(pkgindex_lock)
self._populating = False
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:23,代码来源:bintree.py
示例4: _start
def _start(self):
if not self._force_async:
try:
self._imp = lockfile(self.path,
wantnewlockfile=True, flags=os.O_NONBLOCK)
except TryAgain:
pass
else:
self.returncode = os.EX_OK
self.wait()
return
if self._force_process or \
(not self._force_thread and \
(self._use_process_by_default or threading is dummy_threading)):
self._imp = _LockProcess(path=self.path, scheduler=self.scheduler)
else:
self._imp = _LockThread(path=self.path,
scheduler=self.scheduler,
_force_dummy=self._force_dummy)
self._imp.addExitListener(self._imp_exit)
self._imp.start()
开发者ID:devurandom,项目名称:portage,代码行数:24,代码来源:AsynchronousLock.py
示例5: lock
def lock(self):
self._ensure_dirs()
self._lock = lockfile(self._filename, wantnewlockfile=1)
开发者ID:devurandom,项目名称:portage,代码行数:3,代码来源:files.py
示例6: updateItems
def updateItems(self, repoid):
"""
Figure out which news items from NEWS_PATH are both unread and relevant to
the user (according to the GLEP 42 standards of relevancy). Then add these
items into the news.repoid.unread file.
"""
# Ensure that the unread path exists and is writable.
try:
ensure_dirs(self.unread_path, uid=self._uid, gid=self._gid,
mode=self._dir_mode, mask=self._mode_mask)
except (OperationNotPermitted, PermissionDenied):
return
if not os.access(self.unread_path, os.W_OK):
return
news_dir = self._news_dir(repoid)
try:
news = _os.listdir(_unicode_encode(news_dir,
encoding=_encodings['fs'], errors='strict'))
except OSError:
return
skip_filename = self._skip_filename(repoid)
unread_filename = self._unread_filename(repoid)
unread_lock = lockfile(unread_filename, wantnewlockfile=1)
try:
try:
unread = set(grabfile(unread_filename))
unread_orig = unread.copy()
skip = set(grabfile(skip_filename))
skip_orig = skip.copy()
except PermissionDenied:
return
for itemid in news:
try:
itemid = _unicode_decode(itemid,
encoding=_encodings['fs'], errors='strict')
except UnicodeDecodeError:
itemid = _unicode_decode(itemid,
encoding=_encodings['fs'], errors='replace')
writemsg_level(
_("!!! Invalid encoding in news item name: '%s'\n") % \
itemid, level=logging.ERROR, noiselevel=-1)
continue
if itemid in skip:
continue
filename = os.path.join(news_dir, itemid,
itemid + "." + self.language_id + ".txt")
if not os.path.isfile(filename):
continue
item = NewsItem(filename, itemid)
if not item.isValid():
continue
if item.isRelevant(profile=self._profile_path,
config=self.config, vardb=self.vdb):
unread.add(item.name)
skip.add(item.name)
if unread != unread_orig:
write_atomic(unread_filename,
"".join("%s\n" % x for x in sorted(unread)))
apply_secpass_permissions(unread_filename,
uid=self._uid, gid=self._gid,
mode=self._file_mode, mask=self._mode_mask)
if skip != skip_orig:
write_atomic(skip_filename,
"".join("%s\n" % x for x in sorted(skip)))
apply_secpass_permissions(skip_filename,
uid=self._uid, gid=self._gid,
mode=self._file_mode, mask=self._mode_mask)
finally:
unlockfile(unread_lock)
开发者ID:nullishzero,项目名称:Portage,代码行数:79,代码来源:news.py
示例7: fetch
#.........这里部分代码省略.........
(mysettings["DISTDIR"], e),
noiselevel=-1, level=logging.ERROR)
del e
if vfs_stat is not None:
try:
mysize = os.stat(myfile_path).st_size
except OSError as e:
if e.errno not in (errno.ENOENT, errno.ESTALE):
raise
del e
mysize = 0
if (size - mysize + vfs_stat.f_bsize) >= \
(vfs_stat.f_bsize * vfs_stat.f_bavail):
if (size - mysize + vfs_stat.f_bsize) >= \
(vfs_stat.f_bsize * vfs_stat.f_bfree):
has_space_superuser = False
if not has_space_superuser:
has_space = False
elif secpass < 2:
has_space = False
elif userfetch:
has_space = False
if distdir_writable and use_locks:
lock_kwargs = {}
if fetchonly:
lock_kwargs["flags"] = os.O_NONBLOCK
try:
file_lock = lockfile(myfile_path,
wantnewlockfile=1, **lock_kwargs)
except TryAgain:
writemsg(_(">>> File '%s' is already locked by "
"another fetcher. Continuing...\n") % myfile,
noiselevel=-1)
continue
try:
if not listonly:
eout = EOutput()
eout.quiet = mysettings.get("PORTAGE_QUIET") == "1"
match, mystat = _check_distfile(
myfile_path, pruned_digests, eout, hash_filter=hash_filter)
if match:
# Skip permission adjustment for symlinks, since we don't
# want to modify anything outside of the primary DISTDIR,
# and symlinks typically point to PORTAGE_RO_DISTDIRS.
if distdir_writable and not os.path.islink(myfile_path):
try:
apply_secpass_permissions(myfile_path,
gid=portage_gid, mode=0o664, mask=0o2,
stat_cached=mystat)
except PortageException as e:
if not os.access(myfile_path, os.R_OK):
writemsg(_("!!! Failed to adjust permissions:"
" %s\n") % str(e), noiselevel=-1)
del e
continue
if distdir_writable and mystat is None:
# Remove broken symlinks if necessary.
try:
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:67,代码来源:fetch.py
示例8: lock
def lock(self):
"""Grab an exclusive lock on the preserved libs registry."""
if self._lock is not None:
raise AssertionError("already locked")
self._lock = lockfile(self._filename)
开发者ID:zy-sunshine,项目名称:easymgc,代码行数:5,代码来源:PreservedLibsRegistry.py
示例9: _input_handler
def _input_handler(self):
# Read the whole pickle in a single atomic read() call.
data = self._read_buf(self._files.pipe_in)
if data is None:
pass # EAGAIN
elif data:
try:
obj = pickle.loads(data)
except SystemExit:
raise
except Exception:
# The pickle module can raise practically
# any exception when given corrupt data.
pass
else:
self._reopen_input()
cmd_key = obj[0]
cmd_handler = self.commands[cmd_key]
reply = cmd_handler(obj)
try:
self._send_reply(reply)
except OSError as e:
if e.errno == errno.ENXIO:
# This happens if the client side has been killed.
pass
else:
raise
# Allow the command to execute hooks after its reply
# has been sent. This hook is used by the 'exit'
# command to kill the ebuild process. For some
# reason, the ebuild-ipc helper hangs up the
# ebuild process if it is waiting for a reply
# when we try to kill the ebuild process.
reply_hook = getattr(cmd_handler,
'reply_hook', None)
if reply_hook is not None:
reply_hook()
else: # EIO/POLLHUP
# This can be triggered due to a race condition which happens when
# the previous _reopen_input() call occurs before the writer has
# closed the pipe (see bug #401919). It's not safe to re-open
# without a lock here, since it's possible that another writer will
# write something to the pipe just before we close it, and in that
# case the write will be lost. Therefore, try for a non-blocking
# lock, and only re-open the pipe if the lock is acquired.
lock_filename = os.path.join(
os.path.dirname(self.input_fifo), '.ipc_lock')
try:
lock_obj = lockfile(lock_filename, unlinkfile=True,
flags=os.O_NONBLOCK)
except TryAgain:
# We'll try again when another IO_HUP event arrives.
pass
else:
try:
self._reopen_input()
finally:
unlockfile(lock_obj)
开发者ID:gentoo,项目名称:portage,代码行数:62,代码来源:EbuildIpcDaemon.py
示例10: fix
def fix(self, **kwargs):
onProgress = kwargs.get('onProgress', None)
bintree = self._bintree
_instance_key = bintree.dbapi._instance_key
cpv_all = self._bintree.dbapi.cpv_all()
cpv_all.sort()
missing = []
maxval = 0
if onProgress:
onProgress(maxval, 0)
pkgindex = self._pkgindex
missing = []
stale = []
metadata = {}
for d in pkgindex.packages:
cpv = _pkg_str(d["CPV"], metadata=d,
settings=bintree.settings)
d["CPV"] = cpv
metadata[_instance_key(cpv)] = d
if not bintree.dbapi.cpv_exists(cpv):
stale.append(cpv)
for cpv in cpv_all:
d = metadata.get(_instance_key(cpv))
if not d or self._need_update(cpv, d):
missing.append(cpv)
if missing or stale:
from portage import locks
pkgindex_lock = locks.lockfile(
self._pkgindex_file, wantnewlockfile=1)
try:
# Repopulate with lock held.
bintree._populate()
cpv_all = self._bintree.dbapi.cpv_all()
cpv_all.sort()
pkgindex = bintree._load_pkgindex()
self._pkgindex = pkgindex
# Recount stale/missing packages, with lock held.
missing = []
stale = []
metadata = {}
for d in pkgindex.packages:
cpv = _pkg_str(d["CPV"], metadata=d,
settings=bintree.settings)
d["CPV"] = cpv
metadata[_instance_key(cpv)] = d
if not bintree.dbapi.cpv_exists(cpv):
stale.append(cpv)
for cpv in cpv_all:
d = metadata.get(_instance_key(cpv))
if not d or self._need_update(cpv, d):
missing.append(cpv)
maxval = len(missing)
for i, cpv in enumerate(missing):
d = bintree._pkgindex_entry(cpv)
try:
bintree._eval_use_flags(cpv, d)
except portage.exception.InvalidDependString:
writemsg("!!! Invalid binary package: '%s'\n" % \
bintree.getname(cpv), noiselevel=-1)
else:
metadata[_instance_key(cpv)] = d
if onProgress:
onProgress(maxval, i+1)
for cpv in stale:
del metadata[_instance_key(cpv)]
# We've updated the pkgindex, so set it to
# repopulate when necessary.
bintree.populated = False
del pkgindex.packages[:]
pkgindex.packages.extend(metadata.values())
bintree._pkgindex_write(self._pkgindex)
finally:
locks.unlockfile(pkgindex_lock)
if onProgress:
if maxval == 0:
maxval = 1
onProgress(maxval, maxval)
return (True, None)
开发者ID:dol-sen,项目名称:portage,代码行数:90,代码来源:binhost.py
示例11: fix
def fix(self, **kwargs):
onProgress = kwargs.get('onProgress', None)
bintree = self._bintree
cpv_all = self._bintree.dbapi.cpv_all()
cpv_all.sort()
missing = []
maxval = 0
if onProgress:
onProgress(maxval, 0)
pkgindex = self._pkgindex
missing = []
metadata = {}
for d in pkgindex.packages:
metadata[d["CPV"]] = d
for i, cpv in enumerate(cpv_all):
d = metadata.get(cpv)
if not d or self._need_update(cpv, d):
missing.append(cpv)
stale = set(metadata).difference(cpv_all)
if missing or stale:
from portage import locks
pkgindex_lock = locks.lockfile(
self._pkgindex_file, wantnewlockfile=1)
try:
# Repopulate with lock held.
bintree._populate()
cpv_all = self._bintree.dbapi.cpv_all()
cpv_all.sort()
pkgindex = bintree._load_pkgindex()
self._pkgindex = pkgindex
metadata = {}
for d in pkgindex.packages:
metadata[d["CPV"]] = d
# Recount missing packages, with lock held.
del missing[:]
for i, cpv in enumerate(cpv_all):
d = metadata.get(cpv)
if not d or self._need_update(cpv, d):
missing.append(cpv)
maxval = len(missing)
for i, cpv in enumerate(missing):
try:
metadata[cpv] = bintree._pkgindex_entry(cpv)
except portage.exception.InvalidDependString:
writemsg("!!! Invalid binary package: '%s'\n" % \
bintree.getname(cpv), noiselevel=-1)
if onProgress:
onProgress(maxval, i+1)
for cpv in set(metadata).difference(
self._bintree.dbapi.cpv_all()):
del metadata[cpv]
# We've updated the pkgindex, so set it to
# repopulate when necessary.
bintree.populated = False
del pkgindex.packages[:]
pkgindex.packages.extend(metadata.values())
bintree._pkgindex_write(self._pkgindex)
finally:
locks.unlockfile(pkgindex_lock)
if onProgress:
if maxval == 0:
maxval = 1
onProgress(maxval, maxval)
return None
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:76,代码来源:binhost.py
示例12: lock
def lock(self):
if self._lock is not None:
raise AssertionError("already locked")
self._lock = lockfile(self._filename, wantnewlockfile=1)
开发者ID:jonasstein,项目名称:portage,代码行数:4,代码来源:files.py
示例13: _input_handler
def _input_handler(self, fd, event):
# Read the whole pickle in a single atomic read() call.
data = None
if event & self.scheduler.IO_IN:
# For maximum portability, use os.read() here since
# array.fromfile() and file.read() are both known to
# erroneously return an empty string from this
# non-blocking fifo stream on FreeBSD (bug #337465).
try:
data = os.read(fd, self._bufsize)
except OSError as e:
if e.errno != errno.EAGAIN:
raise
# Assume that another event will be generated
# if there's any relevant data.
if data:
try:
obj = pickle.loads(data)
except SystemExit:
raise
except Exception:
# The pickle module can raise practically
# any exception when given corrupt data.
pass
else:
self._reopen_input()
cmd_key = obj[0]
cmd_handler = self.commands[cmd_key]
reply = cmd_handler(obj)
try:
self._send_reply(reply)
except OSError as e:
if e.errno == errno.ENXIO:
# This happens if the client side has been killed.
pass
else:
raise
# Allow the command to execute hooks after its reply
# has been sent. This hook is used by the 'exit'
# command to kill the ebuild process. For some
# reason, the ebuild-ipc helper hangs up the
# ebuild process if it is waiting for a reply
# when we try to kill the ebuild process.
reply_hook = getattr(cmd_handler,
'reply_hook', None)
if reply_hook is not None:
reply_hook()
elif event & self.scheduler.IO_HUP:
# This can be triggered due to a race condition which happens when
# the previous _reopen_input() call occurs before the writer has
# closed the pipe (see bug #401919). It's not safe to re-open
# without a lock here, since it's possible that another writer will
# write something to the pipe just before we close it, and in that
# case the write will be lost. Therefore, try for a non-blocking
# lock, and only re-open the pipe if the lock is acquired.
lock_filename = os.path.join(
os.path.dirname(self.input_fifo), '.ipc_lock')
try:
lock_obj = lockfile(lock_filename, unlinkfile=True,
flags=os.O_NONBLOCK)
except TryAgain:
# We'll try again when another IO_HUP event arrives.
pass
else:
try:
self._reopen_input()
finally:
unlockfile(lock_obj)
return True
开发者ID:Spencerx,项目名称:portage,代码行数:76,代码来源:EbuildIpcDaemon.py
示例14: _run_lock
def _run_lock(self):
self._lock_obj = lockfile(self.path, wantnewlockfile=True)
os.write(self._files['pipe_write'], b'\0')
开发者ID:devurandom,项目名称:portage,代码行数:3,代码来源:AsynchronousLock.py
示例15: inject
def inject(self, cpv, filename=None):
"""Add a freshly built package to the database. This updates
$PKGDIR/Packages with the new package metadata (including MD5).
@param cpv: The cpv of the new package to inject
@type cpv: string
@param filename: File path of the package to inject, or None if it's
already in the location returned by getname()
@type filename: string
@rtype: None
"""
mycat, mypkg = catsplit(cpv)
if not self.populated:
self.populate()
if filename is None:
full_path = self.getname(cpv)
else:
full_path = filename
try:
s = os.stat(full_path)
except OSError as e:
if e.errno != errno.ENOENT:
raise
del e
writemsg(_("!!! Binary package does not exist: '%s'\n") % full_path,
noiselevel=-1)
return
mytbz2 = portage.xpak.tbz2(full_path)
slot = mytbz2.getfile("SLOT")
if slot is None:
writemsg(_("!!! Invalid binary package: '%s'\n") % full_path,
noiselevel=-1)
return
slot = slot.strip()
self.dbapi.cpv_inject(cpv)
# Reread the Packages index (in case it's been changed by another
# process) and then updated it, all while holding a lock.
from portage.locks import lockfile, unlockfile
pkgindex_lock = None
created_symlink = False
try:
pkgindex_lock = lockfile(self._pkgindex_file,
wantnewlockfile=1)
if filename is not None:
new_filename = self.getname(cpv)
self._ensure_dir(os.path.dirname(new_filename))
_movefile(filename, new_filename, mysettings=self.settings)
if self._all_directory and \
self.getname(cpv).split(os.path.sep)[-2] == "All":
self._create_symlink(cpv)
created_symlink = True
pkgindex = self._load_pkgindex()
if not self._pkgindex_version_supported(pkgindex):
pkgindex = self._new_pkgindex()
try:
d = self._pkgindex_entry(cpv)
except portage.exception.InvalidDependString:
writemsg(_("!!! Invalid binary package: '%s'\n") % \
self.getname(cpv), noiselevel=-1)
self.dbapi.cpv_remove(cpv)
del self._pkg_paths[cpv]
return
# If found, remove package(s) with duplicate path.
path = d.get("PATH", "")
for i in range(len(pkgindex.packages) - 1, -1, -1):
d2 = pkgindex.packages[i]
if path and path == d2.get("PATH"):
# Handle path collisions in $PKGDIR/All
# when CPV is not identical.
del pkgindex.packages[i]
elif cpv == d2.get("CPV"):
if path == d2.get("PATH", ""):
del pkgindex.packages[i]
elif created_symlink and not d2.get("PATH", ""):
# Delete entry for the package that was just
# overwritten by a symlink to this package.
del pkgindex.packages[i]
pkgindex.packages.append(d)
self._update_pkgindex_header(pkgindex.header)
from portage.util import atomic_ofstream
f = atomic_ofstream(os.path.join(self.pkgdir, "Packages"))
try:
pkgindex.write(f)
finally:
f.close()
finally:
if pkgindex_lock:
unlockfile(pkgindex_lock)
if self._remotepkgs is not None:
# When a remote package is downloaded and injected,
# update state so self.isremote() returns False.
self._remotepkgs.pop(cpv, None)
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:98,代码来源:bintree.py
示例16: _run_lock
def _run_lock(self):
self._lock_obj = lockfile(self.path, wantnewlockfile=True)
# Thread-safe callback to EventLoop
self.scheduler.idle_add(self._run_lock_cb)
开发者ID:Spencerx,项目名称:portage,代码行数:4,代码来源:AsynchronousLock.py
注:本文中的portage.locks.lockfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论