Exemple #1
0
    def _print_file(self, filename, mimetype, options):
        printer = options.strget("printer")
        title = options.strget("title")
        if title:
            printlog.info(" sending '%s' to printer '%s'", title, printer)
        else:
            printlog.info(" sending to printer '%s'", printer)
        print_options = options.dictget("options")
        #TODO: how do we print multiple copies?
        #copies = options.intget("copies")
        #whitelist of options we can forward:
        safe_print_options = dict((k, v) for k, v in print_options.items()
                                  if k in ("PageSize", "Resolution"))
        printlog("safe print options(%s) = %s", options, safe_print_options)
        from xpra.platform.printing import print_files, printing_finished, get_printers
        printers = get_printers()

        def delfile():
            if not DELETE_PRINTER_FILE:
                return
            try:
                os.unlink(filename)
            except:
                printlog("failed to delete print job file '%s'", filename)
            return False

        if not printer:
            printlog.error("Error: the printer name is missing")
            printlog.error(" printers available: %s",
                           csv(printers.keys()) or "none")
            delfile()
            return
        if printer not in printers:
            printlog.error("Error: printer '%s' does not exist!", printer)
            printlog.error(" printers available: %s",
                           csv(printers.keys()) or "none")
            delfile()
            return
        job = print_files(printer, [filename], title, options)
        printlog("printing %s, job=%s", filename, job)
        if job <= 0:
            printlog("printing failed and returned %i", job)
            delfile()
            return
        start = time.time()

        def check_printing_finished():
            done = printing_finished(job)
            printlog("printing_finished(%s)=%s", job, done)
            if done:
                delfile()
                return False
            if time.time() - start > 10 * 60:
                printlog.warn("print job %s timed out", job)
                delfile()
                return False
            return True  #try again..

        if check_printing_finished():
            self.timeout_add(10000, check_printing_finished)
Exemple #2
0
 def _print_file(self, filename, mimetype, options):
     printlog("print_file%s", (filename, mimetype, options))
     printer = options.strget("printer")
     title   = options.strget("title")
     copies  = options.intget("copies", 1)
     if title:
         printlog.info(" sending '%s' to printer '%s'", title, printer)
     else:
         printlog.info(" sending to printer '%s'", printer)
     from xpra.platform.printing import print_files, printing_finished, get_printers
     printers = get_printers()
     def delfile():
         if DELETE_PRINTER_FILE:
             try:
                 os.unlink(filename)
             except OSError:
                 printlog("failed to delete print job file '%s'", filename)
     if not printer:
         printlog.error("Error: the printer name is missing")
         printlog.error(" printers available: %s", csv(printers.keys()) or "none")
         delfile()
         return
     if printer not in printers:
         printlog.error("Error: printer '%s' does not exist!", printer)
         printlog.error(" printers available: %s", csv(printers.keys()) or "none")
         delfile()
         return
     try:
         job_options = options.dictget("options", {})
         job_options["copies"] = copies
         job = print_files(printer, [filename], title, job_options)
     except Exception as e:
         printlog("print_files%s", (printer, [filename], title, options), exc_info=True)
         printlog.error("Error: cannot print file '%s'", os.path.basename(filename))
         printlog.error(" %s", e)
         delfile()
         return
     printlog("printing %s, job=%s", filename, job)
     if job<=0:
         printlog("printing failed and returned %i", job)
         delfile()
         return
     start = monotonic_time()
     def check_printing_finished():
         done = printing_finished(job)
         printlog("printing_finished(%s)=%s", job, done)
         if done:
             delfile()
             return False
         if monotonic_time()-start>=PRINT_JOB_TIMEOUT:
             printlog.warn("Warning: print job %s timed out", job)
             delfile()
             return False
         return True #try again..
     if check_printing_finished():
         #check every 10 seconds:
         self.timeout_add(10000, check_printing_finished)
