本文整理汇总了Python中portage.os.open函数的典型用法代码示例。如果您正苦于以下问题:Python open函数的具体用法?Python open怎么用?Python open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_pipes
def make_pipes():
tempdir = tempfile.mkdtemp()
fifo_path = os.path.join(tempdir, 'fifo')
os.mkfifo(fifo_path)
return ((os.open(fifo_path, os.O_NONBLOCK|os.O_RDONLY),
os.open(fifo_path, os.O_NONBLOCK|os.O_WRONLY)),
functools.partial(shutil.rmtree, tempdir))
示例2: _start_post_builddir_lock
def _start_post_builddir_lock(self, lock_future=None, start_ipc_daemon=False):
if lock_future is not None:
if lock_future is not self._start_future:
raise AssertionError('lock_future is not self._start_future')
self._start_future = None
if lock_future.cancelled():
self._build_dir = None
self.cancelled = True
self._was_cancelled()
self._async_wait()
return
lock_future.result()
if start_ipc_daemon:
self.settings['PORTAGE_IPC_DAEMON'] = "1"
self._start_ipc_daemon()
if self.fd_pipes is None:
self.fd_pipes = {}
null_fd = None
if 0 not in self.fd_pipes and \
self.phase not in self._phases_interactive_whitelist and \
"interactive" not in self.settings.get("PROPERTIES", "").split():
null_fd = os.open('/dev/null', os.O_RDONLY)
self.fd_pipes[0] = null_fd
try:
SpawnProcess._start(self)
finally:
if null_fd is not None:
os.close(null_fd)
示例3: testLogfile
def testLogfile(self):
logfile = None
try:
fd, logfile = tempfile.mkstemp()
os.close(fd)
null_fd = os.open('/dev/null', os.O_RDWR)
test_string = 2 * "blah blah blah\n"
task_scheduler = TaskScheduler()
proc = SpawnProcess(
args=[BASH_BINARY, "-c",
"echo -n '%s'" % test_string],
env={}, fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd},
scheduler=task_scheduler.sched_iface,
logfile=logfile)
task_scheduler.add(proc)
task_scheduler.run()
os.close(null_fd)
f = codecs.open(_unicode_encode(logfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='strict')
log_content = f.read()
f.close()
# When logging passes through a pty, this comparison will fail
# unless the oflag terminal attributes have the termios.OPOST
# bit disabled. Otherwise, tranformations such as \n -> \r\n
# may occur.
self.assertEqual(test_string, log_content)
finally:
if logfile:
try:
os.unlink(logfile)
except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
del e
示例4: _check_sig_key
def _check_sig_key(self):
null_fd = os.open('/dev/null', os.O_RDONLY)
popen_proc = PopenProcess(proc=subprocess.Popen(
["gpg", "--verify", self._manifest_path],
stdin=null_fd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT),
pipe_reader=PipeReader())
os.close(null_fd)
popen_proc.pipe_reader.input_files = {
"producer" : popen_proc.proc.stdout}
self._start_task(popen_proc, self._check_sig_key_exit)
示例5: _start
def _start(self):
self._files = self._files_dict()
input_fd = os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
self._files.pipe_in = os.fdopen(input_fd, 'rb')
self._reg_id = self.scheduler.register(
self._files.pipe_in.fileno(),
self._registered_events, self._input_handler)
self._registered = True
示例6: _reopen_input
def _reopen_input(self):
"""
Re-open the input stream, in order to suppress
POLLHUP events (bug #339976).
"""
self.scheduler.unregister(self._reg_id)
os.close(self._files.pipe_in)
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
self._reg_id = self.scheduler.register(
self._files.pipe_in,
self._registered_events, self._input_handler)
示例7: _start
def _start(self):
self._files = self._files_dict()
# File streams are in unbuffered mode since we do atomic
# read and write of whole pickles.
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
self._reg_id = self.scheduler.register(
self._files.pipe_in,
self._registered_events, self._input_handler)
self._registered = True
示例8: hardlink_lockfile
def hardlink_lockfile(lockfilename, max_wait=14400):
"""Does the NFS, hardlink shuffle to ensure locking on the disk.
We create a PRIVATE lockfile, that is just a placeholder on the disk.
Then we HARDLINK the real lockfile to that private file.
If our file can 2 references, then we have the lock. :)
Otherwise we lather, rise, and repeat.
We default to a 4 hour timeout.
"""
start_time = time.time()
myhardlock = hardlock_name(lockfilename)
reported_waiting = False
while(time.time() < (start_time + max_wait)):
# We only need it to exist.
myfd = os.open(myhardlock, os.O_CREAT|os.O_RDWR,0o660)
os.close(myfd)
if not os.path.exists(myhardlock):
raise FileNotFound(
_("Created lockfile is missing: %(filename)s") % \
{"filename" : myhardlock})
try:
res = os.link(myhardlock, lockfilename)
except OSError:
pass
if hardlink_is_mine(myhardlock, lockfilename):
# We have the lock.
if reported_waiting:
writemsg("\n", noiselevel=-1)
return True
if reported_waiting:
writemsg(".", noiselevel=-1)
else:
reported_waiting = True
from portage.const import PORTAGE_BIN_PATH
msg = _("\nWaiting on (hardlink) lockfile: (one '.' per 3 seconds)\n"
"%(bin_path)s/clean_locks can fix stuck locks.\n"
"Lockfile: %(lockfilename)s\n") % \
{"bin_path": PORTAGE_BIN_PATH, "lockfilename": lockfilename}
writemsg(msg, noiselevel=-1)
time.sleep(3)
os.unlink(myhardlock)
return False
示例9: __init__
def __init__(self, environment):
self.conf = environment
pidfile = open(self.conf.get('pid_file'), 'w')
if (self.conf.get('no_daemon') == False):
print "forking to background"
if (os.fork() == 0):
os.setpgid(0,0);
pidfile.write(str(os.getpid()));
pidfile.close();
fd = os.open("/dev/null", os.O_WRONLY);
os.dup2(fd,1);
os.close(fd);
#self.main_loop()
else:
sys.exit()
else:
print "Keeping in foreground"
pidfile.write(str(os.getpid()));
pidfile.close();
示例10: testLogfile
def testLogfile(self):
logfile = None
try:
fd, logfile = tempfile.mkstemp()
os.close(fd)
null_fd = os.open("/dev/null", os.O_RDWR)
test_string = 2 * "blah blah blah\n"
scheduler = PollScheduler().sched_iface
proc = SpawnProcess(
args=[BASH_BINARY, "-c", "echo -n '%s'" % test_string],
env={},
fd_pipes={0: sys.stdin.fileno(), 1: null_fd, 2: null_fd},
scheduler=scheduler,
logfile=logfile,
)
proc.start()
os.close(null_fd)
self.assertEqual(proc.wait(), os.EX_OK)
f = io.open(
_unicode_encode(logfile, encoding=_encodings["fs"], errors="strict"),
mode="r",
encoding=_encodings["content"],
errors="strict",
)
log_content = f.read()
f.close()
# When logging passes through a pty, this comparison will fail
# unless the oflag terminal attributes have the termios.OPOST
# bit disabled. Otherwise, tranformations such as \n -> \r\n
# may occur.
self.assertEqual(test_string, log_content)
finally:
if logfile:
try:
os.unlink(logfile)
except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
del e
示例11: _run
def _run(self):
syncfs_failed = False
syncfs = self._get_syncfs()
if syncfs is not None:
for path in self.paths:
try:
fd = os.open(path, os.O_RDONLY)
except OSError:
pass
else:
try:
if syncfs(fd) != 0:
# Happens with PyPy (bug #446610)
syncfs_failed = True
finally:
os.close(fd)
if syncfs is None or syncfs_failed:
return 1
return os.EX_OK
示例12: _send_reply
def _send_reply(self, reply):
# File streams are in unbuffered mode since we do atomic
# read and write of whole pickles. Use non-blocking mode so
# we don't hang if the client is killed before we can send
# the reply. We rely on the client opening the other side
# of this fifo before it sends its request, since otherwise
# we'd have a race condition with this open call raising
# ENXIO if the client hasn't opened the fifo yet.
try:
output_fd = os.open(self.output_fifo,
os.O_WRONLY | os.O_NONBLOCK)
try:
os.write(output_fd, pickle.dumps(reply))
finally:
os.close(output_fd)
except OSError as e:
# This probably means that the client has been killed,
# which causes open to fail with ENXIO.
writemsg_level(
"!!! EbuildIpcDaemon %s: %s\n" % \
(_('failed to send reply'), e),
level=logging.ERROR, noiselevel=-1)
示例13: testLogfile
def testLogfile(self):
from portage import settings, spawn
from tempfile import mkstemp
logfile = None
try:
fd, logfile = mkstemp()
os.close(fd)
null_fd = os.open('/dev/null', os.O_RDWR)
test_string = 2 * "blah blah blah\n"
# Test cases are unique because they run inside src_test() which
# may or may not already be running within a sandbox. Interaction
# with SANDBOX_* variables may trigger unwanted sandbox violations
# that are only reproducible with certain combinations of sandbox,
# usersandbox, and userpriv FEATURES. Attempts to filter SANDBOX_*
# variables can interfere with a currently running sandbox
# instance. Therefore, use free=1 here to avoid potential
# interactions (see bug #190268).
spawn("echo -n '%s'" % test_string, settings, logfile=logfile,
free=1, fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd})
os.close(null_fd)
f = codecs.open(_unicode_encode(logfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='strict')
log_content = f.read()
f.close()
# When logging passes through a pty, this comparison will fail
# unless the oflag terminal attributes have the termios.OPOST
# bit disabled. Otherwise, tranformations such as \n -> \r\n
# may occur.
self.assertEqual(test_string, log_content)
finally:
if logfile:
try:
os.unlink(logfile)
except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
del e
示例14: _reopen_input
def _reopen_input(self):
"""
Re-open the input stream, in order to suppress
POLLHUP events (bug #339976).
"""
self.scheduler.remove_reader(self._files.pipe_in)
os.close(self._files.pipe_in)
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
# FD_CLOEXEC is enabled by default in Python >=3.4.
if sys.hexversion < 0x3040000 and fcntl is not None:
try:
fcntl.FD_CLOEXEC
except AttributeError:
pass
else:
fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
fcntl.fcntl(self._files.pipe_in,
fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
self.scheduler.add_reader(
self._files.pipe_in,
self._input_handler)
示例15: _start
def _start(self):
self._files = self._files_dict()
# File streams are in unbuffered mode since we do atomic
# read and write of whole pickles.
self._files.pipe_in = \
os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
# FD_CLOEXEC is enabled by default in Python >=3.4.
if sys.hexversion < 0x3040000 and fcntl is not None:
try:
fcntl.FD_CLOEXEC
except AttributeError:
pass
else:
fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
fcntl.fcntl(self._files.pipe_in,
fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
self.scheduler.add_reader(
self._files.pipe_in,
self._input_handler)
self._registered = True