Ejemplo n.º 1
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()
Ejemplo 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 ()

        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 ()
Ejemplo n.º 3
0
Archivo: main.py Proyecto: gonicus/gosa
    def serve(self):
        try:
            server = self.env.config.get("cups.server")
            port = self.env.config.get("cups.port")
            user = self.env.config.get("cups.user")
            password = self.env.config.get("cups.password")
            encryption_policy = getattr(cups, "HTTP_ENCRYPT_%s" % self.env.config.get("cups.encryption-policy",
                                                                                      default="IF_REQUESTED").upper())
            if server is not None:
                cups.setServer(server)
            if port is not None:
                cups.setPort(int(port))
            if user is not None:
                cups.setUser(user)
            if encryption_policy is not None:
                cups.setEncryption(encryption_policy)

            if password is not None:
                def pw_callback(prompt):
                    return password

                cups.setPasswordCB(pw_callback)

            self.client = cups.Connection()

            sched = PluginRegistry.getInstance("SchedulerService").getScheduler()
            sched.add_interval_job(self.__gc, minutes=60, tag='_internal', jobstore="ram")
            sched.add_interval_job(self.__update_printer_list, minutes=30, tag='_internal', jobstore="ram")

        except RuntimeError as e:
            self.log.error(str(e))
            self.client = None
    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
Ejemplo 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
Ejemplo n.º 6
0
    def printit(self, username, printjob, printer):
        """Print a given document on the given printer

		requests.options = {}
		'username' -- owner of the print job
		'printjob' -- relative filename of the print job
		'printer' -- the printer to use (<hostname>://<printer>)

		return: <PDF document>
		"""

        path = self._get_path(username, printjob)

        try:
            spoolhost, printer = printer.split('://', 1)
        except ValueError:
            raise UMC_Error(_('Invalid printer URI'))

        if not os.path.exists(path):
            raise UMC_Error(
                _('File %r could not be printed as it does not exists (anymore).'
                  ) % (printjob, ))

        MODULE.process('Printing: %s' % path)
        self.pw_callback_bad_password = False
        try:
            cups.setUser(self.username)
            cups.setEncryption(cups.HTTP_ENCRYPT_ALWAYS)
            cups.setPasswordCB(self.pw_callback)
            conn = cups.Connection(spoolhost)
            conn.printFile(printer, path, Printjob.filename2label(printjob),
                           {})
        except RuntimeError:
            raise UMC_Error(
                _('Failed to connect to print server %(printserver)s.') %
                {'printserver': spoolhost})
        except cups.IPPError as (errno, description):
            IPP_AUTHENTICATION_CANCELED = 4096
            description = {
                cups.IPP_NOT_AUTHORIZED: _('No permission to print'),
                IPP_AUTHENTICATION_CANCELED: _('Wrong password'),
            }.get(errno, description)
            raise UMC_Error(
                _('Failed to print on %(printer)s: %(stderr)s (error %(errno)d).'
                  ) % {
                      'printer': printer,
                      'stderr': description,
                      'errno': errno
                  })
    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()
Ejemplo n.º 8
0
    def serve(self):
        try:
            server = self.env.config.get("cups.server")
            port = self.env.config.get("cups.port")
            user = self.env.config.get("cups.user")
            password = self.env.config.get("cups.password")
            encryption_policy = getattr(
                cups, "HTTP_ENCRYPT_%s" % self.env.config.get(
                    "cups.encryption-policy", default="IF_REQUESTED").upper())
            if server is not None:
                cups.setServer(server)
            if port is not None:
                cups.setPort(int(port))
            if user is not None:
                cups.setUser(user)
            if encryption_policy is not None:
                cups.setEncryption(encryption_policy)

            if password is not None:

                def pw_callback(prompt):
                    return password

                cups.setPasswordCB(pw_callback)

            self.client = cups.Connection()

            sched = PluginRegistry.getInstance(
                "SchedulerService").getScheduler()
            sched.add_interval_job(self.__gc,
                                   minutes=60,
                                   tag='_internal',
                                   jobstore="ram")
            sched.add_interval_job(self.__update_printer_list,
                                   minutes=30,
                                   tag='_internal',
                                   jobstore="ram")

        except RuntimeError as e:
            self.log.error(str(e))