Permalink
Browse files

Ask user to rename or overwrite printer if already exists

  • Loading branch information...
simoncadman committed Aug 16, 2012
1 parent d718d68 commit f48911f2fe7a18117a3806cb9ab1ba15affa6f7e
Showing with 20 additions and 2 deletions.
  1. +20 −2 setupcloudprint.py
View
@@ -46,9 +46,27 @@
for cupsprinter in cupsprinters:
if cupsprinters[cupsprinter]['device-uri'] == uri:
found = True
+
if found == False:
- printer.AddPrinter(prefix + ccpprinter['name'].encode('ascii', 'replace'), uri, connection)
- addedCount+=1
+ printername = prefix + ccpprinter['name'].encode('ascii', 'replace')
+
+ # check if printer name already exists
+ foundbyname = False
+ for ccpprinter2 in cupsprinters:
+ if cupsprinters[ccpprinter2]['printer-info'].replace(' ', '_') == printername.replace(' ', '_'):
+ foundbyname = True
+ if ( foundbyname ) :
+ answer = raw_input("Printer " + printername + " already exists, supply another name? ")
+ if ( answer.startswith("Y") or answer.startswith("y") ):
+ printername = raw_input("New printer name? ")
+ else:
+ answer = raw_input("Overwrite " + printername + " with new printer? ")
+ if ( answer.startswith("N") or answer.startswith("n") ):
+ printername = ""
+
+ if printername != "":
+ printer.AddPrinter(printername, uri, connection)
+ addedCount+=1
if addedCount > 0:
print("Added " + str(addedCount) + " new printers to CUPS")

0 comments on commit f48911f

Please sign in to comment.