[ Avaa Bypassed ]




Upload:

Command:

www-data@18.190.217.76: ~ $
#!/usr/bin/python

## system-config-printer

## Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
## Authors:
##  Tim Waugh <twaugh@redhat.com>
##  Till Kamppeter <till.kamppeter@gmail.com>

## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# config is generated from config.py.in by configure
import config

import cupshelpers
from debug import *

from gi.repository import GObject

class OpenPrintingRequest(GObject.GObject):
    __gsignals__ = {
        'finished':     (GObject.SignalFlags.RUN_LAST, None,
                         (
                             # list of (printerid,name) tuples
                             GObject.TYPE_PYOBJECT,

                             # dict of printerid: dict of drivername: dict
                             # for driver info
                             GObject.TYPE_PYOBJECT,
                         )),

        'error':        (GObject.SignalFlags.RUN_LAST, None,
                         (
                             # HTTP status
                             int,

                             GObject.TYPE_PYOBJECT,
                         )),
    }

    def __init__ (self, **args):
        GObject.GObject.__init__ (self)
        debugprint ("Starting")
        self.openprinting = cupshelpers.openprinting.OpenPrinting (**args)
        self._handle = None
        debugprint ("+%s" % self)

    def __del__ (self):
        debugprint ("-%s" % self)

    def cancel (self):
        debugprint ("%s: cancel()" % self)
        if self._handle is not None:
            self.openprinting.cancelOperation (self._handle)
            self._handle = None

        debugprint ("%s -> 'error'" % self)
        self.emit ('error', 0, 'canceled')

    def searchPrinters (self, searchterm, user_data=None):
        debugprint ("%s: searchPrinters()" % self)
        self._handle = self.openprinting.searchPrinters (searchterm,
                                                         self._printers_got,
                                                         user_data)

    def _printers_got (self, status, user_data, printers):
        self._handle = None
        if status != 0:
            debugprint ("%s -> 'error'" % self)
            self.emit ('error', status, printers)
            return

        self.downloadable_printers_unchecked = [(x, printers[x])
                                                for x in printers]
        self.downloadable_printers = []
        self.downloadable_drivers = dict() # by printer id of dict

        # Kick off a search for drivers for each model.
        if not self._query_next_printer ():
            self._drivers_got ()

    def _query_next_printer (self):
        """
        If there are more printers to query, kick off a query and
        return True.

        Otherwise return False.
        """

        try:
            user_data = self.downloadable_printers_unchecked.pop ()
            (printer_id, printer_name) = user_data
        except IndexError:
            debugprint ("%s: All printer driver queries finished" % self)
            return False

        if config.DOWNLOADABLE_ONLYFREE:
            self.openprinting.onlyfree = 1
        else:
            self.openprinting.onlyfree = 0

        options = dict()
        if config.DOWNLOADABLE_ONLYPPD:
            options['onlyppdfiles'] = '1'
        else:
            options['onlydownload'] = '1'
            options['packagesystem'] = config.packagesystem

        debugprint ("%s: Querying drivers for %s" % (self, printer_id))
        self._handle = self.openprinting.listDrivers (printer_id,
                                                      self._printer_drivers_got,
                                                      user_data=user_data,
                                                      extra_options=options)

        return True

    def _printer_drivers_got (self, status, user_data, drivers):
        self._handle = None
        if status != 0:
            debugprint ("%s -> 'error'" % self)
            self.emit ('error', status, drivers)
            return

        if drivers:
            debugprint ("%s: - drivers found" % self)
            drivers_installable = { }
            for driverkey in drivers.keys ():
                driver = drivers[driverkey]
                if (('ppds' in driver and
                     len(driver['ppds']) > 0) or
                    (not config.DOWNLOADABLE_ONLYPPD and
                     'packages' in driver and
                     len(driver['packages']) > 0)):
                    # Driver entry with installable resources (Package or
                    # PPD), overtake it
                    drivers_installable[driverkey] = drivers[driverkey]
                else:
                    debugprint ("Not using invalid driver entry %s" %
                                driverkey)

            if len(drivers_installable) > 0:
                debugprint ("%s: - drivers with installable resources found" %
                            self)
                (printer_id, printer_name) = user_data
                self.downloadable_drivers[printer_id] = drivers_installable
                self.downloadable_printers.append (user_data)

        if not self._query_next_printer ():
            self._drivers_got ()

    def _drivers_got (self):
        self._handle = None
        debugprint ("%s -> 'finished'" % self)
        self.emit ('finished',
                   self.downloadable_printers,
                   self.downloadable_drivers)

if __name__ == '__main__':
    from pprint import pprint
    mainloop = GObject.MainLoop ()
    set_debugging (True)
    cupshelpers.set_debugprint_fn (debugprint)
    req = OpenPrintingRequest ()
    handlers = []

    def done (obj):
        for handler in handlers:
            obj.disconnect (handler)

        GObject.timeout_add_seconds (1, mainloop.quit)

    def error (obj, status, err):
        print ("Error: %d" % status)
        print (repr (err))
        done (obj)

    def finished (obj, printers, drivers):
        pprint (printers)
        pprint (drivers)
        done (obj)

    handlers.append (req.connect ('error', error))
    handlers.append (req.connect ('finished', finished))
    GObject.idle_add (req.searchPrinters, 'ricoh 8000')
    mainloop.run ()
    del req

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
icons Folder 0755
troubleshoot Folder 0755
ui Folder 0755
xml Folder 0755
HIG.py File 57 B 0644
OpenPrintingRequest.py File 6.81 KB 0644
PhysicalDevice.py File 16.19 KB 0644
SearchCriterion.py File 1.32 KB 0644
ToolbarSearchEntry.py File 6.96 KB 0644
applet.py File 16.39 KB 0755
asyncconn.py File 9.6 KB 0644
asyncipp.py File 26.13 KB 0644
asyncpk1.py File 25.85 KB 0644
authconn.py File 18.85 KB 0644
check-device-ids.py File 11.16 KB 0755
config.py File 1.19 KB 0644
cupspk.py File 27.48 KB 0644
debug.py File 1.62 KB 0644
dnssdresolve.py File 4.66 KB 0644
errordialogs.py File 3.12 KB 0644
firewallsettings.py File 9.38 KB 0644
gtkinklevel.py File 4.71 KB 0644
gui.py File 2.13 KB 0644
install-printerdriver.py File 5.34 KB 0755
installpackage.py File 2.2 KB 0644
jobviewer.py File 97.36 KB 0644
killtimer.py File 2.08 KB 0644
monitor.py File 32.36 KB 0644
newprinter.py File 178.53 KB 0644
options.py File 18.97 KB 0644
optionwidgets.py File 8.89 KB 0644
ppdcache.py File 7.57 KB 0644
ppdippstr.py File 16.19 KB 0644
ppdsloader.py File 10.98 KB 0644
printerproperties.py File 78.11 KB 0644
probe_printer.py File 15.82 KB 0644
pysmb.py File 6.81 KB 0755
scp-dbus-service.py File 22.22 KB 0755
serversettings.py File 21.83 KB 0644
smburi.py File 3.22 KB 0644
statereason.py File 6.83 KB 0644
system-config-printer.py File 86.21 KB 0755
timedops.py File 8.21 KB 0644
userdefault.py File 6.2 KB 0644