Esempio n. 1
0
    def MDBM_Main(self, args):

        self.ShowUI()

        # Update caches with the new tags
        pipe = NamedPipe(self.cfg.server.fifofile)
        pipe.WriteLine("refresh")

        return 0
Esempio n. 2
0
    def UpdateServerCache(self):
        """
        This method signals the MusicDB Websocket Server to update its caches by writing ``refresh`` into its named pipe.
        This should always be called when there are new artists, albums or songs added to the database.

        Returns:
            *Nothing*
        """
        pipe = NamedPipe(self.cfg.server.fifofile)
        pipe.WriteLine("refresh")
Esempio n. 3
0
def Initialize(configobj, databaseobj):
    """
    This function initializes the whole server.
    It initializes lots of global objects that get shared between multiple connections.

    The following things happen when this method gets called:

        #. Assign the *configobj* and *databaseobj* to global variables ``cfg`` and ``database`` to share them between multiple connections
        #. Seed Python's random number generator
        #. Instantiate a global :meth:`mdbapi.mise.MusicDBMicroSearchEngine` object
        #. Start the Streaming Thread via :meth:`mdbapi.stream.StartStreamingThread` (see :doc:`/mdbapi/stream` for details)
        #. Update MiSE cache via :meth:`mdbapi.mise.MusicDBMicroSearchEngine.UpdateCache`
        #. Create FIFO file for named pipe

    Args:
        configobj: :class:`~lib.cfg.musicdb.MusicDBConfig` that gets shared between connections
        databaseobj: :class:`~lib.db.musicdb.MusicDatabase` that gets shared between connections

    Returns:
        ``None``

    Raises:
        TypeError: When *configobj* is not of type :class:`~lib.cfg.musicdb.MusicDBConfig`
        TypeError: When *databaseobj* is not of type :class:`~lib.cfg.musicdb.MusicDatabase`
    """

    global cfg
    global database
    if type(configobj) != MusicDBConfig:
        logging.critical("Config-class of unknown type!")
        raise TypeError("configobj must be a valid MusicDBConfig object!")
    if type(databaseobj) != MusicDatabase:
        logging.critical("Database-class of unknown type!")
        raise TypeError("databaseobj must be a valid MusicDatabase object")

    cfg = configobj
    database = databaseobj

    random.seed()

    # Initialize all interfaces
    logging.debug("Initializing MicroSearchEngine…")
    global mise
    mise = MusicDBMicroSearchEngine(database)

    # Start/Connect all interfaces
    logging.debug("Starting Streaming Thread…")
    StartStreamingThread(cfg, database)

    logging.debug("Updateing MiSE Cache…")
    mise.UpdateCache()

    # Signal Handler
    # Don't mention the signals - they are deprecated!
    #logging.info("Register signals \033[0;36m(" + cfg.server.pidfile + ")\033[0m")
    #logging.info("\t\033[1;36mUSR1:\033[1;34m Update Caches\033[0m")
    signal.signal(signal.SIGUSR1, SignalHandler)
    #logging.info("\t\033[1;36mTERM:\033[1;34m Shutdown Server\033[0m")
    signal.signal(signal.SIGTERM, SignalHandler)

    # Named Pipe
    global pipe
    logging.info("Open pipe \033[0;36m(" + cfg.server.fifofile + ")\033[0m")
    logging.info("\t\033[1;36mrefresh\033[1;34m: Update Caches\033[0m")
    logging.info("\t\033[1;36mshutdown\033[1;34m: Shutdown Server\033[0m")
    pipe = NamedPipe(cfg.server.fifofile)
    pipe.Create()

    return None