def ValidatePrefs():
    last_activity_mode = get_pref('activity_mode')

    if Main.authenticate():
        message = MessageContainer(
            "Success",
            "Authentication successful"
        )
    else:
        message = MessageContainer(
            "Error",
            "Authentication failed, incorrect username or password"
        )

    # Restart if activity_mode has changed
    if Prefs['activity_mode'] != last_activity_mode:
        log.info('Activity mode has changed, restarting plugin...')

        def restart():
            # Delay until after `ValidatePrefs` returns
            time.sleep(3)

            # Restart plugin
            Plex[':/plugins'].restart(PLUGIN_IDENTIFIER)

        spawn(restart)
        return message

    # Re-initialize modules
    Main.init_logging()

    return message
    def start(self):
        # Validate username/password
        spawn(self.validate_auth)

        # Check for updates
        self.update_checker.run_once(async=True)

        self.session_manager.start()

        # Start modules
        for module in self.modules:
            if hasattr(module, 'start'):
                log.debug("Starting module %s", module)
                module.start()
def ValidatePrefs():
    # Retrieve plex token
    token_plex = AccountMigration.get_token(Request.Headers)

    # Retrieve current activity mode
    last_activity_mode = Preferences.get('activity.mode')

    if Request.Headers.get('X-Disable-Preference-Migration', '0') == '0':
        # Run account migration
        am = AccountMigration()
        am.run(token_plex)

        # Migrate server preferences
        Preferences.migrate()

        # Try migrate administrator preferences
        try:
            Preferences.initialize(account=1)
            Preferences.migrate(account=1)
        except Account.DoesNotExist:
            log.debug(
                'Unable to migrate administrator preferences, no account found'
            )
    else:
        log.debug('Ignoring preference migration (disabled by header)')

    # Restart if activity_mode has changed
    if Preferences.get('activity.mode') != last_activity_mode or Prefs[
            'language'] != Dict['language']:
        log.info('Restart required to apply changes, restarting plugin...')

        def restart():
            # Delay until after `ValidatePrefs` returns
            time.sleep(3)

            # Restart plugin
            Plex[':/plugins'].restart(PLUGIN_IDENTIFIER)

        spawn(restart)
        return MessageContainer(_("Success"), _("Success"))

    # Fire configuration changed callback
    spawn(Main.on_configuration_changed)

    return MessageContainer(_("Success"), _("Success"))
Example #4
0
def ValidatePrefs():
    # Retrieve plex token
    token_plex = AccountMigration.get_token(Request.Headers)

    # Retrieve current activity mode
    last_activity_mode = Preferences.get("activity.mode")

    if Request.Headers.get("X-Disable-Preference-Migration", "0") == "0":
        # Run account migration
        am = AccountMigration()
        am.run(token_plex)

        # Migrate server preferences
        Preferences.migrate()

        # Try migrate administrator preferences
        try:
            Preferences.initialize(account=1)
            Preferences.migrate(account=1)
        except Account.DoesNotExist:
            log.debug("Unable to migrate administrator preferences, no account found")
    else:
        log.debug("Ignoring preference migration (disabled by header)")

    # Restart if activity_mode has changed
    if RestartRequired(last_activity_mode):
        log.info("Restart required to apply changes, restarting plugin...")

        def restart():
            # Delay until after `ValidatePrefs` returns
            time.sleep(3)

            # Restart plugin
            Plex[":/plugins"].restart(PLUGIN_IDENTIFIER)

        spawn(restart, daemon=True)
        return MessageContainer(_("Success"), _("Success"))

    # Fire configuration changed callback
    spawn(Main.on_configuration_changed, daemon=True)

    return MessageContainer(_("Success"), _("Success"))
Example #5
0
def ValidatePrefs():
    # Retrieve plex token
    token_plex = AccountMigration.get_token(Request.Headers)

    # Retrieve current activity mode
    last_activity_mode = Preferences.get('activity.mode')

    if Request.Headers.get('X-Disable-Preference-Migration', '0') == '0':
        # Run account migration
        am = AccountMigration()
        am.run(token_plex)

        # Migrate server preferences
        Preferences.migrate()

        # Try migrate administrator preferences
        try:
            Preferences.initialize(account=1)
            Preferences.migrate(account=1)
        except Account.DoesNotExist:
            log.debug('Unable to migrate administrator preferences, no account found')
    else:
        log.debug('Ignoring preference migration (disabled by header)')

    # Restart if activity_mode has changed
    if Preferences.get('activity.mode') != last_activity_mode:
        log.info('Activity mode has changed, restarting plugin...')

        def restart():
            # Delay until after `ValidatePrefs` returns
            time.sleep(3)

            # Restart plugin
            Plex[':/plugins'].restart(PLUGIN_IDENTIFIER)

        spawn(restart)
        return MessageContainer("Success", "Success")

    # Fire configuration changed callback
    spawn(Main.on_configuration_changed)

    return MessageContainer("Success", "Success")
