本文整理汇总了Python中xpra.util.nonl函数的典型用法代码示例。如果您正苦于以下问题:Python nonl函数的具体用法?Python nonl怎么用?Python nonl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nonl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_lpinfo_drv
def get_lpinfo_drv(make_and_model):
command = shlex.split(LPINFO) + ["--make-and-model", make_and_model, "-m"]
def preexec():
os.setsid()
log("get_lpinfo_drv(%s) command=%s", make_and_model, command)
try:
proc = subprocess.Popen(
command,
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False,
close_fds=True,
preexec_fn=preexec,
)
except Exception as e:
log("get_lp_info_drv(%s) lpinfo command %s failed", make_and_model, command, exc_info=True)
log.error("Error: lpinfo command failed to run")
log.error(" %s", e)
log.error(" command used: '%s'", " ".join(command))
return None
# use the global child reaper to make sure this doesn't end up as a zombie
from xpra.child_reaper import getChildReaper
from xpra.util import nonl
cr = getChildReaper()
cr.add_process(proc, "lpinfo", command, ignore=True, forget=True)
from xpra.make_thread import make_thread
def watch_lpinfo():
# give it 15 seconds to run:
for _ in range(15):
if proc.poll() is not None:
return # finished already
time.sleep(1)
log.warn("Warning: lpinfo command is taking too long")
proc.terminate()
make_thread(watch_lpinfo, "lpinfo watcher", daemon=True).start()
out, err = proc.communicate()
if proc.wait() != 0:
log.warn("Warning: lpinfo command failed and returned %s", proc.returncode)
log.warn(" command used: '%s'", " ".join(command))
return None
if sys.version_info[0] >= 3:
try:
out = out.decode()
except:
out = str(out)
log("lpinfo out=%s", nonl(out))
log("lpinfo err=%s", nonl(err))
if err:
log.warn("Warning: lpinfo command produced some warnings:")
log.warn(" '%s'", nonl(err))
for line in out.splitlines():
if line.startswith("drv://"):
return line.split(" ")[0]
return None
示例2: safe_exec
def safe_exec(cmd, stdin=None, log_errors=True, **kwargs):
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
out, err = process.communicate(stdin)
code = process.poll()
l=log.debug
if code!=0 and log_errors:
l=log.error
l("signal_safe_exec(%s, %s, %s) stdout='%s'", cmd, stdin, kwargs, nonl(out))
l("signal_safe_exec(%s, %s, %s) stderr='%s'", cmd, stdin, kwargs, nonl(err))
return code, out, err
示例3: get_keymap_spec
def get_keymap_spec(self):
log("get_keymap_spec() keyboard_bindings=%s", self.keyboard_bindings)
if not self.keyboard_bindings:
return None
_query_struct = self.keyboard_bindings.getXkbProperties()
_query = xkbmap_query_tostring(_query_struct)
log("get_keymap_spec() Xkb query tostring(%s)=%s", _query_struct, _query)
#we no longer support servers via xkbmap_print:
xkbmap_print = ""
log("get_keymap_spec()=(%s, %s, %s)", nonl(xkbmap_print), nonl(_query), nonl(_query_struct))
return xkbmap_print, _query, _query_struct
示例4: query_xkbmap
def query_xkbmap(self):
self.xkbmap_layout, self.xkbmap_variant, self.xkbmap_variants = self.keyboard.get_layout_spec()
self.xkbmap_print, self.xkbmap_query = self.keyboard.get_keymap_spec()
self.xkbmap_keycodes = self.get_full_keymap()
self.xkbmap_x11_keycodes = self.keyboard.get_x11_keymap()
self.xkbmap_mod_meanings, self.xkbmap_mod_managed, self.xkbmap_mod_pointermissing = self.keyboard.get_keymap_modifiers()
debug("layout=%s, variant=%s", self.xkbmap_layout, self.xkbmap_variant)
debug("print=%s, query=%s", nonl(self.xkbmap_print), nonl(self.xkbmap_query))
debug("keycodes=%s", str(self.xkbmap_keycodes)[:80]+"...")
debug("x11 keycodes=%s", str(self.xkbmap_x11_keycodes)[:80]+"...")
debug("xkbmap_mod_meanings: %s", self.xkbmap_mod_meanings)
示例5: query_xkbmap
def query_xkbmap(self):
self.xkbmap_layout, self.xkbmap_layouts, self.xkbmap_variant, self.xkbmap_variants = self.get_layout_spec()
self.xkbmap_print, self.xkbmap_query, self.xkbmap_query_struct = self.get_keymap_spec()
self.xkbmap_keycodes = self.get_full_keymap()
self.xkbmap_x11_keycodes = self.keyboard.get_x11_keymap()
self.xkbmap_mod_meanings, self.xkbmap_mod_managed, self.xkbmap_mod_pointermissing = self.keyboard.get_keymap_modifiers()
self.update_hash()
log("layout=%s, layouts=%s, variant=%s, variants=%s", self.xkbmap_layout, self.xkbmap_layouts, self.xkbmap_variant, self.xkbmap_variants)
log("print=%s, query=%s, struct=%s", nonl(self.xkbmap_print), nonl(self.xkbmap_query), nonl(self.xkbmap_query_struct))
log("keycodes=%s", str(self.xkbmap_keycodes)[:80]+"...")
log("x11 keycodes=%s", str(self.xkbmap_x11_keycodes)[:80]+"...")
log("mod managed: %s", self.xkbmap_mod_managed)
log("mod meanings: %s", self.xkbmap_mod_meanings)
log("mod pointermissing: %s", self.xkbmap_mod_pointermissing)
log("hash=%s", self.hash)
示例6: get_text_data
def get_text_data(self):
data = []
tb = self.description.get_buffer()
buf = tb.get_text(*tb.get_bounds(), include_hidden_chars=False)
if len(buf):
data.append(("Description", "", "txt", buf))
for name, dtype, title, value_cb, tooltip in self.toggles:
if not bool(value_cb):
continue
cb = getattr(self, name)
assert cb is not None
if not cb.get_active():
continue
#OK, the checkbox is selected, get the data
value = value_cb
if type(value_cb)!=dict:
try:
value = value_cb()
except TypeError:
log.error("error on %s", value_cb, exc_info=True)
value = str(value_cb)
dtype = "txt"
except Exception as e:
value = e
dtype = "txt"
if value is None:
value = "not available"
elif type(value)==dict:
s = os.linesep.join("%s : %s" % (k.ljust(32), nonl(str(v))) for k,v in sorted(value.items()))
elif type(value) in (list, tuple):
s = os.linesep.join(str(x) for x in value)
else:
s = str(value)
data.append((title, tooltip, dtype, s))
return data
示例7: _process_ack_file_chunk
def _process_ack_file_chunk(self, packet):
#the other end received our send-file or send-file-chunk,
#send some more file data
filelog("ack-file-chunk: %s", packet[1:])
chunk_id, state, error_message, chunk = packet[1:5]
if not state:
filelog.error("Error: remote end is cancelling the file transfer:")
filelog.error(" %s", error_message)
del self.send_chunks_in_progress[chunk_id]
return
chunk_state = self.send_chunks_in_progress.get(chunk_id)
if not chunk_state:
filelog.error("Error: cannot find the file transfer id '%s'", nonl(chunk_id))
return
if chunk_state[-1]!=chunk:
filelog.error("Error: chunk number mismatch (%i vs %i)", chunk_state, chunk)
del self.send_chunks_in_progress[chunk_id]
return
start_time, data, chunk_size, timer, chunk = chunk_state
if not data:
#all sent!
elapsed = time.time()-start_time
filelog("%i chunks of %i bytes sent in %ims (%sB/s)", chunk, chunk_size, elapsed*1000, std_unit(chunk*chunk_size/elapsed))
del self.send_chunks_in_progress[chunk_id]
return
assert chunk_size>0
#carve out another chunk:
cdata = self.compressed_wrapper("file-data", data[:chunk_size])
data = data[chunk_size:]
chunk += 1
if timer:
self.source_remove(timer)
timer = self.timeout_add(CHUNK_TIMEOUT, self._check_chunk_sending, chunk_id, chunk)
self.send_chunks_in_progress[chunk_id] = [start_time, data, chunk_size, timer, chunk]
self.send("send-file-chunk", chunk_id, chunk, cdata, bool(data))
示例8: get_keymap_spec
def get_keymap_spec(self):
v = self.get_keymap_spec_from_xkb()
if not v:
v = self.get_keymap_spec_using_setxkbmap()
from xpra.util import nonl
log("get_keymap_spec()=%s", nonl(str(v)))
return v
示例9: _process_hello
def _process_hello(self, packet):
log.debug("process_hello: %s", packet)
props = packet[1]
if props:
def sorted_nicely(l):
""" Sort the given iterable in the way that humans expect."""
def convert(text):
if text.isdigit():
return int(text)
else:
return text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', bytestostr(key)) ]
return sorted(l, key = alphanum_key)
for k in sorted_nicely(props.keys()):
v = props.get(k)
if sys.version_info[0]>=3:
#FIXME: this is a nasty and horrible python3 workaround (yet again)
#we want to print bytes as strings without the ugly 'b' prefix..
#it assumes that all the strings are raw or in (possibly nested) lists or tuples only
def fixvalue(w):
if type(w)==bytes:
return bytestostr(w)
elif type(w) in (tuple,list):
return type(w)([fixvalue(x) for x in w])
return w
v = fixvalue(v)
log.info("%s=%s", bytestostr(k), nonl(v))
self.quit(0)
示例10: main
def main():
from xpra.platform import init as platform_init, clean
from xpra.util import nonl
from xpra.log import enable_color
try:
platform_init("GUI-Properties")
enable_color()
init()
verbose = "-v" in sys.argv or "--verbose" in sys.argv
if verbose:
from xpra.log import get_all_loggers
for x in get_all_loggers():
x.enable_debug()
# naughty, but how else can I hook this up?
import os
if os.name == "posix":
try:
from xpra.x11.bindings import posix_display_source # @UnusedImport
except:
pass # maybe running on OSX? hope for the best..
i = get_info()
for k in sorted(i.keys()):
v = i[k]
print("* %s : %s" % (k.ljust(32), nonl(v)))
finally:
clean()
示例11: print_options
def print_options(o):
for k,ot in sorted(OPTION_TYPES.items()):
v = getattr(o, name_to_field(k), "")
if ot==bool and v is None:
v = "Auto"
if type(v)==list:
v = ", ".join(str(x) for x in v)
print("* %-32s : %s" % (k, nonl(v)))
示例12: print_options
def print_options(o):
for k,ot in sorted(OPTION_TYPES.items()):
attr_name = k.replace("-", "_")
v = getattr(o, attr_name, "")
if ot==bool and v is None:
v = "Auto"
if type(v)==list:
v = ", ".join(str(x) for x in v)
print("* %-32s : %s" % (k, nonl(v)))
示例13: _process_send_file_chunk
def _process_send_file_chunk(self, packet):
chunk_id, chunk, file_data, has_more = packet[1:5]
filelog("_process_send_file_chunk%s", (chunk_id, chunk, "%i bytes" % len(file_data), has_more))
chunk_state = self.receive_chunks_in_progress.get(chunk_id)
if not chunk_state:
filelog.error("Error: cannot find the file transfer id '%s'", nonl(chunk_id))
self.send("ack-file-chunk", chunk_id, False, "file transfer id not found", chunk)
return
fd = chunk_state[1]
if chunk_state[-1]+1!=chunk:
filelog.error("Error: chunk number mismatch, expected %i but got %i", chunk_state[-1]+1, chunk)
self.send("ack-file-chunk", chunk_id, False, "chunk number mismatch", chunk)
del self.receive_chunks_in_progress[chunk_id]
os.close(fd)
return
#update chunk number:
chunk_state[-1] = chunk
digest = chunk_state[8]
written = chunk_state[9]
try:
os.write(fd, file_data)
digest.update(file_data)
written += len(file_data)
chunk_state[9] = written
except OSError as e:
filelog.error("Error: cannot write file chunk")
filelog.error(" %s", e)
self.send("ack-file-chunk", chunk_id, False, "write error: %s" % e, chunk)
del self.receive_chunks_in_progress[chunk_id]
try:
os.close(fd)
except:
pass
return
self.send("ack-file-chunk", chunk_id, True, "", chunk)
if has_more:
timer = chunk_state[-2]
if timer:
self.source_remove(timer)
#remote end will send more after receiving the ack
timer = self.timeout_add(CHUNK_TIMEOUT, self._check_chunk_receiving, chunk_id, chunk)
chunk_state[-2] = timer
return
del self.receive_chunks_in_progress[chunk_id]
os.close(fd)
#check file size and digest then process it:
filename, mimetype, printit, openit, filesize, options = chunk_state[2:8]
if written!=filesize:
filelog.error("Error: expected a file of %i bytes, got %i", filesize, written)
return
expected_digest = options.get("sha1")
if expected_digest:
self.check_digest(filename, digest.hexdigest(), expected_digest)
start_time = chunk_state[0]
elapsed = time.time()-start_time
filelog("%i bytes received in %i chunks, took %ims", filesize, chunk, elapsed*1000)
self.do_process_downloaded_file(filename, mimetype, printit, openit, filesize, options)
示例14: _process_disconnect
def _process_disconnect(self, packet):
#ie: ("disconnect", "version error", "incompatible version")
reason = bytestostr(packet[1])
info = packet[2:]
s = nonl(reason)
if len(info):
s += " (%s)" % (", ".join([nonl(bytestostr(x)) for x in info]))
if self.server_capabilities is None or len(self.server_capabilities)==0:
#server never sent hello to us - so disconnect is an error
#(but we don't know which one - the info message may help)
log.warn("server failure: disconnected before the session could be established")
e = EXIT_FAILURE
elif disconnect_is_an_error(reason):
log.warn("server failure: %s", reason)
e = EXIT_FAILURE
else:
e = EXIT_OK
self.warn_and_quit(e, "server requested disconnect: %s" % s)
示例15: _open_file
def _open_file(self, filename):
if not self.open_files:
log.warn("Warning: opening files automatically is disabled,")
log.warn(" ignoring uploaded file:")
log.warn(" '%s'", filename)
return
import subprocess
PIPE = subprocess.PIPE
process = subprocess.Popen([self.open_command, filename], stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = process.communicate()
r = process.wait()
filelog.info("opened file %s with %s, exit code: %s", filename, self.open_command, r)
if r!=0:
l = filelog.warn
else:
l = filelog
if out:
l("stdout=%s", nonl(out)[:512])
if err:
l("stderr=%s", nonl(err)[:512])