Skip to content
Permalink
Browse files

Use display name if available for generating values for ppd

  • Loading branch information
simoncadman committed Sep 7, 2013
1 parent f6a3398 commit e16306579ce13daf3dba8ae8c6755928fd2fb48a
Showing with 21 additions and 7 deletions.
  1. +2 −2 dynamicppd.py
  2. +19 −5 printer.py
@@ -128,7 +128,7 @@ def showUsage():
if 'capabilities' in foundprinter['fulldetails']:
for capability in foundprinter['fulldetails']['capabilities']:
originCapabilityName = None
internalcapabilityName = printer.getInternalName(capability['name'])
internalcapabilityName = printer.getInternalName(capability)

if 'displayName' in capability and len(capability['displayName']) > 0:
originCapabilityName = printer.sanitizeText(capability['displayName'])
@@ -153,7 +153,7 @@ def showUsage():
else:
originOptionName = printer.sanitizeText(option['name'])
engOptionName = printer.sanitizeText(option['name'])
internalOptionName = printer.getInternalName(option['name'])
internalOptionName = printer.getInternalName(option)
if 'default' in option and option['default'] == True:
ppddetails += '*DefaultGCP_' + internalcapabilityName + ': ' + internalOptionName + "\n"
ppddetails += '*GCP_' + internalcapabilityName + ' ' + internalOptionName + ':' + internalOptionName + "\n"
@@ -301,18 +301,18 @@ def getCapabilities ( self, gcpid, cupsprintername, overrideoptionsstring ) :
fulldetails = details['printers'][0]
gcpoption = None
for capability in fulldetails['capabilities']:
if hashname == self.getInternalName(capability['name']):
if hashname == self.getInternalName(capability):
gcpname = capability['name']
for option in capability['options']:
if attr.value == self.getInternalName(option['name']):
if attr.value == self.getInternalName(option):
gcpoption = option['name']
break

for overridecapability in overridecapabilities:
if 'Default' + overridecapability == attr.name:
selectedoption = overridecapabilities[overridecapability]
for option in capability['options']:
if selectedoption == self.getInternalName(option['name']):
if selectedoption == self.getInternalName(option):
gcpoption = option['name']
break
break
@@ -389,5 +389,19 @@ def submitJob(self, printerid, jobtype, jobfile, jobname, printername, options="
print('ERROR: Print job %s failed with %s' % ( jobtype, error_msg ))
return False

def getInternalName ( self, name ) :
return hashlib.sha256(self.sanitizeText(name)).hexdigest()[:7]
def getInternalName ( self, details ) :

if 'displayName' in details and len(details['displayName']) > 0:
name = details['displayName']
elif 'psk:DisplayName' in details and len(details['psk:DisplayName']) > 0:
name = details['psk:DisplayName']
else:
name = details['name']

sanitisedName = self.sanitizeText(name)

# only sanitise, no hash
if len(sanitisedName) <= 30 and sanitisedName.encode("ascii","ignore") == sanitisedName:
return sanitisedName

return hashlib.sha256(sanitisedName).hexdigest()[:7]

0 comments on commit e163065

Please sign in to comment.
You can’t perform that action at this time.