def ValidatePrefs():
    last_activity_mode = get_pref('activity_mode')

    if Main.validate_auth():
        message = MessageContainer(
            "Success",
            "Authentication successful"
        )
    else:
        message = MessageContainer(
            "Error",
            "Authentication failed, incorrect username or password"
        )

    # Restart if activity_mode has changed
    if Prefs['activity_mode'] != last_activity_mode:
        log.info('Activity mode has changed, restarting plugin...')
        spawn(PlexMediaServer.restart_plugin)

    return message
Example #7
0
def ValidatePrefs():
    last_activity_mode = get_pref('activity_mode')

    if Main.validate_auth():
        message = MessageContainer(
            "Success",
            "Authentication successful"
        )
    else:
        message = MessageContainer(
            "Error",
            "Authentication failed, incorrect username or password"
        )

    # Restart if activity_mode has changed
    if Prefs['activity_mode'] != last_activity_mode:
        log.info('Activity mode has changed, restarting plugin...')
        spawn(PlexMediaServer.restart_plugin)

    return message
Example #8
0
    def start(self):
        # Get current server version and save it to dict.
        server_version = PlexMediaServer.get_version()
        if server_version:
            Log('Server Version is %s' % server_version)
            Dict['server_version'] = server_version

        # Validate username/password
        spawn(self.validate_auth)

        # Check for updates
        self.update_checker.run_once(async=True)

        self.session_manager.start()

        # Start modules
        for module in self.modules:
            if hasattr(module, 'start'):
                log.debug("Starting module %s", module)
                module.start()
    def start(cls, blocking=False):
        if not blocking:
            spawn(cls.start, blocking=True)
            return

        cls.log = Logger(cls.tag)
        cls.filter_available()

        # Test methods until an available method is found
        for weight, method in cls.available:
            if weight is None:
                cls.start_method(method)
            elif method.test():
                cls.start_method(method)
                break
            else:
                cls.log.info("method '%s' not available" % method.name)

        cls.log.info(
            'Finished starting %s method%s: %s',
            len(cls.enabled), plural(cls.enabled),
            ', '.join([("'%s'" % m.name) for m in cls.enabled])
        )
Example #10
0
    def start(self):
        # Check for authentication token
        log.info('X-Plex-Token: %s', 'available' if os.environ.get('PLEXTOKEN') else 'unavailable')

        # Validate username/password
        spawn(self.authenticate)

        # Start modules
        names = []

        for module in self.modules:
            if not hasattr(module, 'start'):
                continue

            names.append(get_class_name(module))

            module.start()

        log.info('Started %s modules: %s', len(names), ', '.join(names))

        ModuleManager.start()

        # Start plex.activity.py
        Activity.start(ACTIVITY_MODE.get(Prefs['activity_mode']))
    def start(cls, blocking=False):
        if not blocking:
            spawn(cls.start, blocking=True)
            return

        cls.filter_available()

        # Test methods until an available method is found
        for weight, method in cls.available:
            if weight is None:
                cls.start_method(method)
            elif method.test():
                cls.start_method(method)
                break
            else:
                log.info("method '%s' not available" % method.name, tag=cls.tag)

        log.info(
            'Finished starting %s method%s: %s',
            len(cls.enabled), plural(cls.enabled),
            ', '.join([("'%s'" % m.name) for m in cls.enabled]),

            tag=cls.tag
        )
    def queue(self, action, request, priority=3):
        if priority == 0:
            log.info('Maximum retries exceeded for "%s" action', action)
            return False

        # Store in queue
        self.action_queue.put((priority, action, request))

        log.debug('Queued "%s" action (priority: %s)', action, priority)

        # Ensure action thread has started
        if not self.action_thread:
            self.action_thread = spawn(self.process_actions)

        return True
Example #13
0
    def spawn(self, name):
        self.name = name

        spawn(self.run, thread_name=name)
    def start_method(cls, method):
        obj = method()
        cls.enabled.append(obj)

        spawn(obj.start)
Example #15
0
 def spawn(self, name):
     spawn(self.run, thread_name=name)
    def start_method(cls, method):
        obj = method()
        cls.enabled.append(obj)

        spawn(obj.start)
Example #17
0
 def start(self):
     # Construct main thread
     spawn(self.run, daemon=True, thread_name='main')
Example #18
0
 def start(self):
     # Construct main thread
     spawn(self.run, daemon=True, thread_name='main')