def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False): """Issue a ds9 command, raising errors as appropriate""" if getDefaultFrame() is None: return global cmdBuffer if cmd: if frame is not None: cmd = "%s;" % selectFrame(frame) + cmd if get: return xpa.get(None, getXpaAccessPoint(), cmd, "").strip() # Work around xpa's habit of silently truncating long lines if cmdBuffer._lenCommands + len(cmd) > XPA_SZ_LINE - 5: # 5 to handle newlines and such like ds9Cmd(flush=True, silent=silent) cmdBuffer._commands += ";" + cmd cmdBuffer._lenCommands += 1 + len(cmd) if flush or cmdBuffer._lenCommands >= cmdBuffer._getSize(): cmd = cmdBuffer._commands + "\n" cmdBuffer._commands = "" cmdBuffer._lenCommands = 0 else: return try: xpa.set(None, getXpaAccessPoint(), cmd, "", "", 0) except IOError, e: if not trap: raise Ds9Error, "XPA: %s, (%s)" % (e, cmd) elif not silent: print >> sys.stderr, "Caught ds9 exception processing command \"%s\": %s" % (cmd, e)
def list_active_ds9(): """Display information about the DS9 windows currently registered with XPA. Notes ----- when I start a unix socket with connect() the xpa register isn't seeing it when I call this function. I think because it's only listening on the inet socket which starts by default in the OS. That's if xpans is installed on the machine. Otherwise, no nameserver is running at all. """ # only run if XPA/xpans is installed on the machine if find_xpans(): try: sessions = xpa.get(b"xpans") if sessions is None: print("No active sessions") if len(sessions) < 1: print("No active sessions") else: print(sessions.decode()) except xpa.XpaException: print("No active sessions registered") else: print("XPA nameserver not installed or not on PATH, \ function unavailable")
def ds9Version(): """Return the version of ds9 in use, as a string""" try: v = xpa.get(None, getXpaAccessPoint(), "about", "").strip() return v.splitlines()[1].split()[1] except Exception, e: print >> sys.stderr, "Error reading version: %s (%s)" % (v, e) return "0.0.0"
def list_active_ds9(verbose=True): """ Display and/or return information about the DS9 windows currently registered with the XPA. Parameters ---------- verbose : bool If True, prints out all the information about what DS9 windows are active. Returns ------- session_list : list The list of sessions that have been registered. Each entry in the list is a list containing the information that xpans yields. Typically the fourth element in that tuple contains the actual target name. Notes ----- when I start a unix socket with connect() the xpa register isn't seeing it when I call this function. I think because it's only listening on the inet socket which starts by default in the OS. That's if xpans is installed on the machine. Otherwise, no nameserver is running at all. This helps with object cont """ session_dict = {} # only run if XPA/xpans is installed on the machine if find_xpans(): sessions = None try: sessions = xpa.get(b"xpans").decode().strip().split("\n") if ((sessions is None or len(sessions) < 1) and verbose): print("No active sessions") else: for line in sessions: classn, name, access, ids, user = tuple(line.split()) session_dict[ids] = (name, user, classn, access) if verbose: for line in sessions: print(line) except xpa.XpaException: print("No active sessions registered") else: print("XPA nameserver not installed or not on PATH, \ function unavailable") return session_dict
def list_active_ds9(verbose=True): """ Display and/or return information about the DS9 windows currently registered with XPA. Parameters ---------- verbose : bool If True, prints out all the information about what DS9 windows are active. Returns ------- session_list : list The list of sessions that have been registered. Each entry in the list is a list containing the information that xpans yields. Typically the fourth element in that tuple contains the actual target name. Notes ----- when I start a unix socket with connect() the xpa register isn't seeing it when I call this function. I think because it's only listening on the inet socket which starts by default in the OS. That's if xpans is installed on the machine. Otherwise, no nameserver is running at all. This helps with object cont """ session_dict = {} # only run if XPA/xpans is installed on the machine if find_xpans(): sessions = None try: sessions = xpa.get(b"xpans").decode().strip().split("\n") if ((sessions is None or len(sessions) < 1) and verbose): print("No active sessions") else: for line in sessions: classn, name, access, ids, user = tuple(line.split()) session_dict[ids] = (name, user, classn, access) if verbose: for line in sessions: print(line) except xpa.XpaException: print("No active sessions registered") else: print("XPA nameserver not installed or not on PATH, \ function unavailable") return session_dict
def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False): """Issue a ds9 command, raising errors as appropriate""" if getDefaultFrame() is None: return global cmdBuffer if cmd: if frame is not None: cmd = "%s;" % selectFrame(frame) + cmd if get: return xpa.get(None, getXpaAccessPoint(), cmd, "").strip() # Work around xpa's habit of silently truncating long lines if cmdBuffer._lenCommands + len( cmd) > XPA_SZ_LINE - 5: # 5 to handle newlines and such like ds9Cmd(flush=True, silent=silent) cmdBuffer._commands += ";" + cmd cmdBuffer._lenCommands += 1 + len(cmd) if flush or cmdBuffer._lenCommands >= cmdBuffer._getSize(): cmd = cmdBuffer._commands + "\n" cmdBuffer._commands = "" cmdBuffer._lenCommands = 0 else: return cmd = cmd.rstrip() if not cmd: return try: ret = xpa.set(None, getXpaAccessPoint(), cmd, "", "", 0) if ret: raise IOError(ret) except IOError, e: if not trap: raise Ds9Error, "XPA: %s, (%s)" % (e, cmd) elif not silent: print >> sys.stderr, "Caught ds9 exception processing command \"%s\": %s" % ( cmd, e)