Beispiel #1
0
    def __init__(self, messenger, config, account, mediatype):
        """Checks if the config is correct and creates an API object."""
        self.msg = messenger
        self.config = config
        self.msg.info(self.name, "Initializing...")

        # Get filenames
        userfolder = "%s.%s" % (account['username'], account['api'])
        self.userconfig_file = utils.get_filename(userfolder, 'user.json')

        # Handle userconfig and media type to load
        self._load_userconfig()
        if mediatype:
            self.userconfig['mediatype'] = mediatype
            self._save_userconfig()

        # Import the API
        libbase = account['api']
        libname = "lib{0}".format(libbase)
        try:
            modulename = "trackma.lib.{0}".format(libname)
            __import__(modulename)
            apimodule = sys.modules[modulename]
        except ImportError, e:
            raise utils.DataFatal("Couldn't import API module: %s" % e.message)
Beispiel #2
0
    def start(self):
        """
        Starts the engine.
        This function should be called before doing anything with the engine,
        as it initializes the data handler.
        """
        if self.loaded:
            raise utils.TrackmaError("Already loaded.")

        # Start the data handler
        try:
            (self.api_info, self.mediainfo) = self.data_handler.start()
        except utils.DataError, e:
            raise utils.DataFatal(e.message)
Beispiel #3
0
    def _lock(self):
        """Creates the database lock, returns an exception if it
        already exists"""
        if self.config['debug_disable_lock']:
            return

        if os.path.isfile(self.lock_file):
            raise utils.DataFatal(
                "Database is locked by another process. "
                "If you\'re sure there's no other process is using it, "
                "remove the file ~/.wmal/lock")

        f = open(self.lock_file, 'w')
        f.close()
Beispiel #4
0
    def __init__(self, messenger, config, account, userconfig):
        """Checks if the config is correct and creates an API object."""
        self.msg = messenger
        self.config = config
        self.userconfig = userconfig
        self.msg.info(self.name, "Version " + VERSION)

        # Import the API
        # TODO : Dangerous stuff, we should do an alphanumeric test or something.
        libbase = account['api']
        libname = "lib{0}".format(libbase)
        try:
            modulename = "wmal.lib.{0}".format(libname)
            __import__(modulename)
            apimodule = sys.modules[modulename]
        except ImportError, e:
            raise utils.DataFatal("Couldn't import API module: %s" % e.message)
Beispiel #5
0
 def connect_signal(self, signal, callback):
     try:
         self.signals[signal] = callback
     except KeyError:
         raise utils.DataFatal("Invalid signal.")