Permalink
Browse files

Report default options not implemented yet rather than cause timeout

  • Loading branch information...
simoncadman committed Aug 4, 2012
1 parent 4eac8ec commit 534621afde34431dfa0c885dd60bc7fc22b8e189
Showing with 97 additions and 91 deletions.
  1. +97 −91 backend.py
View
@@ -20,8 +20,8 @@
progname = 'cloudprint'
def fileIsPDF ( filename ) :
- type = mimetypes.guess_type(filename)
- return type[0] == "application/pdf"
+ type = mimetypes.guess_type(filename)
+ return type[0] == "application/pdf"
if len(sys.argv) == 1:
print("network " + progname + " \"Unknown\" \"Google Cloud Print\"")
@@ -37,95 +37,101 @@ def fileIsPDF ( filename ) :
else:
prog, jobID, userName, jobTitle, copies, printOptions = sys.argv
-# if no printfile, put stdin to a temp file
-tempFile = None
-if printFile == None:
- tmpDir = os.getenv('TMPDIR')
- if not tmpDir:
- tmpDir = "/tmp"
- tempFile = tmpDir + '/' + jobID + '-' + userName + '-cupsjob-' + str(os.getpid())
-
- OUT = open (tempFile, 'w')
-
- if OUT == False:
- print("ERROR: Cannot write " + tempFile)
- sys.exit(1)
-
- for line in sys.stdin:
- OUT.write(line)
-
- OUT.close()
-
- printFile = tempFile
-
- # Backends should only produce multiple copies if a file name is
- # supplied (see CUPS Software Programmers Manual)
- copies = 1
-
-uri = os.getenv('DEVICE_URI')
-if uri == None:
- sys.stdout.write("URI must be \"cloudprint:/<cloud printer name>\"!\n")
- sys.exit(255)
-
try:
- logfile = open('/var/log/cups/cloudprint_log', 'a')
+ logfile = open('/var/log/cups/cloudprint_log', 'a')
except:
- logfile = sys.stdout
- logfile.write("Unable to write to log file /var/log/cups/cloudprint_log")
-
-logfile.write("Printing file " + printFile + "\n")
-
-def which(program):
- import os
- def is_exe(fpath):
- return os.path.exists(fpath) and os.access(fpath, os.X_OK)
-
- fpath, fname = os.path.split(program)
- if fpath:
- if is_exe(program):
- return program
- else:
- for path in os.environ["PATH"].split(os.pathsep):
- exe_file = os.path.join(path, program)
- if is_exe(exe_file):
- return exe_file
-
- return None
-
-pdfFile = printFile+".pdf"
-ps2PdfName = "ps2pdf"
-if which(ps2PdfName) == None:
- ps2PdfName = "pstopdf"
-
-submitjobpath = "/usr/lib/cloudprint-cups/" + "submitjob.py"
-if not os.path.exists( submitjobpath ):
- submitjobpath = "/usr/local/lib/cloudprint-cups/" + "submitjob.py"
-
-if not fileIsPDF( printFile ):
- sys.stderr.write( "INFO: Converting print job to PDF\n")
- subprocess.call([ps2PdfName, printFile, pdfFile])
- logfile.write("Running " + submitjobpath + "\n")
- logfile.write("Converted to PDF as "+ pdfFile + "\n")
+ logfile = sys.stdout
+ logfile.write("Unable to write to log file /var/log/cups/cloudprint_log")
+
+if sys.argv[3] == "Set Default Options":
+ print "ERROR: Unimplemented command: " + sys.argv[3]
+ logfile.write("ERROR: Unimplemented command: " + sys.argv[3]);
+ sys.exit(0)
else:
- logfile.write("Using " + printFile + " as is already PDF\n")
- pdfFile = printFile
-
-sys.stderr.write( "INFO: Sending document to Cloud Print\n")
-logfile.write("Sending "+ pdfFile + " to cloud\n")
-result = 0
-p = subprocess.Popen([submitjobpath, pdfFile, uri, jobTitle], stdout=subprocess.PIPE)
-output = p.communicate()[0]
-result = p.returncode
-sys.stderr.write(output)
-logfile.write(output)
-logfile.write(pdfFile + " sent to cloud print, deleting\n")
-if os.path.exists( printFile ):
- os.unlink( printFile )
-sys.stderr.write("INFO: Cleaning up temporary files\n")
-logfile.write("Deleted "+ printFile + "\n")
-if os.path.exists( pdfFile ):
- os.unlink( pdfFile )
-logfile.write("Deleted "+ pdfFile + "\n")
-logfile.close()
-sys.stderr.write("INFO: Printing Successful\n")
-sys.exit(result)
+ # if no printfile, put stdin to a temp file
+ tempFile = None
+ if printFile == None:
+ tmpDir = os.getenv('TMPDIR')
+ if not tmpDir:
+ tmpDir = "/tmp"
+ tempFile = tmpDir + '/' + jobID + '-' + userName + '-cupsjob-' + str(os.getpid())
+
+ OUT = open (tempFile, 'w')
+
+ if OUT == False:
+ print("ERROR: Cannot write " + tempFile)
+ sys.exit(1)
+
+ for line in sys.stdin:
+ OUT.write(line)
+
+ OUT.close()
+
+ printFile = tempFile
+
+ # Backends should only produce multiple copies if a file name is
+ # supplied (see CUPS Software Programmers Manual)
+ copies = 1
+
+ uri = os.getenv('DEVICE_URI')
+ if uri == None:
+ sys.stdout.write("URI must be \"cloudprint:/<cloud printer name>\"!\n")
+ sys.exit(255)
+
+ logfile.write("Printing file " + printFile + "\n")
+
+ def which(program):
+ import os
+ def is_exe(fpath):
+ return os.path.exists(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+
+ return None
+
+ pdfFile = printFile+".pdf"
+ ps2PdfName = "ps2pdf"
+ if which(ps2PdfName) == None:
+ ps2PdfName = "pstopdf"
+
+ submitjobpath = "/usr/lib/cloudprint-cups/" + "submitjob.py"
+ if not os.path.exists( submitjobpath ):
+ submitjobpath = "/usr/local/lib/cloudprint-cups/" + "submitjob.py"
+
+ if not fileIsPDF( printFile ):
+ sys.stderr.write( "INFO: Converting print job to PDF\n")
+ subprocess.call([ps2PdfName, printFile, pdfFile])
+ logfile.write("Running " + submitjobpath + "\n")
+ logfile.write("Converted to PDF as "+ pdfFile + "\n")
+ else:
+ logfile.write("Using " + printFile + " as is already PDF\n")
+ pdfFile = printFile
+
+ sys.stderr.write( "INFO: Sending document to Cloud Print\n")
+ logfile.write("Sending "+ pdfFile + " to cloud\n")
+ result = 0
+ p = subprocess.Popen([submitjobpath, pdfFile, uri, jobTitle], stdout=subprocess.PIPE)
+ output = p.communicate()[0]
+ result = p.returncode
+ sys.stderr.write(output)
+ logfile.write(output)
+ logfile.write(pdfFile + " sent to cloud print, deleting\n")
+ if os.path.exists( printFile ):
+ os.unlink( printFile )
+ sys.stderr.write("INFO: Cleaning up temporary files\n")
+ logfile.write("Deleted "+ printFile + "\n")
+ if os.path.exists( pdfFile ):
+ os.unlink( pdfFile )
+ logfile.write("Deleted "+ pdfFile + "\n")
+ logfile.close()
+ sys.stderr.write("INFO: Printing Successful\n")
+ sys.exit(result)
+

0 comments on commit 534621a

Please sign in to comment.