service.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. serviceType = "local"
  3. serviceDesc = _({"en": "Timidity Virtual MIDI Sequencer for Alsa",
  4. "tr": "Timidity Sanal MIDI Ardışımlayıcı"})
  5. MSG_ERR_TIMDPTCH = _({"en": "Failed to set patchset %s for Timidity.",
  6. "tr": "Yama kümesi %s Timidity'ye atanamadı.",
  7. })
  8. from comar.service import *
  9. import os
  10. @synchronized
  11. def start():
  12. if config.get("USE_ESOUND", "") == "yes":
  13. startDependencies("esound")
  14. # set up sound fonts
  15. patchset = config.get("PATCHSET", "shompatches")
  16. currentlink = "/usr/share/timidity/current"
  17. try:
  18. currentpatch = os.readlink(currentlink)
  19. except:
  20. currentpatch = None
  21. if patchset != currentpatch:
  22. if not os.path.exists("/usr/share/timidity/%s" % patchset) and not os.path.exists(patchset):
  23. fail(MSG_ERR_TIMDPTCH % patchset)
  24. else:
  25. if currentpatch:
  26. os.unlink(currentlink)
  27. os.symlink(patchset, currentlink)
  28. if config.get("TIMIDITY_PCM_NAME", "") != "":
  29. loadEnvironment()
  30. os.environ["TIMIDITY_PCM_NAME"]=config.get("TIMIDITY_PCM_NAME")
  31. startService(command="/usr/bin/timidity",
  32. args="-iA %s" % config.get("TIMIDITY_OPTS", ""),
  33. pidfile="/run/timidity.pid",
  34. makepid=True,
  35. detach=True,
  36. donotify=True)
  37. @synchronized
  38. def stop():
  39. stopService(pidfile="/run/timidity.pid",
  40. donotify=True)
  41. def status():
  42. return isServiceRunning("/run/timidity.pid")