]> git.parisson.com Git - deefuzzer.git/commitdiff
add install.py, cleanup
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 10 Mar 2009 23:08:44 +0000 (23:08 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 10 Mar 2009 23:08:44 +0000 (23:08 +0000)
defuzz.py
install.py [new file with mode: 0644]

index 6b8173b64d8d9c8b7bae95df25aaeb4064384f58..d03dade6d8a53c2cff85c9e4dd6248dd93a7638b 100755 (executable)
--- a/defuzz.py
+++ b/defuzz.py
@@ -19,7 +19,6 @@ import random
 import Queue
 import shout
 import subprocess
-from shout import Shout
 from tools import *
 from threading import Thread
 from mutagen.oggvorbis import OggVorbis
@@ -69,7 +68,7 @@ class DeFuzzError:
                                                 error)
 
 class DeFuzz:
-    """A DeFuzz station"""
+    """A DeFuzz diffuser"""
 
     def __init__(self, conf_file):
         self.conf_file = conf_file
@@ -93,31 +92,33 @@ class DeFuzz:
         else:
             nb_stations = len(self.conf['defuzz']['station'])
         print 'Number of stations : ' + str(nb_stations)
-        
+
         # Create a Queue
         q = Queue.Queue(nb_stations)
+
+        # Create a Producer 
         p = Producer(q)
         p.start()
+
         s = []
-        
         for i in range(0,nb_stations):
             if isinstance(self.conf['defuzz']['station'], dict):
                 station = self.conf['defuzz']['station']
             else:
                 station = self.conf['defuzz']['station'][i]
-            #print station
             name = station['infos']['name']
+            # Create a Station
             s.append(Station(station, q))
-        
+
         for i in range(0,nb_stations):
+            # Start the Stations
             s[i].start()
             time.sleep(0.1)
-            #s[i].join()
             pass
-            
+
 
 class Producer(Thread):
-    """A DeFuzz Producer master thread"""
+    """a DeFuzz Producer master thread"""
 
     def __init__(self, q):
         Thread.__init__(self)
@@ -130,19 +131,17 @@ class Producer(Thread):
             #print "Producer produced one queue step: "+str(i)
             self.q.put(i,1)
             i+=1
-            #time.sleep(0.1)
 
 
 class Station(Thread):
-    """A DeFuzz Station shouting slave thread"""
+    """a DeFuzz Station shouting slave thread"""
 
     def __init__(self, station, q):
         Thread.__init__(self)
         self.q = q
         self.station = station
         self.buffer_size = 16384
-        #self.channel_id = channel_id
-        self.channel = Shout()
+        self.channel = shout.Shout()
         self.id = 999999
         self.counter = 0
         self.rand_list = []
@@ -164,7 +163,6 @@ class Station(Thread):
         self.channel.user = 'source'
         self.channel.password = self.station['server']['sourcepassword']
         self.channel.mount = '/' + self.short_name + '.' + self.channel.format
-        #print self.channel.mount
         self.channel.public = int(self.station['server']['public'])
         # s.audio_info = { 'key': 'val', ... }
         #  (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE,
@@ -190,18 +188,15 @@ class Station(Thread):
     def get_next_media_rand(self, playlist):
         lp = len(playlist)
         if self.id >= (lp - 1):
-            #print 'Get random list...'
             playlist = self.get_playlist()
             lp_new = len(playlist)
             if lp_new != lp or self.counter == 0:
                 self.rand_list = range(0,lp_new)
                 random.shuffle(self.rand_list)
-                #print self.rand_list
             self.id = 0
         else:
             self.id = self.id + 1
         index = self.rand_list[self.id]
-        #print str(self.id) +':'+ str(index)
         return playlist, playlist[index]
 
     def core_process(self, media, buffer_size):
@@ -246,12 +241,11 @@ class Station(Thread):
             if lp == 0:
                 break
             if self.mode_shuffle == 1:
-                #print 'Shuffle mode'
                 playlist, media = self.get_next_media_rand(playlist)
             else:
                 playlist, media = self.get_next_media_lin(playlist)
+
             self.counter += 1
-            
             if os.path.exists(media) and not '/.' in media:
                 file_name = string.replace(media, self.media_dir + os.sep, '')
                 self.channel.set_metadata({'song': file_name})
@@ -259,12 +253,11 @@ class Station(Thread):
                 print 'Defuzzing this file on %s :  id = %s, name = %s' % (self.short_name, self.id, file_name)
 
                 for __chunk in stream:
-                    # Get the queue
                     self.channel.send(__chunk)
                     self.channel.sync()
+                    # Get the queue
                     it = q.get(1)
                     #print "Station eated one queue step: "+str(it)
-
         self.channel.close()
 
 
diff --git a/install.py b/install.py
new file mode 100644 (file)
index 0000000..9ac257a
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+# ONLY FOR LINUX
+
+import os, sys
+
+if len(sys.argv) == 1:
+    install_dir = '/usr/share/defuzz/'
+elif len(sys.argv) > 2:
+    sys.exit('Give just one directory to install Telemeta, or none.')
+else:
+    install_dir = sys.argv[1]
+
+if not os.path.exists(install_dir):
+    os.mkdir(install_dir)
+
+os.system('cp -ra ./* '+install_dir+os.sep)
+os.system('rm -rf '+install_dir+os.sep+'debian')
+
+if os.path.exists('/usr/bin/defuzz'):
+    os.system('rm -r /usr/bin/defuzz')
+
+os.system('ln -s '+install_dir+os.sep+'defuzz.py '+'/usr/bin/fuzz')
+
+print """
+   Installation successfull ! 
+   Type 'defuzz' now...
+   """
+