]> git.parisson.com Git - deefuzzer.git/commitdiff
Added stationdefaults parameter (provides a mechanism to give default values for...
authorachbed <github@achbed.org>
Thu, 20 Nov 2014 04:52:32 +0000 (22:52 -0600)
committerachbed <github@achbed.org>
Thu, 20 Nov 2014 04:52:32 +0000 (22:52 -0600)
New merge_defaults function in utils.py - combines two dict objects recursively

Signed-off-by: achbed <github@achbed.org>
deefuzzer/core.py
deefuzzer/tools/utils.py
example/deefuzzer.json
example/deefuzzer.xml
example/deefuzzer.yaml
example/deefuzzer_doc.xml

index ef0f1fc65adb5b979f1ace20727cd0c82af35e94..49e636fc9e578ecfea3748a0beef9efd35a975d9 100644 (file)
@@ -120,6 +120,11 @@ class DeeFuzzer(Thread):
                 station = self.conf['deefuzzer']['station']
             else:
                 station = self.conf['deefuzzer']['station'][i]
+
+            # Apply station defaults if they exist
+            if 'stationdefaults' in self.conf['deefuzzer']:
+                if isinstance(self.conf['deefuzzer']['stationdefaults'], dict):
+                    station = merge_defaults(station, self.conf['deefuzzer']['stationdefaults'])
             self.stations.append(Station(station, q, self.logger, self.m3u))
 
         if self.m3u:
index df4955b879399b8a9b377059cdc1c02a5c91864e..3d2143b05e91328c3b5e5d19b7e9a280c5fac456 100644 (file)
@@ -13,6 +13,8 @@
 import os
 import re
 import string
+from itertools import chain
+from deefuzzer.tools import *
 
 def clean_word(word) :
     """ Return the word without excessive blank spaces, underscores and
@@ -37,3 +39,18 @@ def get_file_info(media):
 
 def is_absolute_path(path):
     return os.sep == path[0]
+
+def merge_defaults(setting, default):
+    combined = {}
+    for key in set(chain(setting, default)):
+        if key in setting:
+            if key in default:
+                if isinstance(setting[key], dict) and isinstance(default[key], dict):
+                    combined[key] = merge_defaults(setting[key], default[key])
+                else:
+                    combined[key] = setting[key]
+            else:
+                combined[key] = setting[key]
+        else:
+            combined[key] = default[key]
+    return combined
index cc4078e36b8951d87ad36a4fe112e0b73f36be9d..2234dedbd168b06bd435d2a2d4e95e32a0d484cf 100644 (file)
@@ -2,6 +2,17 @@
     "deefuzzer": {
         "log": "/path/to/station.log",
         "m3u": "/path/to/station.m3u",
+        "station": {
+            "control": {
+                "mode": 0,
+                "port": 16001
+            },
+            "jingles": {
+                "dir": "/path/to/jingles",
+                "mode": 0,
+                "shuffle": 1
+            }
+        },
         "station": {
             "control": {
                 "mode": 0,
index 593d2edce0973e8d0c1ec20d208dddfdadfbd5f9..9cadbb14d8e45684607f63c9ffa9a433e54e1182 100644 (file)
@@ -1,6 +1,17 @@
 <deefuzzer>
     <log>/path/to/station.log</log>
     <m3u>/path/to/station.m3u</m3u>
+    <stationdefaults>
+        <control>
+            <mode>0</mode>
+            <port>16001</port>
+        </control>
+        <jingles>
+            <dir>/path/to/jingles</dir>
+            <mode>0</mode>
+            <shuffle>1</shuffle>
+        </jingles>
+    </stationdefaults>
     <station>
         <control>
             <mode>0</mode>
index 8e33454cd3deee8477c1ea5ef902310c6969b8aa..366cb7f018da5ff39fba7c2c03425374d4d8ed42 100644 (file)
@@ -2,6 +2,14 @@ deefuzzer:
   log: /path/to/station.log
   m3u: /path/to/station.m3u
 
+  stationdefaults:
+    control: {mode: 0,
+             port: 16001}
+
+    jingles: {dir: /path/to/jingles,
+              mode: 0,
+              shuffle: 1}
+
   station:
     control: {mode: 0,
              port: 16001}
index be45286990dfb1b7003e38c22c0a90fb8e335984..1beb53f19ff416dbb434876e9304637b170e19a3 100644 (file)
@@ -5,6 +5,28 @@
          The file is preferably accessible behind an url,
          for example, http://mydomain.com/m3u/mystation.m3u -->
     <m3u>/path/to/station.m3u</m3u>
+    <stationdefaults>
+      <!-- This tag allows a common default configuration to be set for all stations.  This
+           is useful when defining many stations that will share many common configuration
+           settings.  If a setting is specified here and in a station tag, the station tag 
+           will override this one.  Available options are the same as the station tag. -->
+        <control>
+            <!-- If '1', an OSC controller thread is started to allow external commands
+                See README for more info -->
+            <mode>0</mode>
+            <!-- The port of the OSC server -->
+            <port>16001</port>
+        </control>
+        <jingles>
+            <!-- A path to the directory containing jingles media files.
+                The files have to be of the same type of the main media files. -->
+            <dir>/path/to/jingles</dir>
+            <!-- If '1', some media will be played between each main track of the playlist. '0' does nothing. -->
+            <mode>0</mode>
+            <!-- If '1', the jingle playlist will be randomized. '0' for aphanumeric order -->
+            <shuffle>1</shuffle>
+        </jingles>
+    </stationdefaults>
     <station>
         <control>
             <!-- If '1', an OSC controller thread is started to allow external commands