A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

  1. #!/usr/bin/env python
  2. #
  3. # $Id$
  4. #
  5. from twisted.internet import reactor
  6. from twisted.application import service
  7. from twisted.python import log, usage
  8. import ConfigParser
  9. import pymeds
  10. import os.path
  11. import sys
  12. defconfigfile = 'pymeds.ini'
  13. class ConfigFile(pymeds.Options):
  14. optParameters = [ [ 'config', 'c', defconfigfile,
  15. 'INI style config file', ], ]
  16. if __name__ == '__main__':
  17. config = ConfigFile()
  18. try:
  19. config.checkpath = False
  20. config.parseOptions()
  21. print `config`
  22. if os.path.exists(config['config']):
  23. print 'foo'
  24. scp = ConfigParser.SafeConfigParser()
  25. scp.read(config['config'])
  26. config.update(scp.items('pymeds'))
  27. # Double check config
  28. config.checkpath = True
  29. config.postOptions()
  30. elif config['config'] != defconfigfile:
  31. print 'bar'
  32. raise usage.UsageError(
  33. 'config file %s does not exist' % config['config'])
  34. except usage.UsageError, errortext:
  35. print '%s: %s' % (sys.argv[0], errortext)
  36. print '%s: Try --help for usage details.' % sys.argv[0]
  37. sys.exit(1)
  38. log.startLogging(sys.stdout)
  39. ser = pymeds.makeService(config)
  40. ser.startService()
  41. reactor.addSystemEventTrigger('before', 'shutdown',
  42. service.IService(ser).stopService)
  43. reactor.run()