|
- #!/usr/bin/env python
-
- from twisted.internet import reactor
- from twisted.application import service
- from twisted.python import log, usage
- import ConfigParser
- import pymeds
- import os.path
- import sys
-
- defconfigfile = 'pymeds.ini'
- class ConfigFile(pymeds.Options):
- optParameters = [ [ 'config', 'c', defconfigfile,
- 'INI style config file', ], ]
-
- if __name__ == '__main__':
- config = ConfigFile()
- try:
- config.checkpath = False
- config.parseOptions()
- print `config`
- if os.path.exists(config['config']):
- print 'foo'
- scp = ConfigParser.SafeConfigParser()
- scp.read(config['config'])
- config.update(scp.items('pymeds'))
-
- # Double check config
- config.checkpath = True
- config.postOptions()
- elif config['config'] != defconfigfile:
- print 'bar'
- raise usage.UsageError(
- 'config file %s does not exist' % config['config'])
- except usage.UsageError, errortext:
- print '%s: %s' % (sys.argv[0], errortext)
- print '%s: Try --help for usage details.' % sys.argv[0]
- sys.exit(1)
-
- log.startLogging(sys.stdout)
- ser = pymeds.makeService(config)
- ser.startService()
- reactor.addSystemEventTrigger('before', 'shutdown',
- service.IService(ser).stopService)
- reactor.run()
|