From: Cameron Patrick Date: Sun, 1 Aug 2004 05:37:37 +0000 (+0000) Subject: handle config parser errors more nicely than just throwing up tracebacks X-Git-Tag: IMPORT-FROM-UCCCVS~100 X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=commitdiff_plain;h=48db22f8d2af1191fb7f3b51bfc5e5cb0993f33e handle config parser errors more nicely than just throwing up tracebacks --- diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index d8122aa..dd9739d 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -380,7 +380,7 @@ def connect_to_vend(options, DBServer, DBName, DBUser, DBPassword, ServiceName, return rfh, wfh if __name__ == '__main__': - from ConfigParser import ConfigParser + import ConfigParser from optparse import OptionParser op = OptionParser(usage="%prog [OPTION]...") @@ -393,19 +393,23 @@ if __name__ == '__main__': if len(args) != 0: op.error('extra command line arguments: ' + ' '.join(args)) - cp = ConfigParser() - cp.read(options.config_file) - DBServer = cp.get('Database', 'Server') - DBName = cp.get('Database', 'Name') - DBUser = cp.get('VendingMachine', 'DBUser') - DBPassword = cp.get('VendingMachine', 'DBPassword') - - ServiceName = cp.get('VendingMachine', 'ServiceName') - ServicePassword = cp.get('VendingMachine', 'Password') - - ServerName = cp.get('DecServer', 'Name') - ConnectPassword = cp.get('DecServer', 'ConnectPassword') - PrivPassword = cp.get('DecServer', 'PrivPassword') + try: + cp = ConfigParser.ConfigParser() + cp.read(options.config_file) + DBServer = cp.get('Database', 'Server') + DBName = cp.get('Database', 'Name') + DBUser = cp.get('VendingMachine', 'DBUser') + DBPassword = cp.get('VendingMachine', 'DBPassword') + + ServiceName = cp.get('VendingMachine', 'ServiceName') + ServicePassword = cp.get('VendingMachine', 'Password') + + ServerName = cp.get('DecServer', 'Name') + ConnectPassword = cp.get('DecServer', 'ConnectPassword') + PrivPassword = cp.get('DecServer', 'PrivPassword') + except ConfigParser.Error, e: + print "Error reading config file: " + str(e) + sys.exit(1) while True: try: