Browse Source

pamusb-conf: Prettier XML output

master
Andrea Luzzardi 18 years ago
parent
commit
af8670fc00
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      pam_usb/tools/pamusb-conf

+ 8
- 3
pam_usb/tools/pamusb-conf View File

@ -82,7 +82,7 @@ def listOptions(question, options, autodetect = True):
def writeConf(options, doc): def writeConf(options, doc):
try: try:
f = open(options['configFile'], 'w') f = open(options['configFile'], 'w')
f.write(doc.toxml())
doc.writexml(f)
f.close() f.close()
except Exception, err: except Exception, err:
print 'Unable to save %s: %s' % (options['configFile'], err) print 'Unable to save %s: %s' % (options['configFile'], err)
@ -98,6 +98,10 @@ def shouldSave(options, items):
if sys.stdin.readline().strip() != 'y': if sys.stdin.readline().strip() != 'y':
sys.exit(1) sys.exit(1)
def prettifyElement(element):
tmp = minidom.parseString(element.toprettyxml())
return tmp.lastChild
def addUser(options): def addUser(options):
print 'adding user %s' % options['userName'] print 'adding user %s' % options['userName']
try: try:
@ -134,7 +138,7 @@ def addUser(options):
t = doc.createTextNode(device) t = doc.createTextNode(device)
e.appendChild(t) e.appendChild(t)
user.appendChild(e) user.appendChild(e)
users[0].appendChild(user)
users[0].appendChild(prettifyElement(user))
writeConf(options, doc) writeConf(options, doc)
def addDevice(options): def addDevice(options):
@ -181,7 +185,6 @@ def addDevice(options):
devs = doc.getElementsByTagName('devices') devs = doc.getElementsByTagName('devices')
dev = doc.createElement('device') dev = doc.createElement('device')
dev.attributes['id'] = options['deviceName'] dev.attributes['id'] = options['deviceName']
devs[0].appendChild(dev)
for name, value in (('vendor', device.vendor), for name, value in (('vendor', device.vendor),
('model', device.product), ('model', device.product),
@ -200,6 +203,8 @@ def addDevice(options):
e.setAttribute('name', 'one_time_pad') e.setAttribute('name', 'one_time_pad')
e.appendChild(doc.createTextNode('false')) e.appendChild(doc.createTextNode('false'))
dev.appendChild(e) dev.appendChild(e)
devs[0].appendChild(prettifyElement(dev))
writeConf(options, doc) writeConf(options, doc)
def usage(): def usage():


Loading…
Cancel
Save