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.

53 lines
1.3 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. #fix for wstools
  13. import collections
  14. collections.MutableMapping = collections.abc.MutableMapping
  15. defconfigfile = 'pymeds.ini'
  16. class ConfigFile(pymeds.Options):
  17. optParameters = [ [ 'config', 'c', defconfigfile,
  18. 'INI style config file', ], ]
  19. if __name__ == '__main__':
  20. config = ConfigFile()
  21. try:
  22. config.checkpath = False
  23. config.parseOptions()
  24. print(repr(config))
  25. if os.path.exists(config['config']):
  26. print('foo')
  27. scp = configparser.SafeConfigParser()
  28. scp.read(config['config'])
  29. config.update(scp.items('pymeds'))
  30. # Double check config
  31. config.checkpath = True
  32. config.postOptions()
  33. elif config['config'] != defconfigfile:
  34. print('bar')
  35. raise usage.UsageError(
  36. 'config file %s does not exist' % config['config'])
  37. except usage.UsageError as errortext:
  38. print('%s: %s' % (sys.argv[0], errortext))
  39. print('%s: Try --help for usage details.' % sys.argv[0])
  40. sys.exit(1)
  41. log.startLogging(sys.stdout)
  42. ser = pymeds.makeService(config)
  43. ser.startService()
  44. reactor.addSystemEventTrigger('before', 'shutdown',
  45. service.IService(ser).stopService)
  46. reactor.run()