Permalink
Browse files

Only parse newest URI format

  • Loading branch information...
simoncadman committed Mar 8, 2014
1 parent 396f882 commit 539ca2efa4092bcaa58d0816b525cc465054d998
Showing with 40 additions and 71 deletions.
  1. +2 −2 backend.py
  2. +1 −1 deleteaccount.py
  3. +3 −3 dynamicppd.py
  4. +2 −2 listcloudprinters.py
  5. +1 −1 listdrivefiles.py
  6. +5 −18 printer.py
  7. +2 −2 reportissues.py
  8. +4 −4 setupcloudprint.py
  9. +17 −35 test_printer.py
  10. +3 −3 upgrade.py
View
@@ -22,7 +22,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print CUPS Backend Version " + CCPVersion
sys.exit(0)
@@ -51,7 +51,7 @@
try:
if printers != None:
for foundprinter in printers:
- print "network " + printer.printerNameToUri(foundprinter['account'], foundprinter['name'], foundprinter['id']) + " " + "\"" + foundprinter['name'] + "\" \"Google Cloud Print\"" + " \"MFG:Google;MDL:Cloud Print;DES:GoogleCloudPrint;\""
+ print "network " + printer.printerNameToUri(foundprinter['account'], foundprinter['id']) + " " + "\"" + foundprinter['name'] + "\" \"Google Cloud Print\"" + " \"MFG:Google;MDL:Cloud Print;DES:GoogleCloudPrint;\""
except Exception as error:
print error
pass
View
@@ -22,7 +22,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Delete Account Script Version " + CCPVersion
sys.exit(0)
View
@@ -20,7 +20,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Dynamic PPD Generator Version " + CCPVersion
sys.exit(0)
@@ -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(' ', '-') + '-' + 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'] ) +';"'
+ 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['id'] ) +';"'
elif sys.argv[1] == 'cat':
if len(sys.argv) == 2 or sys.argv[2] == "":
@@ -122,7 +122,7 @@ def showUsage():
*LandscapeOrientation: Minus90
*TTRasterizer: Type42
*% Driver-defined attributes...
-*1284DeviceID: "MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:""" + printer.printerNameToUri( foundprinter['account'], foundprinter['name'], foundprinter['id'] ) + """;"
+*1284DeviceID: "MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:""" + printer.printerNameToUri( foundprinter['account'], foundprinter['id'] ) + """;"
*OpenUI *PageSize/Media Size: PickOne
*""" + language + """.Translation PageSize/Media Size: ""
*OrderDependency: 10 AnySetup *PageSize
View
@@ -26,7 +26,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Printer Lister Version " + CCPVersion
sys.exit(0)
@@ -41,4 +41,4 @@
printerName = foundprinter['name']
if 'displayName' in foundprinter:
printerName = foundprinter['displayName']
- print printerName.encode('ascii', 'replace') + ' - ' + printer.printerNameToUri(foundprinter['account'], foundprinter['name'], foundprinter['id']) + " - " + foundprinter['account']
+ print printerName.encode('ascii', 'replace') + ' - ' + printer.printerNameToUri(foundprinter['account'], foundprinter['id']) + " - " + foundprinter['account']
View
@@ -22,7 +22,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Printer Drive Lister Version " + CCPVersion
sys.exit(0)
View
@@ -88,7 +88,7 @@ def getPrinters(self, fulldetails = False, accountName=None, printerName=None ):
def sanitizeText(self, text):
return text.replace('/','-').replace(':','_').replace(';','_').replace(' ','_').encode('utf8', 'ignore')
- def printerNameToUri( self, account, printer, printerid=None ) :
+ def printerNameToUri( self, account, printerid ) :
"""Generates a URI for the Cloud Print Printer
Args:
@@ -98,10 +98,7 @@ def printerNameToUri( self, account, printer, printerid=None ) :
Returns:
string: URI for the printer
"""
- if printerid == None:
- return self.PROTOCOL + urllib.quote(printer.encode('ascii', 'replace')) + "/" + urllib.quote(account.encode('ascii', 'replace'))
- else:
- return self.PROTOCOL + urllib.quote(printer.encode('ascii', 'replace')) + "/" + urllib.quote(account.encode('ascii', 'replace')) + "/" + urllib.quote(printerid.encode('ascii', 'replace'))
+ return self.PROTOCOL + urllib.quote(account.encode('ascii', 'replace')) + "/" + urllib.quote(printerid.encode('ascii', 'replace'))
def sanitizePrinterName ( self, name ) :
@@ -161,11 +158,8 @@ def parseURI( self, uristring ):
"""
uri = urlparse(uristring)
pathparts = uri.path.split('/')
- accountName = pathparts[1]
- printerId = None
- if len(pathparts) > 2:
- printerId = pathparts[2]
- return uri.netloc, accountName, printerId
+ printerId = pathparts[1]
+ return uri.netloc, printerId
def findRequestorForAccount(self, account):
"""Searches the requestors in the printer object for the requestor for a specific account
@@ -188,21 +182,14 @@ def getPrinterIDByURI(self, uri):
printer id: Single requestor object for the account, or None if no account found
requestor: Single requestor object for the account
"""
- printername, account, printerid = self.parseURI(uri)
+ account, printerid = self.parseURI(uri)
# find requestor based on account
requestor = self.findRequestorForAccount(urllib.unquote(account))
if requestor == None:
return None, None
if printerid != None:
return printerid, requestor
-
- responseobj = requestor.doRequest('search?connection_status=ALL&client=webui&q=%s' % (printername))
- printername = urllib.unquote(printername)
- if 'printers' in responseobj and len(responseobj['printers']) > 0:
- for printerdetail in responseobj['printers']:
- if printername == printerdetail['name']:
- return printerdetail['id'], requestor
else:
return None, None
View
@@ -21,7 +21,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Issue Reporting Script Version " + CCPVersion
sys.exit(0)
@@ -43,7 +43,7 @@
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(' ', '-') + '.ppd" en "Google" "' + foundprinter['name'].encode('ascii', 'replace') + ' (' + foundprinter['account'] + ')" "MFG:GOOGLE;DRV:GCP;CMD:POSTSCRIPT;MDL:' + printer.printerNameToUri( foundprinter['account'], foundprinter['id'] ) +';"'
print ""
print foundprinter['fulldetails']
print "\n"
View
@@ -22,7 +22,7 @@
if len(sys.argv) == 2 and sys.argv[1] == 'version':
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
print "CUPS Cloud Print Setup Script Version " + CCPVersion
sys.exit(0)
@@ -101,7 +101,7 @@
print "Not using prefix"
printername = prefix + ccpprinter['name'].encode('ascii', 'replace')
- uri = printer.printerNameToUri(ccpprinter['account'], ccpprinter['name'], ccpprinter['id'])
+ uri = printer.printerNameToUri(ccpprinter['account'], ccpprinter['id'])
found = False
for cupsprinter in cupsprinters:
if cupsprinters[cupsprinter]['device-uri'] == uri:
@@ -131,7 +131,7 @@
print "Not using prefix"
for ccpprinter in printers:
- uri = printer.printerNameToUri(ccpprinter['account'], ccpprinter['name'], ccpprinter['id'])
+ uri = printer.printerNameToUri(ccpprinter['account'], ccpprinter['id'])
found = False
for cupsprinter in cupsprinters:
if cupsprinters[cupsprinter]['device-uri'] == uri:
@@ -171,7 +171,7 @@
printer = Printer(requestors)
printers = printer.getPrinters()
for foundprinter in printers:
- printeruris.append(printer.printerNameToUri(foundprinter['account'], foundprinter['name'], foundprinter['id']))
+ printeruris.append(printer.printerNameToUri(foundprinter['account'], foundprinter['id']))
# check for printers to prune
prunePrinters = []
View
@@ -53,14 +53,8 @@ def teardown_function(function):
def test_parseURI():
global printerItem, requestors
- printername, account, printerid = printerItem.parseURI("cloudprint://Save%20to%20Google%20Docs/testaccount")
- assert printername == "Save%20to%20Google%20Docs"
- assert account == "testaccount"
- assert printerid == None
-
- printername, account, printerid = printerItem.parseURI("cloudprint://Save%20to%20Google%20Docs/testaccount/testid")
- assert printername == "Save%20to%20Google%20Docs"
- assert account == "testaccount"
+ account, printerid = printerItem.parseURI("cloudprint://testaccount2%40gmail.com/testid")
+ assert account == "testaccount2%40gmail.com"
assert printerid == "testid"
def test_getCUPSPrintersForAccount():
@@ -80,8 +74,8 @@ def test_getCUPSPrintersForAccount():
printers = printerItem.getPrinters()
assert len(printers) == totalPrinters
printer = printers[0]
- uri = printerItem.printerNameToUri(requestors[1].getAccount(), printer['name'])
- printername, account, printerid = printerItem.parseURI(uri)
+ uri = printerItem.printerNameToUri(requestors[1].getAccount(), printer['id'])
+ account, printerid = printerItem.parseURI(uri)
printerId, requestor = printerItem.getPrinterIDByURI(uri)
# get ppd
@@ -90,10 +84,10 @@ def test_getCUPSPrintersForAccount():
printerppdname, printerppd = ppds.popitem()
# test add printer to cups
- assert printerItem.addPrinter( printername, uri, connection, printerppdname) != None
+ assert printerItem.addPrinter( printer['name'], uri, connection, printerppdname) != None
foundprinters, newconnection = printerItem.getCUPSPrintersForAccount(requestors[1].getAccount())
# delete test printer
- connection.deletePrinter( printerItem.sanitizePrinterName(printername) )
+ connection.deletePrinter( printerItem.sanitizePrinterName(printer['name']) )
assert isinstance(foundprinters, list)
assert len(foundprinters) == 1
@@ -124,8 +118,8 @@ def test_getCapabilities():
printers = printerItem.getPrinters()
printer = printers[0]
- uri = printerItem.printerNameToUri(requestors[1].getAccount(), printer['name'])
- printername, account, printerid = printerItem.parseURI(uri)
+ uri = printerItem.printerNameToUri(requestors[1].getAccount(), printer['id'])
+ account, printerid = printerItem.parseURI(uri)
printerId, requestor = printerItem.getPrinterIDByURI(uri)
# get ppd
@@ -134,16 +128,16 @@ def test_getCapabilities():
printerppdname, printerppd = ppds.popitem()
# add test printer to cups
- assert printerItem.addPrinter( printername, uri, connection, printerppdname) != None
+ assert printerItem.addPrinter( printer['name'], uri, connection, printerppdname) != None
foundprinters, newconnection = printerItem.getCUPSPrintersForAccount(requestors[1].getAccount())
- emptyoptions = printerItem.getCapabilities( printerId, printerItem.sanitizePrinterName(printername), "" )
+ emptyoptions = printerItem.getCapabilities( printerId, printerItem.sanitizePrinterName(printer['name']), "" )
assert isinstance(emptyoptions, dict)
assert isinstance(emptyoptions['capabilities'], list)
assert len(emptyoptions['capabilities']) == 0
# delete test printer
- connection.deletePrinter( printerItem.sanitizePrinterName(printername) )
+ connection.deletePrinter( printerItem.sanitizePrinterName(printer['name']) )
def test_GetPrinterIDByURIFails ( ):
global printerItem, requestors
@@ -233,30 +227,18 @@ def test_printers():
assert len(printer['id']) > 0
# test encoding and decoding printer details to/from uri
- uritest = re.compile("cloudprint://(.*)/" + urllib.quote( printer['account'] ) + "/" + urllib.quote( printer['id']) )
- uri = printerItem.printerNameToUri(printer['account'], printer['name'], printer['id'])
+ uritest = re.compile("cloudprint://(.*)/" + urllib.quote( printer['id']) )
+ uri = printerItem.printerNameToUri(printer['account'], printer['id'])
assert isinstance(uri, str) or isinstance(uri, unicode)
assert len(uri) > 0
assert uritest.match(uri) != None
- uritest = re.compile("cloudprint://(.*)/" + urllib.quote( printer['account'] ))
- uri = printerItem.printerNameToUri(printer['account'], printer['name'])
- assert isinstance(uri, str)
- assert len(uri) > 0
- assert uritest.match(uri) != None
-
- printername, account, printerid = printerItem.parseURI(uri)
- assert isinstance(printername, str)
- assert urllib.unquote(printername) == printer['name']
+ account, printerid = printerItem.parseURI(uri)
assert isinstance(account, str)
assert urllib.unquote(account) == printer['account']
- printerId, requestor = printerItem.getPrinterIDByURI(uri + "/testprinterid")
- assert printerId == "testprinterid"
- assert isinstance(requestor, MockRequestor)
-
printerId, requestor = printerItem.getPrinterIDByURI(uri)
- assert isinstance(printerId, unicode)
+ assert isinstance(printerId, str)
assert isinstance(requestor, MockRequestor)
# get ppd
@@ -265,8 +247,8 @@ def test_printers():
printerppdname, printerppd = ppds.popitem()
# test add printer to cups
- assert printerItem.addPrinter( printername, uri, connection, printerppdname) != None
- testprintername = printerItem.sanitizePrinterName(printername)
+ assert printerItem.addPrinter( printer['name'], uri, connection, printerppdname) != None
+ testprintername = printerItem.sanitizePrinterName(printer['name'])
# test printer actually added to cups
cupsPrinters = connection.getPrinters()
View
@@ -39,7 +39,7 @@
printerItem = Printer(requestors)
# line below is replaced on commit
- CCPVersion = "20140223 234321"
+ CCPVersion = "20140308 012527"
if len(sys.argv) == 2 and sys.argv[1] == 'version':
print "CUPS Cloud Print Upgrade Script Version " + CCPVersion
@@ -85,13 +85,13 @@
for device in cupsprinters:
try:
if ( cupsprinters[device]["device-uri"].find("cloudprint://") == 0 ):
- printername, account, printerid = printerItem.parseURI(cupsprinters[device]["device-uri"])
+ 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)
+ newDeviceURI = printerItem.printerNameToUri(urllib.unquote(account), 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]

0 comments on commit 539ca2e

Please sign in to comment.