Example #1
0
	def __init__(self):
		"""Creates a new instance of ImportThread and connects to the database.
		This design pattern is important: since the constructor runs synchonously,
		it ensures that two threads don't attempt to initialize the database at
		the same time.
		"""
		super(ImportThread, self).__init__(name=__name__)
		self.log = initLogging(__name__)
		db = DatabaseWrapper()
		self.sa_session = db.get_session()
Example #2
0
	def __init__(self, threads):
		self.log = initLogging(__name__)
		self.threads = threads

		# Subscribe specifically to the 'stop' method passed by cherrypy.
		# This lets us cleanly stop all threads executed by the application.
		SAEnginePlugin(cherrypy.engine).subscribe()
		cherrypy.engine.subscribe("stop", self.stop_threads)
		cherrypy.tools.db = SATool()

		config = {'/':
			{
				'tools.db.on': True,
				'tools.staticdir.root': os.path.dirname(os.path.realpath(sys.argv[0])),
			},
			'/static':
			{
				'tools.staticdir.on': True,
				'tools.staticdir.dir': "static",
			},
		}
		cherrypy.tree.mount(Musik(), '/', config=config)
Example #3
0
    def __init__(self, path):
        self.running = False
        self.finished = False
        self.log = initLogging(__name__)
        self.log.info("%s created with path %s" % (__name__, path))

        # Set up the Gstreamer pipeline.
        self.pipeline = gst.Pipeline()
        self.src = gst.element_factory_make("filesrc")
        self.dec = gst.element_factory_make("decodebin2")
        self.conv = gst.element_factory_make("audioconvert")
        self.enc = gst.element_factory_make("vorbisenc")
        self.mux = gst.element_factory_make("oggmux")
        self.sink = gst.element_factory_make('appsink')

        # Register for bus signals.
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()
        bus.connect("message::eos", self._message)
        bus.connect("message::error", self._message)

        # Configure the input/decoding stage.
        print "path is %s" % path
        self.src.set_property("location", path)

        # The callback to connect the input.
        self.dec.connect("pad-added", self._pad_added)
        self.dec.connect("no-more-pads", self._no_more_pads)

        # And a callback if decoding fails.
        self.dec.connect("unknown-type", self._unkown_type)

        # Set up the characteristics of the output. We don't want to
        # drop any data (nothing is real-time here); we should bound
        # the memory usage of the internal queue; and, most
        # importantly, setting "sync" to False disables the default
        # behavior in which you consume buffers in real time. This way,
        # we get data as soon as it's decoded.
        self.sink.set_property('drop', False)
        self.sink.set_property('max-buffers', BUFFER_SIZE)
        self.sink.set_property('sync', False)
        # The callback to receive decoded data.
        self.sink.set_property('emit-signals', True)
        self.sink.connect("new-buffer", self._new_buffer)

        # We'll need to know when the stream becomes ready and we get
        # its attributes. This semaphore will become available when the
        # caps are received. That way, when __init__() returns, the file
        # (and its attributes) will be ready for reading.
        self.ready_sem = threading.Semaphore(0)
        self.caps_handler = self.sink.get_pad("sink").connect(
            "notify::caps", self._notify_caps
        )

        # Link up everything but the decoder (which must be linked only
        # when it becomes ready).
        self.pipeline.add(self.src, self.dec, self.conv, self.enc, self.mux, self.sink)
        self.src.link(self.dec)
        self.conv.link(self.enc)
        self.enc.link(self.mux)
        self.mux.link(self.sink)

        # Set up the queue for data and run the main thread.
        self.queue = Queue.Queue(QUEUE_SIZE)
        self.thread = get_loop_thread()

        # This wil get filled with an exception if opening fails.
        self.read_exc = None

        # Return as soon as the stream is ready!
        self.running = True
        self.pipeline.set_state(gst.STATE_PLAYING)
        self.ready_sem.acquire()
        if self.read_exc:
            # An error occurred before the stream became ready.
            self.log.error("%s" % unicode(self.read_exc))
            self.close(True)
            raise self.read_exc
Example #4
0
File: api.py Project: jbillo/musik
	def __init__(self):
		self.log = initLogging(__name__)
Example #5
0
	log.info(u'Stopping CherryPy Engine')
	app.stop()

	log.info(u'Clean up complete')
	sys.exit(0)


# application entry - starts the database connection and dev server
if __name__ == '__main__':
	global log, importThread, app

	threads = []

	# get logging set up
	log = initLogging(__name__)

	# TODO: also register for CherryPy shutdown messages
	log.info(u'Registering for shutdown signals')
	for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
		signal.signal(sig, cleanup)

	log.info(u'Starting worker threads')
	importThread = musik.library.importer.ImportThread()
	importThread.start()
	threads.append(importThread)

	# this is a blocking call
	log.info(u'Starting Web App')
	app = musik.web.application.MusikWebApplication(threads=threads)