Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Commit

Permalink
Fixed ppd names to contain id, upgrade script adds id to uris
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncadman committed Feb 21, 2014
1 parent 4b99f3f commit 90f5cc1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend.py
Expand Up @@ -22,7 +22,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print CUPS Backend Version " + CCPVersion
sys.exit(0)

Expand Down
2 changes: 1 addition & 1 deletion deleteaccount.py
Expand Up @@ -22,7 +22,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Delete Account Script Version " + CCPVersion
sys.exit(0)

Expand Down
6 changes: 3 additions & 3 deletions dynamicppd.py
Expand Up @@ -20,7 +20,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Dynamic PPD Generator Version " + CCPVersion
sys.exit(0)

Expand Down Expand Up @@ -55,7 +55,7 @@ def showUsage():
print "ERROR: No Printers Found"
sys.exit(1)
for foundprinter in printers:
print '"cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '.ppd" en "Google" "' + foundprinter['name'].encode('ascii', 'replace') + ' (' + foundprinter['account'] + ')" "MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:' + printer.printerNameToUri( foundprinter['account'], foundprinter['name'], foundprinter['id'] ) +';"'
print '"cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '-' + foundprinter['id'].encode('ascii', 'replace').replace(' ', '-') + '.ppd" en "Google" "' + foundprinter['name'].encode('ascii', 'replace') + ' (' + foundprinter['account'] + ')" "MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:' + printer.printerNameToUri( foundprinter['account'], foundprinter['name'], foundprinter['id'] ) +';"'

elif sys.argv[1] == 'cat':
if len(sys.argv) == 2 or sys.argv[2] == "":
Expand All @@ -80,7 +80,7 @@ def showUsage():

# find printer
for foundprinter in printers:
if ppdname == 'cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '.ppd':
if ppdname == 'cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '-' + foundprinter['id'].encode('ascii', 'replace').replace(' ', '-') + '.ppd':
capabilities = []
# generate and output ppd
language = "en"
Expand Down
2 changes: 1 addition & 1 deletion listcloudprinters.py
Expand Up @@ -26,7 +26,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Printer Lister Version " + CCPVersion
sys.exit(0)

Expand Down
2 changes: 1 addition & 1 deletion listdrivefiles.py
Expand Up @@ -22,7 +22,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Printer Drive Lister Version " + CCPVersion
sys.exit(0)

Expand Down
9 changes: 5 additions & 4 deletions printer.py
Expand Up @@ -40,10 +40,11 @@ def __init__( self, requestors ):
Args:
requestors: list or cloudprintrequestor instance, A list of requestors, or a single requestor to use for all Cloud Print requests.
"""
if isinstance(requestors, list):
self.requestors = requestors
else:
self.requestors = [requestors]
if requestors != None:
if isinstance(requestors, list):
self.requestors = requestors
else:
self.requestors = [requestors]

def getCUPSPrintersForAccount(self, account):
import cups
Expand Down
4 changes: 2 additions & 2 deletions reportissues.py
Expand Up @@ -21,7 +21,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Issue Reporting Script Version " + CCPVersion
sys.exit(0)

Expand All @@ -47,7 +47,7 @@
print ""
print foundprinter['fulldetails']
print "\n"
p = subprocess.Popen([os.path.join(libpath,'dynamicppd.py'), 'cat', ('cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '.ppd').lstrip('-')], stdout=subprocess.PIPE)
p = subprocess.Popen([os.path.join(libpath,'dynamicppd.py'), 'cat', ('cupscloudprint:' + foundprinter['account'].encode('ascii', 'replace').replace(' ', '-') +':' + foundprinter['name'].encode('ascii', 'replace').replace(' ', '-') + '-' + foundprinter['id'].encode('ascii', 'replace').replace(' ', '-') + '.ppd').lstrip('-')], stdout=subprocess.PIPE)
ppddata = p.communicate()[0]
result = p.returncode
tempfile = open('/tmp/.ppdfile', 'w')
Expand Down
2 changes: 1 addition & 1 deletion setupcloudprint.py
Expand Up @@ -22,7 +22,7 @@

if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"
print "CUPS Cloud Print Setup Script Version " + CCPVersion
sys.exit(0)

Expand Down
35 changes: 31 additions & 4 deletions upgrade.py
Expand Up @@ -17,12 +17,13 @@

if __name__ == '__main__': # pragma: no cover

import sys, cups, subprocess, os, json, logging
import sys, cups, subprocess, os, json, logging, urllib
from oauth2client import client
from oauth2client import multistore_file
from auth import Auth

from ccputils import Utils
from printer import Printer
Utils.SetupLogging()

try:
Expand All @@ -32,8 +33,15 @@
except:
logging.warning("Failed to change ownerships and permissions of logfile")

requestors, storage = Auth.SetupAuth(False)
if requestors == False:
sys.stderr.write("ERROR: config is invalid or missing\n")
logging.error("backend tried to run with invalid config");
sys.exit(1)
printerItem = Printer(requestors)

# line below is replaced on commit
CCPVersion = "20140221 192004"
CCPVersion = "20140221 220925"

if len(sys.argv) == 2 and sys.argv[1] == 'version':
print "CUPS Cloud Print Upgrade Script Version " + CCPVersion
Expand Down Expand Up @@ -79,8 +87,27 @@
for device in cupsprinters:
try:
if ( cupsprinters[device]["device-uri"].find("cloudprint://") == 0 ):
print "Updating " + cupsprinters[device]["printer-info"]
printername, account, printerid = printerItem.parseURI(cupsprinters[device]["device-uri"])
if printerid == None:
# update with new uri
print "Updating " + cupsprinters[device]["printer-info"], "with new id uri format"
printerid, requestor = printerItem.getPrinterIDByURI(cupsprinters[device]["device-uri"])
if printerid != None:
newDeviceURI = printerItem.printerNameToUri(urllib.unquote(account), urllib.unquote(printername), printerid)
cupsprinters[device]["device-uri"] = newDeviceURI
p = subprocess.Popen(["lpadmin", "-p", cupsprinters[device]["printer-info"].lstrip('-'), "-v", newDeviceURI], stdout=subprocess.PIPE)
output = p.communicate()[0]
result = p.returncode
sys.stderr.write(output)
else:
print cupsprinters[device]["printer-info"], "not found, you should delete and re-add this printer"
continue
else:
print "Updating " + cupsprinters[device]["printer-info"]

ppdid = 'MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:' + cupsprinters[device]["device-uri"] + ';'

# just needs updating
printerppdname = None
for ppd in allppds:
if allppds[ppd]['ppd-device-id'] == ppdid:
Expand All @@ -91,6 +118,6 @@
result = p.returncode
sys.stderr.write(output)
else:
print cupsprinters[device]["printer-info"] + " not found"
print cupsprinters[device]["printer-info"], "not found, you should delete and re-add this printer"
except Exception, e:
sys.stderr.write("Error connecting to CUPS: " + str(e) + "\n")

0 comments on commit 90f5cc1

Please sign in to comment.