Ejemplo n.º 1
0
def XConnect():

    name, host, displayno, screenno = xnet.get_X_display()
    xsock = xnet.get_X_socket(host, displayno)
    auth_name, auth_data = xnet.get_X_auth(xsock, name, host, displayno)
    byte_order = xnet.get_X_byteorder()

    rq = XConnectRequest(byte_order, 11, 0, auth_name, auth_data)

    xreply = Xchange(xsock, rq)

    if xreply[0] == '\x00':
        repobj = XConnectRefusedReply(xreply)
        raise xnet.XConnectionError(repobj.reason)

    elif xreply[0] == '\x01':
        repobj = XConnectAcceptedReply(xreply)

    elif xreply[0] == '\x02':
        repobj = XConnectAuthenticateReply(xreply)
        raise xnet.XConnectionError(repobj.reason)

    else:
        raise xnet.XConnectionError('Unknown connection failure')

    return xsock, repobj
Ejemplo n.º 2
0
def XConnect():

    name, host, displayno, screenno = xnet.get_X_display()
    xsock = xnet.get_X_socket( host, displayno )
    auth_name, auth_data = xnet.get_X_auth( xsock, name, host, displayno )
    byte_order = xnet.get_X_byteorder()

    rq = XConnectRequest( byte_order, 11, 0, auth_name, auth_data )

    xreply = Xchange( xsock, rq )

    if xreply[0] == '\x00':
        repobj = XConnectRefusedReply(xreply)
        raise xnet.XConnectionError( repobj.reason )

    elif xreply[0] == '\x01':
        repobj = XConnectAcceptedReply(xreply)

    elif xreply[0] == '\x02':
        repobj = XConnectAuthenticateReply(xreply) 
        raise xnet.XConnectionError( repobj.reason )

    else:
        raise xnet.XConnectionError( 'Unknown connection failure' )

    return xsock, repobj
Ejemplo n.º 3
0
    def query(self, type, option, target=None, device=None):
        '''retrieve the value from an option for a target. If target is None,
        the first found target is found. Device should only be specified
        for options that require one. If the specified device is not found,
        the value of the option without a device specification is returned,
        if present. This is how nvidia-settings behaves if I'm correct.
        Returns first option found, or None if not found. The option is
        cast to type on success (so that you don't have to check for None
        and then cast it).
        Only options for the X display are found.

        TODO: make more specific targets in configfile get precedence.'''
        # option name
        opts = filter(lambda x: x[1] == option, self._opts)
        # device
        # TODO it's unclear if multiple devices may be specified for a single
        #      option in the configuration file
        if device:
            optsdfl = filter(lambda x: not x[2], opts)
            opts = filter(lambda x: x[2] == device, opts)
            if not opts: opts = optsdfl
        if not target: target = Screen(0)
        # target: only current host for display
        d, host, dno, screen = xnet.get_X_display()
        if not host: host = socket.gethostname()
        host = socket.gethostbyname(host)
        if isinstance(target, Screen): screen = target.id()
        # throw away all options that aren't for us
        for o in list(opts):
            loc = o[0]
            if not loc: continue
            # {host}:{display}.{screen}[target_type:target_id]
            m = re.match('(([\w\.]*):)?(\d+)(\.(\d+))?(\[(\w+):(\d+)\])?$',
                         loc)
            if m:
                chost, cdno, cscreen = m.group(2), m.group(3), m.group(5)
                ctargettype, ctargetval = m.group(7), m.group(8)
                if chost: chost = socket.gethostbyname(chost)
                if (not chost or chost==host) and \
                   (not cdno or int(cdno)==int(dno)) and \
                   (not cscreen or int(cscreen)==int(screen)) and \
                   (not ctargettype or \
                     (ctargettype=='gpu' and isinstance(target, GPU)) or \
                     (ctargettype=='screen' and isinstance(target, Screen))
                   ) and \
                   (not ctargetval or ctargetval==target.id()):
                    # everything matches, keep
                    continue
            else:
                # TODO warn
                pass
            # no match, remove opts from list
            opts.remove(o)
        # return
        if len(opts) > 0: return type(opts[0][3])
        else: return None
