From 3b980743d335e523eff66398e91f90703dc13035 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Jan 2007 20:19:31 +0000 Subject: [PATCH] Nice error handling --- tools/pusb_conf | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/pusb_conf b/tools/pusb_conf index 16d24b5..c12c2f7 100755 --- a/tools/pusb_conf +++ b/tools/pusb_conf @@ -114,7 +114,12 @@ def addDevice(options): if sys.stdin.readline().strip() != 'y': sys.exit(1) - doc = minidom.parse(options['configFile']) + try: + doc = minidom.parse(options['configFile']) + except Exception, err: + print 'Unable to read %s: %s' % (options['configFile'], err) + sys.exit(1) + devs = doc.getElementsByTagName('devices') dev = doc.createElement('device') dev.attributes['id'] = options['deviceName'] @@ -129,10 +134,15 @@ def addDevice(options): e.appendChild(t) dev.appendChild(e) - f = open(options['configFile'], 'w') - f.write(doc.toxml()) - f.close() - print 'Done.' + try: + f = open(options['configFile'], 'w') + f.write(doc.toxml()) + f.close() + except Exception, err: + print 'Unable to save %s: %s' % (options['configFile'], err) + sys.exit(1) + else: + print 'Done.' def usage(): print 'Usage: %s [--config file] --add-device [--no-autodetect]' % os.path.basename(__file__) @@ -171,4 +181,8 @@ halService = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager') halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager') -addDevice(options) +try: + addDevice(options) +except KeyboardInterrupt: + sys.exit(1) +