]> git.parisson.com Git - deefuzzer.git/commitdiff
Updates for relative paths
authorachbed <github@achbed.org>
Sat, 24 Jan 2015 07:54:41 +0000 (01:54 -0600)
committerachbed <github@achbed.org>
Sat, 24 Jan 2015 07:54:41 +0000 (01:54 -0600)
Added base_dir parameter to station definition (issue #10)
Added default station short_name to auto-created stations
Removed previously-mandatory tags from example XML config stationfolder tag

Signed-off-by: achbed <github@achbed.org>
deefuzzer/core.py
deefuzzer/station.py
example/deefuzzer_doc.xml

index e394c924f70f11af2c1c2cbf21dbb6016984310b..ab9547484d22990cce1ddb00359a281b5f457ac4 100644 (file)
@@ -169,6 +169,11 @@ class DeeFuzzer(Thread):
         # This makes the log file a lot more verbose.  Commented out since we report on new stations anyway.
         # self._info('Scanning folder ' + folder + ' for stations')
 
+        if not 'infos' in options.keys():
+            options['infos'] = {}
+        if not 'short_name' in options['infos'].keys():
+            options['infos']['short_name'] = '[name]'
+
         files = os.listdir(folder)
         for file in files:
             filepath = os.path.join(folder, file)
@@ -205,6 +210,7 @@ class DeeFuzzer(Thread):
         if not 'media' in s.keys():
             s['media'] = {}
         s['media']['source'] = folder
+        
         self.add_station(s)
 
     def load_stations_fromconfig(self, folder):
index 566b8e5822053d81213df5531e2732732689fd39..58048665173983e1c4d91df18870f983a9750437 100644 (file)
@@ -74,7 +74,6 @@ class Station(Thread):
     relay_mode = 0
     record_mode = 0
     run_mode = 1
-    station_dir = None
     appendtype = 1
     feeds_json = 0
     feeds_rss = 1
@@ -87,6 +86,7 @@ class Station(Thread):
     starting_id = -1
     jingles_frequency = 2
     statusfile = ''
+    base_directory = ''
 
     def __init__(self, station, q, logqueue, m3u):
         Thread.__init__(self)
@@ -105,21 +105,21 @@ class Station(Thread):
             except:
                 pass
 
-        if 'station_dir' in self.station:
-            self.station_dir = self.station['station_dir']
-
+        if 'base_dir' in self.station:
+            self.base_directory = self.station['base_dir'].strip()
+        
         # Media
         if 'm3u' in self.station['media'].keys():
             if not self.station['media']['m3u'].strip() == '':
-                self.media_source = self.station['media']['m3u']
+                self.media_source = self._path_add_base(self.station['media']['m3u'])
         
         if 'dir' in self.station['media'].keys():
             if not self.station['media']['dir'].strip() == '':
-                self.media_source = self.station['media']['dir']
+                self.media_source = self._path_add_base(self.station['media']['dir'])
         
         if 'source' in self.station['media'].keys():
             if not self.station['media']['source'].strip() == '':
-                self.media_source = self.station['media']['source']
+                self.media_source = self._path_add_base(self.station['media']['source'])
         
         self.media_format = self.station['media']['format']
         self.shuffle_mode = int(self.station['media']['shuffle'])
@@ -188,7 +188,7 @@ class Station(Thread):
         if 'rss' in self.station:
             if 'mode' in self.station['rss']:
                 self.feeds_mode = int(self.station['rss']['mode'])
-            self.feeds_dir = self.station['rss']['dir']
+            self.feeds_dir = self._path_add_base(self.station['rss']['dir'])
             self.feeds_enclosure = int(self.station['rss']['enclosure'])
             if 'json' in self.station['rss']:
                 self.feeds_json = int(self.station['rss']['json'])
@@ -248,7 +248,7 @@ class Station(Thread):
             if 'frequency' in self.station['jingles']:
                 self.jingles_frequency = int(self.station['jingles']['frequency'])
             if 'dir' in self.station['jingles']:
-                self.jingles_dir = self.station['jingles']['dir']
+                self.jingles_dir = self._path_add_base(self.station['jingles']['dir'])
             if self.jingles_mode == 1:
                 self.jingles_callback('/jingles', [1])
 
@@ -279,12 +279,15 @@ class Station(Thread):
         # Recording
         if 'record' in self.station:
             self.record_mode = int(self.station['record']['mode'])
-            self.record_dir = self.station['record']['dir']
+            self.record_dir = self._path_add_base(self.station['record']['dir'])
             if self.record_mode:
                 self.record_callback('/record', [1])
 
         self.valid = True
-
+        
+    def _path_add_base(self, a):
+        return os.path.join(self.base_directory, a)
+        
     def _log(self, level, msg):
         try:
             obj = {}
index 93dcc3e2e79b50a64bd84fdb9a7eecb3d7c4ab31..193e9b5613e5cbedf39525c9dd5b538b8afa04e3 100644 (file)
         </jingles>
     </stationdefaults>
     <station>
+        <!-- The base directory to be prepended to file paths for this station. This value is prepended
+              to the following parameters:
+                jingles/dir
+                media/m3u
+                media/dir (except for stations created using the stationfolder method)
+                media/source (except for stations created using the stationfolder method)
+                record/dir
+                feeds/dir
+              If the parameter path begins with a slash, it is assumed to be an absolute path and
+              prepending does not occur (see https://docs.python.org/2/library/os.path.html#os.path.join )
+        -->
+        <base_dir>/path/to/station/folder</base_dir>
         <control>
             <!-- If '1', an OSC controller thread is started to allow external commands
                 See README for more info -->
         <!-- OPTIONAL: If '1', stations will be created as folders are added ("watchfolder" capability). If '0', 
              folders will only be added when the program is started. -->
         <livecreation>1</livecreation>
-        <!-- Station information to use.  At a minimum, the following should be defined:
-                infos.short_name so that mount points will be unique. 
-                media.dir so that the files are loaded from the right place (IMPROVEMENT: should be set in code!)
+        <!-- Station information to use.
              All the same options are available as the station setting, and all stations will also have the global
              stationdefaults applied.  -->
         <infos>
             <name>[name]</name>
             <genre>[name]</genre>
         </infos>
-        <media>
-            <dir>[path]</dir>
-        </media>
     </stationfolder>
                
     <!-- The stationfolder option allows specifying a folder to scan for additional configuration files.  Applies only