Exemple #3
0
 def _print_file(self, filename, mimetype, options):
     printer = options.strget("printer")
     title   = options.strget("title")
     copies  = options.intget("copies", 1)
     if title:
         printlog.info(" sending '%s' to printer '%s'", title, printer)
     else:
         printlog.info(" sending to printer '%s'", printer)
     from xpra.platform.printing import print_files, printing_finished, get_printers
     printers = get_printers()
     def delfile():
         if not DELETE_PRINTER_FILE:
             return
         try:
             os.unlink(filename)
         except:
             printlog("failed to delete print job file '%s'", filename)
         return False
     if not printer:
         printlog.error("Error: the printer name is missing")
         printlog.error(" printers available: %s", csv(printers.keys()) or "none")
         delfile()
         return
     if printer not in printers:
         printlog.error("Error: printer '%s' does not exist!", printer)
         printlog.error(" printers available: %s", csv(printers.keys()) or "none")
         delfile()
         return
     try:
         job_options = options.get("options")
         job_options["copies"] = copies
         job = print_files(printer, [filename], title, job_options)
     except Exception as e:
         printlog("print_files%s", (printer, [filename], title, options), exc_info=True)
         printlog.error("Error: cannot print file '%s'", os.path.basename(filename))
         printlog.error(" %s", e)
         delfile()
         return
     printlog("printing %s, job=%s", filename, job)
     if job<=0:
         printlog("printing failed and returned %i", job)
         delfile()
         return
     start = time.time()
     def check_printing_finished():
         done = printing_finished(job)
         printlog("printing_finished(%s)=%s", job, done)
         if done:
             delfile()
             return False
         if time.time()-start>10*60:
             printlog.warn("print job %s timed out", job)
             delfile()
             return False
         return True #try again..
     if check_printing_finished():
         self.timeout_add(10000, check_printing_finished)
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
    def _print_file(self, filename, printer, title, options):
        import time
        from xpra.platform.printing import print_files, printing_finished, get_printers
        printers = get_printers()
        if printer not in printers:
            printlog.error("Error: printer '%s' does not exist!", printer)
            printlog.error(" printers available: %s",
                           printers.keys() or "none")
            return

        def delfile():
            if not DELETE_PRINTER_FILE:
                return
            try:
                os.unlink(filename)
            except:
                printlog("failed to delete print job file '%s'", filename)
            return False

        job = print_files(printer, [filename], title, options)
        printlog("printing %s, job=%s", filename, job)
        if job <= 0:
            printlog("printing failed and returned %i", job)
            delfile()
            return
        start = time.time()

        def check_printing_finished():
            done = printing_finished(job)
            printlog("printing_finished(%s)=%s", job, done)
            if done:
                delfile()
                return False
            if time.time() - start > 10 * 60:
                printlog.warn("print job %s timed out", job)
                delfile()
                return False
            return True  #try again..

        if check_printing_finished():
            self.timeout_add(10000, check_printing_finished)
Exemple #7
0
 def _print_file(self, filename, printer, title, options):
     import time
     from xpra.platform.printing import print_files, printing_finished, get_printers
     printers = get_printers()
     if printer not in printers:
         printlog.error("Error: printer '%s' does not exist!", printer)
         printlog.error(" printers available: %s", printers.keys() or "none")
         return
     def delfile():
         if not DELETE_PRINTER_FILE:
             return
         try:
             os.unlink(filename)
         except:
             printlog("failed to delete print job file '%s'", filename)
         return False
     job = print_files(printer, [filename], title, options)
     printlog("printing %s, job=%s", filename, job)
     if job<=0:
         printlog("printing failed and returned %i", job)
         delfile()
         return
     start = time.time()
     def check_printing_finished():
         done = printing_finished(job)
         printlog("printing_finished(%s)=%s", job, done)
         if done:
             delfile()
             return False
         if time.time()-start>10*60:
             printlog.warn("print job %s timed out", job)
             delfile()
             return False
         return True #try again..
     if check_printing_finished():
         self.timeout_add(10000, check_printing_finished)