示例#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)
示例#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)
示例#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)
示例#4
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)
示例#5
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)