]> git.parisson.com Git - deefuzzer.git/commitdiff
add a logger to DeFuzz
authorGuillaume Pellerin <yomguy@parisson.com>
Sat, 11 Apr 2009 16:27:54 +0000 (16:27 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Sat, 11 Apr 2009 16:27:54 +0000 (16:27 +0000)
deefuzz-deamon [deleted file]
deefuzz-deamon.sh [new file with mode: 0644]
deefuzz.py
example/myfuzz.xml
example/test_mp3.xml
install.py
tools/__init__.py
tools/logger.py [new file with mode: 0644]

diff --git a/deefuzz-deamon b/deefuzz-deamon
deleted file mode 100644 (file)
index 6d1c0cd..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-conf_file=$1
-log_file=/tmp/deefuzz.log
-
-ulimit -c unlimited
-while true; do
-  deefuzz $1 >> $log_file
-  sleep 3
-done
diff --git a/deefuzz-deamon.sh b/deefuzz-deamon.sh
new file mode 100644 (file)
index 0000000..0406cff
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+conf_file=$1
+log_file=/tmp/deefuzz.log
+
+ulimit -c unlimited
+while true; do
+  deefuzz $1 > /dev/null
+  sleep 3
+done
index 6c82a91a6523e678ba4a6b62e3ab1d0311bd37e0..476ec316c9e1c7105b0445ea12405c10c8b0bdb8 100755 (executable)
@@ -107,16 +107,13 @@ class DeeFuzz:
         dict = xmltodict(conf_xml,'utf-8')
         return dict
 
-    def get_station_names(self):
-        return self.conf['station']['name']
-
     def run(self):
         if isinstance(self.conf['deefuzz']['station'], dict):
             # Fix wrong type data from xmltodict when one station (*)
             nb_stations = 1
         else:
             nb_stations = len(self.conf['deefuzz']['station'])
-        print 'Number of stations : ' + str(nb_stations)
+        #print 'Number of stations : ' + str(nb_stations)
 
         # Create a Queue
         q = Queue.Queue(1)
@@ -127,21 +124,23 @@ class DeeFuzz:
 
         # Define the buffer_size
         self.buffer_size = 65536/nb_stations
-        print 'Buffer size per station = ' + str(self.buffer_size)
+        #print 'Buffer size per station = ' + str(self.buffer_size)
+
+        # Set the deefuzz logger
+        self.logger = Logger(self.conf['deefuzz']['log'])
 
-        # Start the stations
+        # Start the Stations
         s = []
         for i in range(0,nb_stations):
             if isinstance(self.conf['deefuzz']['station'], dict):
                 station = self.conf['deefuzz']['station']
             else:
                 station = self.conf['deefuzz']['station'][i]
-            name = station['infos']['name']
+
             # Create a Station
-            s.append(Station(station, q, self.buffer_size))
+            s.append(Station(station, q, self.buffer_size, self.logger))
 
         for i in range(0,nb_stations):
-            # Start the Stations
             s[i].start()   
 
 
@@ -164,11 +163,12 @@ class Producer(Thread):
 class Station(Thread):
     """a DeeFuzz shouting station thread"""
 
-    def __init__(self, station, q, buffer_size):
+    def __init__(self, station, q, buffer_size, logger):
         Thread.__init__(self)
         self.station = station
         self.q = q
         self.buffer_size = buffer_size
+        self.logger = logger
         self.channel = shout.Shout()
         self.id = 999999
         self.counter = 0
@@ -209,8 +209,12 @@ class Station(Thread):
         #print self.playlist
         self.lp = len(self.playlist)
         self.channel.open()
-        print 'Opening ' + self.short_name + ' - ' + self.channel.name + \
-                ' (' + str(self.lp) + ' tracks)...'
+
+        # Logging
+        self.logger.write('DeeFuzz v' + version)
+        self.logger.write('Using libshout version %s' % shout.version())
+        self.logger.write('Opening ' + self.short_name + ' - ' + self.channel.name + \
+                ' (' + str(self.lp) + ' tracks)...')
 
     def update_rss(self, media_list, rss_file):
         rss_item_list = []
@@ -367,7 +371,8 @@ class Station(Thread):
                 self.channel.set_metadata({'song': str(title)})
                 self.update_rss(self.current_media_obj, self.rss_current_file)
                 file_name, file_title, file_ext = self.get_file_info(media)
-                print 'DeeFuzzing this file on %s :  id = %s, name = %s' % (self.short_name, self.id, file_name)
+                self.logger.write('DeeFuzzing this file on %s :  id = %s, name = %s' \
+                                    % (self.short_name, self.id, file_name))
                 stream = self.core_process_read(media)
                 q.task_done()
                 
@@ -383,8 +388,6 @@ class Station(Thread):
 
 def main():
     if len(sys.argv) == 2:
-        print "DeeFuzz v"+version
-        print "Using libshout version %s" % shout.version()
         d = DeeFuzz(sys.argv[1])
         d.run()
     else:
index 8cd3e4f1592e7592c1ae9f95e30c9159b50bb156..266cdbcc31ce31e76b290daa908c96be3ae26538 100644 (file)
@@ -1,4 +1,5 @@
 <deefuzz>
+    <log>/tmp/deefuzz.log</log>
     <station>
         <infos>
             <short_name>My_Station_1</short_name>
index f6b759fc5f90836ccb9a74c8693c2976f94331c9..7a5e0b4e0a7f6fd1a6f08ef7875f2cef77f359ab 100644 (file)
@@ -1,4 +1,5 @@
 <deefuzz>
+    <log>/tmp/deefuzz.log</log>
     <station>
         <infos>
             <short_name>My_Station_1</short_name>
index c211ebeb16951b37207be8c2b49e01146eb02814..e09bdfa128039f471640194de5020fddaf2da430 100644 (file)
@@ -57,6 +57,7 @@ if os.path.exists('/usr/bin/deefuzz'):
     os.system('rm -r /usr/bin/deefuzz')
 
 os.system('ln -s '+install_dir+os.sep+'deefuzz.py '+'/usr/bin/deefuzz')
+os.system('ln -s '+install_dir+os.sep+'deefuzz-deamon.sh '+'/usr/bin/deefuzz-deamon')
 
 print """
    Installation successfull ! 
index 89f1866b9ab55e66b276821c904637649ba35eaa..3f9d101b061e5eafd00c9aadf155dbb360adf48e 100644 (file)
@@ -3,3 +3,4 @@ from xmltodict import *
 from PyRSS2Gen import *
 from mp3 import *
 from ogg import *
+from logger import *
\ No newline at end of file
diff --git a/tools/logger.py b/tools/logger.py
new file mode 100644 (file)
index 0000000..65a386f
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import logging
+
+class Logger:
+
+    def __init__(self, file):
+        self.logger = logging.getLogger('myapp')
+        self.hdlr = logging.FileHandler(file)
+        self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+        self.hdlr.setFormatter(self.formatter)
+        self.logger.addHandler(self.hdlr)
+        self.logger.setLevel(logging.INFO)
+
+    def write(self, message):
+        self.logger.info(message)
+
+
+    
\ No newline at end of file