Permalink
Browse files

Merged submitjob.py script into backend script

  • Loading branch information...
simoncadman committed Feb 2, 2014
1 parent 5d210ad commit 480ad01f9017b7a280a8d9be2d867cf5e7a98e80
View
@@ -20,7 +20,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print CUPS Backend Version " + CCPVersion
sys.exit(0)
@@ -62,19 +62,21 @@ def getBackendDescription ( ) :
if __name__ == '__main__': # pragma: no cover
+ libpath = "/usr/local/share/cloudprint-cups/"
+ if not os.path.exists( libpath ):
+ libpath = "/usr/share/cloudprint-cups"
+ sys.path.insert(0, libpath)
+
+ from auth import Auth
+ from printer import Printer
+ requestors, storage = Auth.SetupAuth(False)
+ printer = Printer(requestors)
+ printers = printer.getPrinters()
+
if len(sys.argv) == 1:
print getBackendDescription()
-
+
try:
- libpath = "/usr/local/share/cloudprint-cups/"
- if not os.path.exists( libpath ):
- libpath = "/usr/share/cloudprint-cups"
- sys.path.insert(0, libpath)
- from auth import Auth
- from printer import Printer
- requestors, storage = Auth.SetupAuth(False)
- printer = Printer(requestors)
- printers = printer.getPrinters()
if printers != None:
for foundprinter in printers:
print "network " + printer.printerNameToUri(foundprinter['account'], foundprinter['name']) + " " + "\"" + foundprinter['name'] + "\" \"Google Cloud Print\"" + " \"MFG:Google;MDL:Cloud Print;DES:GoogleCloudPrint;\""
@@ -149,14 +151,9 @@ def getBackendDescription ( ) :
ps2PdfName = "pstopdf"
convertToPDFParams = [ps2PdfName, printFile, pdfFile]
- submitjobpath = "/usr/share/cloudprint-cups/" + "submitjob.py"
- if not os.path.exists( submitjobpath ):
- submitjobpath = "/usr/local/share/cloudprint-cups/" + "submitjob.py"
-
if not fileIsPDF( printFile ):
sys.stderr.write( "INFO: Converting print job to PDF\n")
subprocess.call(convertToPDFParams)
- logging.info("Running " + submitjobpath)
logging.info("Converted to PDF as "+ pdfFile)
else:
pdfFile = printFile + '.pdf'
@@ -165,12 +162,21 @@ def getBackendDescription ( ) :
sys.stderr.write( "INFO: Sending document to Cloud Print\n")
logging.info("Sending "+ pdfFile + " to cloud")
+
result = 0
- p = subprocess.Popen([submitjobpath, pdfFile, jobTitle, uri, printername, printOptions], stdout=subprocess.PIPE)
- output = p.communicate()[0]
- result = p.returncode
- sys.stderr.write(output)
- logging.info(output.strip())
+ printerid, requestor = printer.getPrinterIDByURI(uri)
+ printer.requestor = requestor
+ if printerid == None:
+ print "ERROR: Printer '" + uri + "' not found"
+ result = 1
+ else:
+ if printer.submitJob(printerid, 'pdf', pdfFile, jobTitle, printername, printOptions ):
+ print "INFO: Successfully printed"
+ result = 0
+ else:
+ print "ERROR: Failed to submit job to cloud print"
+ result = 1
+
logging.info(pdfFile + " sent to cloud print, deleting")
if os.path.exists( printFile ):
os.unlink( printFile )
@@ -179,6 +185,10 @@ def getBackendDescription ( ) :
if os.path.exists( pdfFile ):
os.unlink( pdfFile )
logging.info("Deleted "+ pdfFile)
- sys.stderr.write("INFO: Printing Successful\n")
- logging.info("Completed printing")
+ if result != 0:
+ sys.stderr.write("INFO: Printing Failed\n")
+ logging.info("Failed printing")
+ else:
+ sys.stderr.write("INFO: Printing Successful\n")
+ logging.info("Completed printing")
sys.exit(result)
View
@@ -21,7 +21,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Delete Account Script Version " + CCPVersion
sys.exit(0)
View
@@ -19,7 +19,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Dynamic PPD Generator Version " + CCPVersion
sys.exit(0)
View
@@ -28,7 +28,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Printer Lister Version " + CCPVersion
sys.exit(0)
View
@@ -21,7 +21,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Printer Drive Lister Version " + CCPVersion
sys.exit(0)
View
@@ -24,7 +24,7 @@ if [[ ! -f /usr/bin/python2 ]]; then
fi
if [[ $pyversion != "" ]]; then
- sed -i "1 s/\/usr\/bin\/env python2$/\/usr\/bin\/env $pyversion/" /usr/share/cloudprint-cups/{backend.py,deleteaccount.py,dynamicppd.py,listcloudprinters.py,reportissues.py,setupcloudprint.py,submitjob.py,upgrade.py}
+ sed -i "1 s/\/usr\/bin\/env python2$/\/usr\/bin\/env $pyversion/" /usr/share/cloudprint-cups/{backend.py,deleteaccount.py,dynamicppd.py,listcloudprinters.py,reportissues.py,setupcloudprint.py,upgrade.py}
sed -i "1 s/\/usr\/bin\/env python2$/\/usr\/bin\/env $pyversion/" /usr/lib/cups/backend/cloudprint
sed -i "1 s/\/usr\/bin\/env python2$/\/usr\/bin\/env $pyversion/" /usr/lib/cups/driver/cupscloudprint
fi
@@ -19,7 +19,6 @@ lib/cloudprint-cups/listcloudprinters.py
lib/cloudprint-cups/printer.py
lib/cloudprint-cups/reportissues.py
lib/cloudprint-cups/setupcloudprint.py
-lib/cloudprint-cups/submitjob.py
lib/cloudprint-cups/test_auth.py
lib/cloudprint-cups/test_backend.py
lib/cloudprint-cups/test_cloudprintrequestor.py
@@ -59,7 +59,6 @@ python2 -m compileall -q -f .
%attr(755, root, lp) %{_usr}/share/cloudprint-cups/full-test.sh
%attr(755, root, lp) %{_usr}/share/cloudprint-cups/reportissues.py
%attr(755, root, lp) %{_usr}/share/cloudprint-cups/setupcloudprint.py
-%attr(755, root, lp) %{_usr}/share/cloudprint-cups/submitjob.py
%attr(755, root, lp) %{_usr}/share/cloudprint-cups/upgrade.py
%attr(644, root, lp) %{_usr}/share/cloudprint-cups/oauth2client/*.pyc
%attr(644, root, lp) %{_usr}/share/cloudprint-cups/oauth2client/*.pyo
View
@@ -19,7 +19,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Issue Reporting Script Version " + CCPVersion
sys.exit(0)
View
@@ -21,7 +21,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140202 021728"
+ CCPVersion = "20140202 151329"
print "CUPS Cloud Print Setup Script Version " + CCPVersion
sys.exit(0)
View
@@ -1,54 +0,0 @@
-#! /usr/bin/env python2
-# CUPS Cloudprint - Print via Google Cloud Print
-# Copyright (C) 2011 Simon Cadman
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import sys, logging
-from auth import Auth
-from printer import Printer
-
-logpath = '/var/log/cups/cloudprint_log'
-
-try:
- logging.basicConfig(filename=logpath,level=logging.INFO)
-except:
- logging.basicConfig(level=logging.INFO)
- logging.error("Unable to write to log file "+ logpath)
-
-if len(sys.argv) == 2 and sys.argv[1] == 'version':
- # line below is replaced on commit
- CCPVersion = "20140202 021728"
- print "CUPS Cloud Print Submit Job Version " + CCPVersion
- sys.exit(0)
-
-if ( len(sys.argv) < 6 ):
- sys.stderr.write("ERROR: Usage: " + sys.argv[0] + " pdf-file page-title printer-uri cups-printer-name options\n")
- sys.exit(1)
-
-requestors, storage = Auth.SetupAuth(False)
-printer = Printer(requestors)
-
-printerid, requestor = printer.getPrinterIDByURI(sys.argv[3])
-printer.requestor = requestor
-if printerid == None:
- print "ERROR: Printer '" + sys.argv[3] + "' not found"
- sys.exit(1)
-
-if printer.submitJob(printerid, 'pdf', sys.argv[1], sys.argv[2], sys.argv[4], sys.argv[5] ):
- print "INFO: Successfully printed"
- sys.exit(0)
-else:
- print "ERROR: Failed to submit job to cloud print"
- sys.exit(1)
View
@@ -41,7 +41,7 @@
sys.stderr.write("If you are upgrading from version 20131013 or earlier you should be aware that the scripts have moved from /usr/lib/cloudprint-cups to /usr/share/cloudprint-cups\n")
# line below is replaced on commit
-CCPVersion = "20140202 021728"
+CCPVersion = "20140202 151329"
if len(sys.argv) == 2 and sys.argv[1] == 'version':
print "CUPS Cloud Print Upgrade Script Version " + CCPVersion

0 comments on commit 480ad01

Please sign in to comment.