Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merged submitjob.py script into backend script

  • Loading branch information
simoncadman committed Feb 2, 2014
1 parent 5d210ad commit 480ad01f9017b7a280a8d9be2d867cf5e7a98e80
@@ -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)
@@ -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)

@@ -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)

@@ -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)

@@ -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)

@@ -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
@@ -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)

@@ -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)

This file was deleted.

@@ -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.
You can’t perform that action at this time.