Ejemplo n.º 4
0
    def init_NV_CONTROL(self):
        '''Connect to X and confirm NV-CONTROL. Raise KeyError is NV-CONTROL
        not found, or raise ValueError is buggy NV-CONTROL (minor 8 or 9) is
        found.'''

        name, host, displayno, self.xscreen = xnet.get_X_display()
        self.xsock, self.xconn = minx.XConnect()
        try:
            NVCtrl = minx.XQueryExtension(self.xsock, 'NV-CONTROL')
            self.opcode = NVCtrl.major_opcode
        except Exception, e:
            self.xsock.close()
            raise e
Ejemplo n.º 5
0
    def init_NV_CONTROL(self):
        """Connect to X and confirm NV-CONTROL. Raise KeyError is NV-CONTROL
        not found, or raise ValueError is buggy NV-CONTROL (minor 8 or 9) is
        found."""

        name, host, displayno, self.xscreen = xnet.get_X_display()
        self.xsock, self.xconn = minx.XConnect()
        try:
            NVCtrl = minx.XQueryExtension(self.xsock, "NV-CONTROL")
            self.opcode = NVCtrl.major_opcode
        except Exception, e:
            self.xsock.close()
            raise e
Ejemplo n.º 6
0
    def init_NV_CONTROL(self):
        '''Connect to X and confirm NV-CONTROL. Raise KeyError is NV-CONTROL
        not found, or raise ValueError is buggy NV-CONTROL (minor 8 or 9) is
        found.'''

        name, host, displayno, self.xscreen = xnet.get_X_display()
        self.xsock, self.xconn = minx.XConnect()
        try:
            NVCtrl = minx.XQueryExtension(self.xsock, 'NV-CONTROL')
            self.opcode = NVCtrl.major_opcode
        except Exception as e:
            self.xsock.close()
            raise e

        if not NVCtrl.present:
            self.xsock.close()
            self.xsock = None
            raise KeyError( 'NV-CONTROL extension not found, probably not an nVidia card' )

        version = self.get_version()

        if version[1] == 8 or version[1] == 9:
            self.xsock.close()
            raise ValueError( 'buggy NV-CONTROL extension (arg swap bug): '+'.'.join(version) )
Ejemplo n.º 7
0
    def query(self, type, option, target=None, device=None):
        """retrieve the value from an option for a target. If target is None,
        the first found target is found. Device should only be specified
        for options that require one. If the specified device is not found,
        the value of the option without a device specification is returned,
        if present. This is how nvidia-settings behaves if I'm correct.
        Returns first option found, or None if not found. The option is
        cast to type on success (so that you don't have to check for None
        and then cast it).
        Only options for the X display are found.

        TODO: make more specific targets in configfile get precedence."""
        # option name
        opts = filter(lambda x: x[1] == option, self._opts)
        # device
        # TODO it's unclear if multiple devices may be specified for a single
        #      option in the configuration file
        if device:
            optsdfl = filter(lambda x: not x[2], opts)
            opts = filter(lambda x: x[2] == device, opts)
            if not opts:
                opts = optsdfl
        if not target:
            target = Screen(0)
        # target: only current host for display
        d, host, dno, screen = xnet.get_X_display()
        if not host:
            host = socket.gethostname()
        host = socket.gethostbyname(host)
        if isinstance(target, Screen):
            screen = target.id()
        # throw away all options that aren't for us
        for o in list(opts):
            loc = o[0]
            if not loc:
                continue
            # {host}:{display}.{screen}[target_type:target_id]
            m = re.match("(([\w\.]*):)?(\d+)(\.(\d+))?(\[(\w+):(\d+)\])?$", loc)
            if m:
                chost, cdno, cscreen = m.group(2), m.group(3), m.group(5)
                ctargettype, ctargetval = m.group(7), m.group(8)
                if chost:
                    chost = socket.gethostbyname(chost)
                if (
                    (not chost or chost == host)
                    and (not cdno or int(cdno) == int(dno))
                    and (not cscreen or int(cscreen) == int(screen))
                    and (
                        not ctargettype
                        or (ctargettype == "gpu" and isinstance(target, GPU))
                        or (ctargettype == "screen" and isinstance(target, Screen))
                    )
                    and (not ctargetval or ctargetval == target.id())
                ):
                    # everything matches, keep
                    continue
            else:
                # TODO warn
                pass
            # no match, remove opts from list
            opts.remove(o)
        # return
        if len(opts) > 0:
            return type(opts[0][3])
        else:
            return None