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.

46 lines
1.2 KiB

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