def get_info(): from xpra.platform.printing import get_mimetypes, DEFAULT_MIMETYPES return { "mimetypes": { "": get_mimetypes(), "default": DEFAULT_MIMETYPES, "printers": MIMETYPE_TO_PRINTER, "ppd": MIMETYPE_TO_PPD }, "mimetype": { "default": DEFAULT_MIMETYPE }, "simulate-failure": SIMULATE_PRINT_FAILURE, "raw-mode": RAW_MODE, "generic": GENERIC, "tmpdir": FORWARDER_TMPDIR, "lpadmin": LPADMIN, "lpinfo": LPINFO, "forwarder": FORWARDER_BACKEND, "skipped-printers": SKIPPED_PRINTERS, "add-local-printers": ADD_LOCAL_PRINTERS, "printer-prefix": PRINTER_PREFIX, "cups-dbus": { "": CUPS_DBUS, "default": DEFAULT_CUPS_DBUS, "poll-delay": POLLING_DELAY }, "cups.default-options": DEFAULT_CUPS_OPTIONS, "printers": { "": get_printer_definitions(), "predefined": UNPROBED_PRINTER_DEFS }, }
def get_info(): from xpra.platform.printing import get_mimetypes, DEFAULT_MIMETYPES return { "mimetypes": { "": get_mimetypes(), "default": DEFAULT_MIMETYPES, "printers": MIMETYPE_TO_PRINTER, "ppd": MIMETYPE_TO_PPD, }, "mimetype": {"default": DEFAULT_MIMETYPE}, "simulate-failure": SIMULATE_PRINT_FAILURE, "allow-user": ALLOW, "raw-mode": RAW_MODE, "generic": GENERIC, "tmpdir": FORWARDER_TMPDIR, "lpadmin": LPADMIN, "lpinfo": LPINFO, "forwarder": FORWARDER_BACKEND, "skipped-printers": SKIPPED_PRINTERS, "add-local-printers": ADD_LOCAL_PRINTERS, "printer-prefix": PRINTER_PREFIX, "cups-dbus": {"": CUPS_DBUS, "default": DEFAULT_CUPS_DBUS, "poll-delay": POLLING_DELAY}, "cups.default-options": DEFAULT_CUPS_OPTIONS, "printers": {"": get_printer_definitions(), "predefined": UNPROBED_PRINTER_DEFS}, }
def do_send_printers(self): try: self.send_printers_pending = False from xpra.platform.printing import get_printers, get_mimetypes printers = get_printers() printlog("do_send_printers() found printers=%s", printers) #remove xpra-forwarded printers to avoid loops and multi-forwards, #also ignore stopped printers #and only keep the attributes that the server cares about (self.printer_attributes) exported_printers = {} def used_attrs(d): #filter attributes so that we only compare things that are actually used if not d: return d return dict((k,v) for k,v in d.items() if k in self.printer_attributes) for k,v in printers.items(): device_uri = v.get("device-uri", "") if device_uri: #this is cups specific.. oh well printlog("do_send_printers() device-uri(%s)=%s", k, device_uri) if device_uri.startswith("xpraforwarder"): printlog("do_send_printers() skipping xpra forwarded printer=%s", k) continue state = v.get("printer-state") #"3" if the destination is idle, #"4" if the destination is printing a job, #"5" if the destination is stopped. if state==5: printlog("do_send_printers() skipping stopped printer=%s", k) continue attrs = used_attrs(v) #add mimetypes: attrs["mimetypes"] = get_mimetypes() exported_printers[k.encode("utf8")] = attrs if self.exported_printers is None: #not been sent yet, ensure we can use the dict below: self.exported_printers = {} elif exported_printers==self.exported_printers: printlog("do_send_printers() exported printers unchanged: %s", self.exported_printers) return #show summary of what has changed: added = [k for k in exported_printers.keys() if k not in self.exported_printers] if added: printlog("do_send_printers() new printers: %s", added) removed = [k for k in self.exported_printers.keys() if k not in exported_printers] if removed: printlog("do_send_printers() printers removed: %s", removed) modified = [k for k,v in exported_printers.items() if self.exported_printers.get(k)!=v and k not in added] if modified: printlog("do_send_printers() printers modified: %s", modified) printlog("do_send_printers() printers=%s", exported_printers.keys()) printlog("do_send_printers() exported printers=%s", ", ".join(str(x) for x in exported_printers.keys())) self.exported_printers = exported_printers self.send("printers", self.exported_printers) except: log.error("do_send_printers()", exc_info=True)
def do_send_printers(self): try: self.send_printers_timer = None from xpra.platform.printing import get_printers, get_mimetypes printers = get_printers() printlog("do_send_printers() found printers=%s", printers) #remove xpra-forwarded printers to avoid loops and multi-forwards, #also ignore stopped printers #and only keep the attributes that the server cares about (self.printer_attributes) exported_printers = {} def used_attrs(d): #filter attributes so that we only compare things that are actually used if not d: return d return dict((k,v) for k,v in d.items() if k in self.printer_attributes) for k,v in printers.items(): device_uri = v.get("device-uri", "") if device_uri: #this is cups specific.. oh well printlog("do_send_printers() device-uri(%s)=%s", k, device_uri) if device_uri.startswith("xpraforwarder"): printlog("do_send_printers() skipping xpra forwarded printer=%s", k) continue state = v.get("printer-state") #"3" if the destination is idle, #"4" if the destination is printing a job, #"5" if the destination is stopped. if state==5 and SKIP_STOPPED_PRINTERS: printlog("do_send_printers() skipping stopped printer=%s", k) continue attrs = used_attrs(v) #add mimetypes: attrs["mimetypes"] = get_mimetypes() exported_printers[k.encode("utf8")] = attrs if self.exported_printers is None: #not been sent yet, ensure we can use the dict below: self.exported_printers = {} elif exported_printers==self.exported_printers: printlog("do_send_printers() exported printers unchanged: %s", self.exported_printers) return #show summary of what has changed: added = [k for k in exported_printers.keys() if k not in self.exported_printers] if added: printlog("do_send_printers() new printers: %s", added) removed = [k for k in self.exported_printers.keys() if k not in exported_printers] if removed: printlog("do_send_printers() printers removed: %s", removed) modified = [k for k,v in exported_printers.items() if self.exported_printers.get(k)!=v and k not in added] if modified: printlog("do_send_printers() printers modified: %s", modified) printlog("do_send_printers() printers=%s", exported_printers.keys()) printlog("do_send_printers() exported printers=%s", ", ".join(str(x) for x in exported_printers.keys())) self.exported_printers = exported_printers self.send("printers", self.exported_printers) except: printlog.error("do_send_printers()", exc_info=True)
def get_printer_definitions(): global PRINTER_DEF, PRINTER_DEF_LOCK, UNPROBED_PRINTER_DEFS, MIMETYPE_TO_PRINTER with PRINTER_DEF_LOCK: if PRINTER_DEF is not None: return PRINTER_DEF log("get_printer_definitions() UNPROBED_PRINTER_DEFS=%s, GENERIC=%s", UNPROBED_PRINTER_DEFS, GENERIC) from xpra.platform.printing import get_mimetypes mimetypes = get_mimetypes() #first add the user-supplied definitions: PRINTER_DEF = UNPROBED_PRINTER_DEFS.copy() #raw mode if supported: if RAW_MODE: PRINTER_DEF["raw"] = ["-o", "raw"] #now probe for generic printers via lpinfo: if GENERIC: for mt in mimetypes: if mt in PRINTER_DEF: continue #we have a pre-defined one already x = MIMETYPE_TO_PRINTER.get(mt) if not x: log.warn( "Warning: unknown mimetype '%s', cannot find printer definition", mt) continue drv = get_lpinfo_drv(x) if drv: #ie: ["-m", "drv:///sample.drv/generic.ppd"] PRINTER_DEF[mt] = ["-m", drv] #fallback to locating ppd files: for mt in mimetypes: if mt in PRINTER_DEF: continue #we have a generic or pre-defined one already x = MIMETYPE_TO_PPD.get(mt) if not x: log.warn( "Warning: unknown mimetype '%s', cannot find corresponding PPD file", mt) continue f = find_ppd_file(mt.replace("application/", "").upper(), x) if f: #ie: ["-P", "/usr/share/cups/model/Generic-PDF_Printer-PDF.ppd"] PRINTER_DEF[mt] = ["-P", f] log("pycups settings: PRINTER_DEF=%s", PRINTER_DEF) return PRINTER_DEF
def get_printer_definitions(): global PRINTER_DEF, PRINTER_DEF_LOCK, UNPROBED_PRINTER_DEFS, MIMETYPE_TO_PRINTER with PRINTER_DEF_LOCK: if PRINTER_DEF is not None: return PRINTER_DEF log("get_printer_definitions() UNPROBED_PRINTER_DEFS=%s, GENERIC=%s", UNPROBED_PRINTER_DEFS, GENERIC) from xpra.platform.printing import get_mimetypes mimetypes = get_mimetypes() # first add the user-supplied definitions: PRINTER_DEF = UNPROBED_PRINTER_DEFS.copy() # raw mode if supported: if RAW_MODE: PRINTER_DEF["raw"] = ["-o", "raw"] # now probe for generic printers via lpinfo: if GENERIC: for mt in mimetypes: if mt in PRINTER_DEF: continue # we have a pre-defined one already x = MIMETYPE_TO_PRINTER.get(mt) if not x: log.warn("Warning: unknown mimetype '%s', cannot find printer definition", mt) continue drv = get_lpinfo_drv(x) if drv: # ie: ["-m", "drv:///sample.drv/generic.ppd"] PRINTER_DEF[mt] = ["-m", drv] # fallback to locating ppd files: for mt in mimetypes: if mt in PRINTER_DEF: continue # we have a generic or pre-defined one already x = MIMETYPE_TO_PPD.get(mt) if not x: log.warn("Warning: unknown mimetype '%s', cannot find corresponding PPD file", mt) continue f = find_ppd_file(mt.replace("application/", "").upper(), x) if f: # ie: ["-P", "/usr/share/cups/model/Generic-PDF_Printer-PDF.ppd"] PRINTER_DEF[mt] = ["-P", f] log("pycups settings: PRINTER_DEF=%s", PRINTER_DEF) return PRINTER_DEF