Browse Source

Initial commit

dgellow 4 years ago
parent
commit
cd732184b6
5 changed files with 59 additions and 0 deletions
  1. 0 0
      LICENSE
  2. 5 0
      config.py
  3. 24 0
      main.py
  4. 1 0
      requirements.txt
  5. 29 0
      run.py

+ 0 - 0
LICENSE


+ 5 - 0
config.py

@@ -0,0 +1,5 @@
+HOST = 'localhost'
+PORT = 6600
+PASSWORD = None
+
+HOOKS_DIR = ''

+ 24 - 0
main.py

@@ -0,0 +1,24 @@
+#!/usr/bin/env python2
+
+from mpd import MPDClient
+import config
+
+client = MPDClient()
+
+def setup():
+    client.connect(config.HOST, config.PORT)
+
+def cleanup():
+    client.close()
+    client.disconnect()
+
+def reload_config():
+    cleanup()
+    setup()
+
+def main():
+    client.send_idle()
+    events = client.fetch_idle()
+
+    for event in events:
+        print '[hmmm::event]', event

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+python-mpd2==0.5.4

+ 29 - 0
run.py

@@ -0,0 +1,29 @@
+import os
+import grp
+import signal
+import daemon
+import lockfile
+
+from main import (
+    setup,
+    main,
+    cleanup,
+    reload_config,
+)
+
+context = daemon.DaemonContext(
+    working_directory = '/var/lib/hmmm',
+    umask = 0o002,
+    pidfile = lockfile.FileLock('/var/run/hmmm.pid'),
+)
+
+context.signal_map = {
+    signal.SIGTERM: cleanup,
+    signal.SIGHUP: 'terminate',
+    signal.SIGUSR1: reload_config
+}
+
+initial_program_setup()
+
+with context:
+    main()