|
- #!/usr/bin/env python
- #
- # $Id$
- #
-
- 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
-
- #fix for wstools
- import collections
- collections.MutableMapping = collections.abc.MutableMapping
-
- 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(repr(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 as 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()
|