Exemplo n.º 1
0
    def run (self):
        if self.host == None:
            self.host = cups.getServer ()
        if self.port == None:
            self.port = cups.getPort ()
        if self._encryption == None:
            self._encryption = cups.getEncryption ()

        if self.user:
            cups.setUser (self.user)
        else:
            self.user = cups.getUser ()

        try:
            cups.setPasswordCB2 (self._auth)
        except AttributeError:
            # Requires pycups >= 1.9.47.  Fall back to rubbish API.
            cups.setPasswordCB (self._auth)

        try:
            conn = cups.Connection (host=self.host,
                                    port=self.port,
                                    encryption=self._encryption)
            self._reply (None)
        except RuntimeError, e:
            conn = None
            self._error (e)
Exemplo n.º 2
0
    def __init__(self,
                 parent=None,
                 try_as_root=True,
                 lock=False,
                 host=None,
                 port=None,
                 encryption=None):
        if host != None:
            cups.setServer(host)
        if port != None:
            cups.setPort(port)
        if encryption != None:
            cups.setEncryption(encryption)

        self._use_password = ''
        self._parent = parent
        self._try_as_root = try_as_root
        self._use_user = cups.getUser()
        self._server = cups.getServer()
        self._port = cups.getPort()
        self._encryption = cups.getEncryption()
        self._prompt_allowed = True
        self._operation_stack = []
        self._lock = lock
        self._gui_event = threading.Event()

        self._connect()
Exemplo n.º 3
0
    def __init__ (self, parent=None, try_as_root=True, lock=False,
                  host=None, port=None, encryption=None):
        if host != None:
            cups.setServer (host)
        if port != None:
            cups.setPort (port)
        if encryption != None:
            cups.setEncryption (encryption)

        self._use_password = ''
        self._parent = parent
        self._try_as_root = try_as_root
        self._use_user = cups.getUser ()
        self._server = cups.getServer ()
        self._port = cups.getPort()
        self._encryption = cups.getEncryption ()
        self._prompt_allowed = True
        self._operation_stack = []
        self._lock = lock
        self._gui_event = threading.Event ()

        creds = global_authinfocache.lookup_auth_info (host=host, port=port)
        if creds != None:
            if (creds[0] != 'root' or try_as_root):
                (self._use_user, self._use_password) = creds
            del creds

        self._connect ()
    def __init__(self,
                 bus=None,
                 my_jobs=True,
                 specific_dests=None,
                 monitor_jobs=True,
                 host=None,
                 port=None,
                 encryption=None):
        GObject.GObject.__init__(self)
        self.my_jobs = my_jobs
        self.specific_dests = specific_dests
        self.monitor_jobs = monitor_jobs
        self.jobs = {}
        self.printer_state_reasons = {}
        self.printers = set()
        self.process_pending_events = True
        self.fetch_jobs_timer = None
        self.cups_connection_in_error = False

        if host:
            cups.setServer(host)
        if port:
            cups.setPort(port)
        if encryption:
            cups.setEncryption(encryption)
        self.user = cups.getUser()
        self.host = cups.getServer()
        self.port = cups.getPort()
        self.encryption = cups.getEncryption()
        self.ppdcache = ppdcache.PPDCache(host=self.host,
                                          port=self.port,
                                          encryption=self.encryption)

        self.which_jobs = "not-completed"
        self.reasons_seen = {}
        self.connecting_timers = {}
        self.still_connecting = set()
        self.connecting_to_device = {}
        self.received_any_dbus_signals = False
        self.update_timer = None

        if bus is None:
            try:
                bus = dbus.SystemBus()
            except dbus.exceptions.DBusException:
                # System bus not running.
                pass

        self.bus = bus
        if bus is not None:
            bus.add_signal_receiver(self.handle_dbus_signal,
                                    path=self.DBUS_PATH,
                                    dbus_interface=self.DBUS_IFACE)
        self.sub_id = -1
