Exemplo n.º 1
0
class PrinterDiscover(gobject.GObject):
    STYPE = '_pdl-datastream._tcp'

    SIGNAL = (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                (gobject.TYPE_PYOBJECT,))

    __gsignals__ = {
        'printer_discovered' : SIGNAL,
        'printer_losed' : SIGNAL,
    }

    def __init__(self):
        gobject.GObject.__init__(self)

        self.printers = {}
	self.discoverer = ServiceDiscover()

        self.discoverer.connect_service(PrinterDiscover.STYPE, self.discovered, self.losed)

    def get_printers(self):
        return self.printers.values()

    def discovered(self, *args):
	print args
        try:
            address, port, name, host, txt = self.discoverer.resolve(*args)
            mac = getoutput('arping -f -w 10 '+address+'|grep reply|awk \'{print $5}\'').strip('[[,]]')
        except Exception, err:
            print "Cant discover: ", err
            return
        printer = {'address': address, 'port': port, 'name': name, 'host': host, 'txt': txt, 'mac': mac}
        self.printers[args[:-1]] = printer
        self.emit('printer_discovered', printer)
Exemplo n.º 2
0
    def __init__(self):
        gobject.GObject.__init__(self)

        self.printers = {}
	self.discoverer = ServiceDiscover()

        self.discoverer.connect_service(PrinterDiscover.STYPE, self.discovered, self.losed)