handle config parser errors more nicely than just throwing up tracebacks
authorCameron Patrick <[email protected]>
Sun, 1 Aug 2004 05:37:37 +0000 (05:37 +0000)
committerCameron Patrick <[email protected]>
Sun, 1 Aug 2004 05:37:37 +0000 (05:37 +0000)
sql-edition/servers/VendServer.py

index d8122aa..dd9739d 100755 (executable)
@@ -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:

UCC git Repository :: git.ucc.asn.au