Exemplo n.º 5
0
    def __init__(self, bus=None, my_jobs=True,
                 specific_dests=None, monitor_jobs=True, host=None,
                 port=None, encryption=None):
        GObject.GObject.__init__ (self)
        self.my_jobs = my_jobs
        self.specific_dests = specific_dests
        self.monitor_jobs = monitor_jobs
        self.jobs = {}
        self.printer_state_reasons = {}
        self.printers = set()
        self.process_pending_events = True
        self.fetch_jobs_timer = None
        self.cups_connection_in_error = False

        if host:
            cups.setServer (host)
        if port:
            cups.setPort (port)
        if encryption:
            cups.setEncryption (encryption)
        self.user = cups.getUser ()
        self.host = cups.getServer ()
        self.port = cups.getPort ()
        self.encryption = cups.getEncryption ()
        self.ppdcache = ppdcache.PPDCache (host=self.host,
                                           port=self.port,
                                           encryption=self.encryption)

        self.which_jobs = "not-completed"
        self.reasons_seen = {}
        self.connecting_timers = {}
        self.still_connecting = set()
        self.connecting_to_device = {}
        self.received_any_dbus_signals = False
        self.update_timer = None

        if bus is None:
            try:
                bus = dbus.SystemBus ()
            except dbus.exceptions.DBusException:
                # System bus not running.
                pass

        self.bus = bus
        if bus is not None:
            bus.add_signal_receiver (self.handle_dbus_signal,
                                     path=self.DBUS_PATH,
                                     dbus_interface=self.DBUS_IFACE)
        self.sub_id = -1
    def __init__(self, parent=None, try_as_root=True, lock=False, host=None, port=None, encryption=None):
        if host != None:
            cups.setServer(host)
        if port != None:
            cups.setPort(port)
        if encryption != None:
            cups.setEncryption(encryption)

        self._use_password = ""
        self._parent = parent
        self._try_as_root = try_as_root
        self._use_user = cups.getUser()
        self._server = cups.getServer()
        self._port = cups.getPort()
        self._encryption = cups.getEncryption()
        self._prompt_allowed = True
        self._operation_stack = []
        self._lock = lock
        self._gui_event = threading.Event()

        self._connect()
Exemplo n.º 7
0
    def run (self):
        if self.host == None:
            self.host = cups.getServer ()
        if self.port == None:
            self.port = cups.getPort ()
        if self._encryption == None:
            self._encryption = cups.getEncryption ()

        if self.user:
            cups.setUser (self.user)
        else:
            self.user = cups.getUser ()

        cups.setPasswordCB2 (self._auth)

        try:
            conn = cups.Connection (host=self.host,
                                    port=self.port,
                                    encryption=self._encryption)
            self._reply (None)
        except RuntimeError, e:
            conn = None
            self._error (e)
Exemplo n.º 8
0
    def run (self):
        if self.host == None:
            self.host = cups.getServer ()
        if self.port == None:
            self.port = cups.getPort ()
        if self._encryption == None:
            self._encryption = cups.getEncryption ()

        if self.user:
            cups.setUser (self.user)
        else:
            self.user = cups.getUser ()

        cups.setPasswordCB2 (self._auth)

        try:
            conn = cups.Connection (host=self.host,
                                    port=self.port,
                                    encryption=self._encryption)
            self._reply (None)
        except RuntimeError as e:
            conn = None
            self._error (e)

        while True:
            # Wait to find out what operation to try.
            debugprint ("Awaiting further instructions")
            self.idle = self._queue.empty ()
            item = self._queue.get ()
            debugprint ("Next task: %s" % repr (item))
            if item == None:
                # Our signal to quit.
                self._queue.task_done ()
                break

            self.idle = False
            (fn, args, kwds, rh, eh, ah) = item
            if rh != False:
                self._reply_handler = rh
            if eh != False:
                self._error_handler = eh
            if ah != False:
                self._auth_handler = ah

            if fn == True:
                # Our signal to change user and reconnect.
                self.user = args[0]
                cups.setUser (self.user)
                debugprint ("Set user=%s; reconnecting..." % self.user)
                cups.setPasswordCB2 (self._auth)

                try:
                    conn = cups.Connection (host=self.host,
                                            port=self.port,
                                            encryption=self._encryption)
                    debugprint ("...reconnected")

                    self._queue.task_done ()
                    self._reply (None)
                except RuntimeError as e:
                    debugprint ("...failed")
                    self._queue.task_done ()
                    self._error (e)

                continue

            # Normal IPP operation.  Try to perform it.
            try:
                debugprint ("Call %s" % fn)
                result = fn (conn, *args, **kwds)
                if fn == cups.Connection.adminGetServerSettings.__call__:
                    # Special case for a rubbish bit of API.
                    if result == {}:
                        # Authentication failed, but we aren't told that.
                        raise cups.IPPError (cups.IPP_NOT_AUTHORIZED, '')

                debugprint ("...success")
                self._reply (result)
            except Exception as e:
                debugprint ("...failure (%s)" % repr (e))
                self._error (e)

            self._queue.task_done ()

        debugprint ("Thread exiting")
        self._destroyed = True
        del self._conn # already destroyed
        del self._reply_handler
        del self._error_handler
        del self._auth_handler
        del self._queue
        del self._auth_queue
        del conn

        cups.setPasswordCB2 (None)
    def run(self):
        if self.host == None:
            self.host = cups.getServer()
        if self.port == None:
            self.port = cups.getPort()
        if self._encryption == None:
            self._encryption = cups.getEncryption()

        if self.user:
            cups.setUser(self.user)
        else:
            self.user = cups.getUser()

        cups.setPasswordCB2(self._auth)

        try:
            conn = cups.Connection(host=self.host, port=self.port, encryption=self._encryption)
            self._reply(None)
        except RuntimeError as e:
            conn = None
            self._error(e)

        while True:
            # Wait to find out what operation to try.
            debugprint("Awaiting further instructions")
            self.idle = self._queue.empty()
            item = self._queue.get()
            debugprint("Next task: %s" % repr(item))
            if item == None:
                # Our signal to quit.
                self._queue.task_done()
                break
            elif self._destroyed:
                # Just mark all tasks done
                self._queue.task_done()
                continue

            self.idle = False
            (fn, args, kwds, rh, eh, ah) = item
            if rh != False:
                self._reply_handler = rh
            if eh != False:
                self._error_handler = eh
            if ah != False:
                self._auth_handler = ah

            if fn == True:
                # Our signal to change user and reconnect.
                self.user = args[0]
                cups.setUser(self.user)
                debugprint("Set user=%s; reconnecting..." % self.user)
                cups.setPasswordCB2(self._auth)

                try:
                    conn = cups.Connection(host=self.host, port=self.port, encryption=self._encryption)
                    debugprint("...reconnected")

                    self._queue.task_done()
                    self._reply(None)
                except RuntimeError as e:
                    debugprint("...failed")
                    self._queue.task_done()
                    self._error(e)

                continue

            # Normal IPP operation.  Try to perform it.
            try:
                debugprint("Call %s" % fn)
                result = fn(conn, *args, **kwds)
                if fn == cups.Connection.adminGetServerSettings.__call__:
                    # Special case for a rubbish bit of API.
                    if result == {}:
                        # Authentication failed, but we aren't told that.
                        raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, "")

                debugprint("...success")
                self._reply(result)
            except Exception as e:
                debugprint("...failure (%s)" % repr(e))
                self._error(e)

            self._queue.task_done()

        debugprint("Thread exiting")
        del self._conn  # already destroyed
        del self._reply_handler
        del self._error_handler
        del self._auth_handler
        del self._queue
        del self._auth_queue
        del conn

        cups.setPasswordCB2(None)