Example #1
0
def create_active_item(oc):
    task, handler = SyncManager.get_current()
    if not task:
        return

    # Format values
    remaining = format_remaining(task.statistics.seconds_remaining)
    progress = format_percentage(task.statistics.progress)

    # Title
    title = '%s - Status' % handler.title

    if progress:
        title += ' (%s)' % progress

    # Summary
    summary = task.statistics.message or 'Working'

    if remaining:
        summary += ', ~%s second%s remaining' % (remaining, plural(remaining))

    # Create items
    oc.add(
        DirectoryObject(key=Callback(SyncMenu, refresh=timestamp()),
                        title=pad_title(title),
                        summary=summary + ' (click to refresh)'))

    oc.add(
        DirectoryObject(key=Callback(Cancel),
                        title=pad_title('%s - Cancel' % handler.title)))
def create_active_item(oc):
    task, handler = SyncManager.get_current()
    if not task:
        return

    # Format values
    remaining = format_remaining(task.statistics.seconds_remaining)
    progress = format_percentage(task.statistics.progress)

    # Title
    title = '%s - Status' % normalize(handler.title)

    if progress:
        title += ' (%s)' % progress

    # Summary
    summary = task.statistics.message or 'Working'

    if remaining:
        summary += ', ~%s second%s remaining' % (remaining, plural(remaining))

    # Create items
    oc.add(DirectoryObject(
        key=Callback(SyncMenu, refresh=timestamp()),
        title=pad_title(title),
        summary=summary + ' (click to refresh)'
    ))

    oc.add(DirectoryObject(
        key=Callback(Cancel),
        title=pad_title('%s - Cancel' % normalize(handler.title))
    ))
def ListMessages(days=14, version='latest', viewed=False, *args, **kwargs):
    # Cast `viewed` to boolean
    if type(viewed) is str:
        if viewed == 'None':
            viewed = None
        else:
            viewed = viewed == 'True'

    # Retrieve messages
    messages = list(
        List(days=try_convert(days, int), version=version,
             viewed=viewed).order_by(Message.last_logged_at.desc()).limit(50))

    total_messages = List(
        days=try_convert(days, int),
        version=version,
    ).count()

    # Construct container
    oc = ObjectContainer(title2=_("Messages"))

    if viewed is False and len(messages) > 1:
        oc.add(
            DirectoryObject(key=Callback(DismissMessages),
                            title=pad_title(_("Dismiss all"))))

    for m in messages:
        if m.type is None or\
           m.summary is None:
            continue

        thumb = None

        if m.type == Message.Type.Exception:
            thumb = R("icon-exception-viewed.png") if m.viewed else R(
                "icon-exception.png")
        elif m.type == Message.Type.Info:
            thumb = R("icon-notification-viewed.png") if m.viewed else R(
                "icon-notification.png")
        elif m.type in ERROR_TYPES:
            thumb = R("icon-error-viewed.png") if m.viewed else R(
                "icon-error.png")

        oc.add(
            DirectoryObject(
                key=Callback(ViewMessage, error_id=m.id),
                title=pad_title('[%s] %s' %
                                (Message.Type.title(m.type), m.summary)),
                thumb=thumb))

    # Append "View All" button
    if len(messages) != 50 and len(messages) < total_messages:
        oc.add(
            DirectoryObject(key=Callback(ListMessages, days=None, viewed=None),
                            title=pad_title(_("View All"))))

    return oc
def ViewMessage(error_id, *args, **kwargs):
    # Retrieve message from database
    message = MessageManager.get.by_id(error_id)

    # Update `last_viewed_at` field
    message.last_viewed_at = datetime.utcnow()
    message.save()

    # Parse request headers
    web_client = Request.Headers.get('X-Plex-Product',
                                     '').lower() == 'plex web'

    # Build objects
    oc = ObjectContainer(
        title2='[%s] %s' %
        (Message.Type.title(message.type), Trim(message.summary)))

    if message.type == Message.Type.Exception:
        # Display exception samples
        for e in message.exceptions.order_by(
                Exception.timestamp.desc()).limit(50):
            since = datetime.utcnow() - e.timestamp

            callback = Callback(ViewMessage, error_id=error_id)

            if web_client:
                # Display exception traceback in Plex/Web
                callback = Callback(ViewException, exception_id=e.id)

            oc.add(
                DirectoryObject(
                    key=callback,
                    title=pad_title(
                        '[%s] %s: %s' %
                        (human(since, precision=1), e.type, e.message)),
                    thumb=R("icon-exception.png")))
    elif message.type in [
            Message.Type.Info, Message.Type.Warning, Message.Type.Error,
            Message.Type.Critical
    ]:
        # Display message code
        oc.add(
            DirectoryObject(key='',
                            title=pad_title(_('Code: %s') %
                                            hex(message.code))))

        # Display message description
        if message.description:
            oc.add(
                DirectoryObject(key='',
                                title=pad_title(
                                    _('Description: %s') %
                                    message.description)))

    return oc
Example #5
0
def AboutMenu(*args, **kwargs):
    oc = ObjectContainer(title2=_("About"))

    oc.add(
        DirectoryObject(key=Callback(ListMessages, days=None, viewed=None),
                        title=pad_title(_("Messages"))))

    oc.add(
        DirectoryObject(key=Callback(AboutMenu),
                        title=pad_title(_("Version: %s") % PLUGIN_VERSION)))

    return oc
def AboutMenu():
    oc = ObjectContainer(title2="About")

    oc.add(DirectoryObject(
        key=Callback(CacheStatisticsMenu),
        title=pad_title("Cache Statistics")
    ))

    oc.add(DirectoryObject(
        key=Callback(AboutMenu),
        title=pad_title("Version: %s" % PLUGIN_VERSION)
    ))

    return oc
Example #7
0
def AboutMenu():
    oc = ObjectContainer(title2="About")

    oc.add(DirectoryObject(
        key=Callback(ListMessages, viewed=None),
        title=pad_title("Messages")
    ))

    oc.add(DirectoryObject(
        key=Callback(AboutMenu),
        title=pad_title("Version: %s" % PLUGIN_VERSION)
    ))

    return oc
def ListMessages(viewed=None):
    # Cast `viewed` to boolean
    if type(viewed) is str:
        if viewed == 'None':
            viewed = None
        else:
            viewed = viewed == 'True'

    # Retrieve messages
    messages = list(List(
        viewed=viewed
    ).order_by(
        Message.last_logged_at.desc()
    ).limit(50))

    total_messages = List().count()

    # Construct container
    oc = ObjectContainer(
        title2="Messages"
    )

    for m in messages:
        if m.type is None or\
           m.summary is None:
            continue

        thumb = None

        if m.type == Message.Type.Exception:
            thumb = R("icon-exception-viewed.png") if m.viewed else R("icon-exception.png")
        elif m.type == Message.Type.Info:
            thumb = R("icon-notification-viewed.png") if m.viewed else R("icon-notification.png")
        elif m.type in ERROR_TYPES:
            thumb = R("icon-error-viewed.png") if m.viewed else R("icon-error.png")

        oc.add(DirectoryObject(
            key=Callback(ViewMessage, error_id=m.id),
            title=pad_title('[%s] %s' % (Message.Type.title(m.type), m.summary)),
            thumb=thumb
        ))

    # Append "View More" button
    if len(messages) != 50 and len(messages) < total_messages:
        oc.add(DirectoryObject(
            key=Callback(ListMessages),
            title=pad_title("View All")
        ))

    return oc
def ViewException(exception_id):
    # Retrieve exception from database
    exception = ExceptionManager.get.by_id(exception_id)

    # Split traceback into lines
    traceback = exception.traceback

    if traceback:
        traceback = traceback.split('\n')

    # Build exception view
    oc = ObjectContainer(
        title2='%s: %s' % (exception.type, Trim(exception.message))
    )

    if not traceback:
        return oc

    for line in traceback:
        if not line:
            continue

        length = len(line)

        line = line.lstrip()
        spaces = length - len(line)

        oc.add(DirectoryObject(
            key=Callback(ViewException, exception_id=exception_id),
            title=pad_title(('&nbsp;' * spaces) + line)
        ))

    return oc
def ViewException(exception_id, *args, **kwargs):
    # Retrieve exception from database
    exception = ExceptionManager.get.by_id(exception_id)

    # Split traceback into lines
    traceback = exception.traceback

    if traceback:
        traceback = traceback.split('\n')

    # Build exception view
    oc = ObjectContainer(
        title2='%s: %s' % (exception.type, Trim(exception.message))
    )

    if not traceback:
        return oc

    for line in traceback:
        if not line:
            continue

        oc.add(DirectoryObject(
            key=Callback(ViewException, exception_id=exception_id),
            title=pad_title(line)
        ))

    return oc
def ViewException(exception_id, *args, **kwargs):
    # Retrieve exception from database
    exception = ExceptionManager.get.by_id(exception_id)

    # Split traceback into lines
    traceback = exception.traceback

    if traceback:
        traceback = traceback.split('\n')

    # Build exception view
    oc = ObjectContainer(title2='%s: %s' %
                         (exception.type, Trim(exception.message)))

    if not traceback:
        return oc

    for line in traceback:
        if not line:
            continue

        length = len(line)

        line = line.lstrip()
        spaces = length - len(line)

        oc.add(
            DirectoryObject(key=Callback(ViewException,
                                         exception_id=exception_id),
                            title=pad_title(('&nbsp;' * spaces) + line)))

    return oc
Example #12
0
def AboutMenu(*args, **kwargs):
    oc = ObjectContainer(
        title2=_("About")
    )

    oc.add(DirectoryObject(
        key=Callback(ListMessages, days=None, viewed=None),
        title=pad_title(_("Messages"))
    ))

    oc.add(DirectoryObject(
        key=Callback(AboutMenu),
        title=pad_title(_("Version: %s") % PLUGIN_VERSION)
    ))

    return oc
def ViewMessage(error_id):
    # Retrieve message from database
    message = MessageManager.get.by_id(error_id)

    # Update `last_viewed_at` field
    message.last_viewed_at = datetime.utcnow()
    message.save()

    # Parse request headers
    web_client = Request.Headers.get('X-Plex-Product', '').lower() == 'plex web'

    # Build objects
    oc = ObjectContainer(
        title2='[%s] %s' % (Message.Type.title(message.type), Trim(message.summary))
    )

    if message.type == Message.Type.Exception:
        # Display exception samples
        for e in message.exceptions.order_by(Exception.timestamp.desc()).limit(50):
            since = datetime.utcnow() - e.timestamp

            callback = Callback(ViewMessage, error_id=error_id)

            if web_client:
                # Display exception traceback in Plex/Web
                callback = Callback(ViewException, exception_id=e.id)

            oc.add(DirectoryObject(
                key=callback,
                title=pad_title('[%s] %s: %s' % (human(since, precision=1), e.type, e.message)),
                thumb=R("icon-exception.png")
            ))
    elif message.type in [Message.Type.Info, Message.Type.Warning, Message.Type.Error, Message.Type.Critical]:
        # Display message code
        oc.add(DirectoryObject(
            key='',
            title=pad_title('Code: %s' % hex(message.code))
        ))

        # Display message description
        if message.description:
            oc.add(DirectoryObject(
                key='',
                title=pad_title('Description: %s' % message.description)
            ))

    return oc
Example #14
0
def AboutMenu():
    oc = ObjectContainer(title2="About", no_cache=True)

    oc.add(DirectoryObject(
        key=Callback(AboutMenu),
        title=pad_title("Version: %s" % PLUGIN_VERSION)
    ))

    return oc
Example #15
0
def AboutMenu():
    oc = ObjectContainer(title2="About")

    oc.add(DirectoryObject(
        key=Callback(AboutMenu),
        title=pad_title("Version: %s" % PLUGIN_VERSION)
    ))

    return oc
def CacheStatisticsMenu():
    oc = ObjectContainer(title2="Cache Statistics")

    for item in CacheManager.statistics():
        oc.add(DirectoryObject(
            key='',
            title=pad_title("[%s] Cache Size: %s, Store Size: %s" % item)
        ))

    return oc
def SyncMenu(refresh=None):
    oc = ObjectContainer(title2=L('sync_menu:title'), no_history=True, no_cache=True)
    all_keys = []

    create_active_item(oc)

    oc.add(DirectoryObject(
        key=Callback(Synchronize),
        title=pad_title('Synchronize'),
        summary=get_task_status('synchronize'),
        thumb=R("icon-sync.png")
    ))

    f_allow, f_deny = get_filter('filter_sections')
    sections = Plex['library'].sections()

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(DirectoryObject(
            key=Callback(Push, section=section.key),
            title=pad_title('Push "%s" to trakt' % section.title),
            summary=get_task_status('push', section.key),
            thumb=R("icon-sync_up.png")
        ))
        all_keys.append(section.key)

    if len(all_keys) > 1:
        oc.add(DirectoryObject(
            key=Callback(Push),
            title=pad_title('Push all to trakt'),
            summary=get_task_status('push'),
            thumb=R("icon-sync_up.png")
        ))

    oc.add(DirectoryObject(
        key=Callback(Pull),
        title=pad_title('Pull from trakt'),
        summary=get_task_status('pull'),
        thumb=R("icon-sync_down.png")
    ))

    return oc
def SyncMenu(refresh=None):
    oc = ObjectContainer(title2=L("Sync"), no_history=True, no_cache=True)
    all_keys = []

    create_active_item(oc)

    oc.add(DirectoryObject(
        key=Callback(Synchronize),
        title=pad_title('Synchronize'),
        summary=get_task_status('synchronize'),
        thumb=R("icon-sync.png")
    ))

    sections = PlexMediaServer.get_sections(['show', 'movie'], titles=get_filter('filter_sections'))

    for _, key, title in sections:
        oc.add(DirectoryObject(
            key=Callback(Push, section=key),
            title=pad_title('Push "' + title + '" to trakt'),
            summary=get_task_status('push', key),
            thumb=R("icon-sync_up.png")
        ))
        all_keys.append(key)

    if len(all_keys) > 1:
        oc.add(DirectoryObject(
            key=Callback(Push),
            title=pad_title('Push all to trakt'),
            summary=get_task_status('push'),
            thumb=R("icon-sync_up.png")
        ))

    oc.add(DirectoryObject(
        key=Callback(Pull),
        title=pad_title('Pull from trakt'),
        summary=get_task_status('pull'),
        thumb=R("icon-sync_down.png")
    ))

    return oc
Example #19
0
def SyncMenu(refresh=None):
    oc = ObjectContainer(title2=L("Sync"), no_history=True, no_cache=True)
    all_keys = []

    create_active_item(oc)

    oc.add(
        DirectoryObject(key=Callback(Synchronize),
                        title=pad_title('Synchronize'),
                        summary=get_task_status('synchronize'),
                        thumb=R("icon-sync.png")))

    sections = PlexMediaServer.get_sections(
        ['show', 'movie'], titles=get_filter('filter_sections'))

    for _, key, title in sections:
        oc.add(
            DirectoryObject(key=Callback(Push, section=key),
                            title=pad_title('Push "' + title + '" to trakt'),
                            summary=get_task_status('push', key),
                            thumb=R("icon-sync_up.png")))
        all_keys.append(key)

    if len(all_keys) > 1:
        oc.add(
            DirectoryObject(key=Callback(Push),
                            title=pad_title('Push all to trakt'),
                            summary=get_task_status('push'),
                            thumb=R("icon-sync_up.png")))

    oc.add(
        DirectoryObject(key=Callback(Pull),
                        title=pad_title('Pull from trakt'),
                        summary=get_task_status('pull'),
                        thumb=R("icon-sync_down.png")))

    return oc
Example #20
0
def ControlsMenu(account_id=1,
                 title=None,
                 message=None,
                 refresh=None,
                 message_only=False,
                 *args,
                 **kwargs):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(title2=_("Sync (%s)") % account.name,
                         no_cache=True,
                         art=function_path('Cover.png',
                                           account_id=account.id,
                                           refresh=account.refreshed_ts))

    # Start result message
    if title and message:
        oc.add(
            DirectoryObject(key=Callback(ControlsMenu,
                                         account_id=account.id,
                                         refresh=timestamp()),
                            title=pad_title(title),
                            summary=message))

        if message_only:
            return oc

    # Active sync status
    Active.create(oc,
                  callback=Callback(ControlsMenu,
                                    account_id=account.id,
                                    refresh=timestamp()),
                  account=account)

    #
    # Full
    #

    oc.add(
        DirectoryObject(key=Trigger.callback(Synchronize, account),
                        title=pad_title(SyncMode.title(SyncMode.Full)),
                        summary=Status.build(account, SyncMode.Full),
                        thumb=R("icon-sync.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    #
    # Pull
    #

    oc.add(
        DirectoryObject(key=Trigger.callback(Pull, account),
                        title=pad_title(
                            _('%s from Trakt.tv') %
                            SyncMode.title(SyncMode.Pull)),
                        summary=Status.build(account, SyncMode.Pull),
                        thumb=R("icon-sync_down.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    oc.add(
        DirectoryObject(key=Trigger.callback(FastPull, account),
                        title=pad_title(
                            _('%s from Trakt.tv') %
                            SyncMode.title(SyncMode.FastPull)),
                        summary=Status.build(account, SyncMode.FastPull),
                        thumb=R("icon-sync_down.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception as ex:
        # Build message
        if p_account is None:
            message = _("Plex account hasn't been authenticated")
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s',
                 message,
                 exc_info=True)

        return redirect('/sync',
                        account_id=account_id,
                        title=_('Error'),
                        message=message,
                        message_only=True)

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(
            DirectoryObject(
                key=Trigger.callback(Push, account, section),
                title=pad_title(
                    _('%s "%s" to Trakt.tv') %
                    (SyncMode.title(SyncMode.Push), section.title)),
                summary=Status.build(account, SyncMode.Push, section.key),
                thumb=R("icon-sync_up.png"),
                art=function_path('Cover.png',
                                  account_id=account.id,
                                  refresh=account.refreshed_ts)))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(
            DirectoryObject(key=Trigger.callback(Push, account),
                            title=pad_title(
                                _('%s all to Trakt.tv') %
                                SyncMode.title(SyncMode.Push)),
                            summary=Status.build(account, SyncMode.Push),
                            thumb=R("icon-sync_up.png"),
                            art=function_path('Cover.png',
                                              account_id=account.id,
                                              refresh=account.refreshed_ts)))

    return oc
Example #21
0
 def build_cancel(cls, current, title):
     return DirectoryObject(key=Callback(Cancel,
                                         account_id=current.account.id,
                                         id=current.id),
                            title=pad_title(_('%s - Cancel') % title))
Example #22
0
 def build_status(cls, current, title, callback=None):
     return DirectoryObject(key=callback,
                            title=pad_title(_('%s - Status') % title),
                            summary=cls.build_status_summary(current))
Example #23
0
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False, *args, **kwargs):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(
        title2=_("Sync (%s)") % account.name,
        no_cache=True,

        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    )

    # Start result message
    if title and message:
        oc.add(DirectoryObject(
            key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
            title=pad_title(title),
            summary=message
        ))

        if message_only:
            return oc

    # Active sync status
    Active.create(
        oc,
        callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
        account=account
    )

    #
    # Full
    #

    oc.add(DirectoryObject(
        key=Trigger.callback(Synchronize, account),
        title=pad_title(SyncMode.title(SyncMode.Full)),
        summary=Status.build(account, SyncMode.Full),

        thumb=R("icon-sync.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Pull
    #

    oc.add(DirectoryObject(
        key=Trigger.callback(Pull, account),
        title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.Pull)),
        summary=Status.build(account, SyncMode.Pull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    oc.add(DirectoryObject(
        key=Trigger.callback(FastPull, account),
        title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.FastPull)),
        summary=Status.build(account, SyncMode.FastPull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception as ex:
        # Build message
        if p_account is None:
            message = _("Plex account hasn't been authenticated")
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True)

        return redirect('/sync',
            account_id=account_id,
            title=_('Error'),
            message=message,
            message_only=True
        )

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(DirectoryObject(
            key=Trigger.callback(Push, account, section),
            title=pad_title(_('%s "%s" to Trakt.tv') % (SyncMode.title(SyncMode.Push), section.title)),
            summary=Status.build(account, SyncMode.Push, section.key),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
        ))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(DirectoryObject(
            key=Trigger.callback(Push, account),
            title=pad_title(_('%s all to Trakt.tv') % SyncMode.title(SyncMode.Push)),
            summary=Status.build(account, SyncMode.Push),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
        ))

    return oc
Example #24
0
 def build_cancel(cls, current, title):
     return DirectoryObject(
         key=Callback(Cancel, account_id=current.account.id, id=current.id),
         title=pad_title(_('%s - Cancel') % title)
     )
Example #25
0
 def build_status(cls, current, title, callback=None):
     return DirectoryObject(
         key=callback,
         title=pad_title(_('%s - Status') % title),
         summary=cls.build_status_summary(current)
     )
Example #26
0
        return redirect('/sync',
            account_id=account_id,
            title='Error',
            message=message,
            message_only=True
        )

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(DirectoryObject(
            key=Callback(Push, account_id=account.id, section=section.key, refresh=timestamp()),
            title=pad_title('%s "%s" to trakt' % (SyncMode.title(SyncMode.Push), section.title)),
            summary=Status.build(account, SyncMode.Push, section.key),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
        ))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(DirectoryObject(
            key=Callback(Push, account_id=account.id, refresh=timestamp()),
            title=pad_title('%s all to trakt' % SyncMode.title(SyncMode.Push)),
            summary=Status.build(account, SyncMode.Push),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
Example #27
0
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(
        title2=LF('controls:title', account.name),
        no_cache=True,

        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    )

    # Start result message
    if title and message:
        oc.add(DirectoryObject(
            key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
            title=pad_title(title),
            summary=message
        ))

        if message_only:
            return oc

    # Active sync status
    Active.create(
        oc,
        callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
        account=account
    )

    #
    # Full
    #

    oc.add(DirectoryObject(
        key=Callback(Synchronize, account_id=account.id, refresh=timestamp()),
        title=pad_title(SyncMode.title(SyncMode.Full)),
        summary=Status.build(account, SyncMode.Full),

        thumb=R("icon-sync.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Pull
    #

    oc.add(DirectoryObject(
        key=Callback(Pull, account_id=account.id, refresh=timestamp()),
        title=pad_title('%s from trakt' % SyncMode.title(SyncMode.Pull)),
        summary=Status.build(account, SyncMode.Pull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    oc.add(DirectoryObject(
        key=Callback(FastPull, account_id=account.id, refresh=timestamp()),
        title=pad_title('%s from trakt' % SyncMode.title(SyncMode.FastPull)),
        summary=Status.build(account, SyncMode.FastPull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception, ex:
        # Build message
        if p_account is None:
            message = "Plex account hasn't been authenticated"
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True)

        return redirect('/sync',
            account_id=account_id,
            title='Error',
            message=message,
            message_only=True
        )
Example #28
0
        return redirect('/sync',
                        account_id=account_id,
                        title=_('Error'),
                        message=message,
                        message_only=True)

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(
            DirectoryObject(
                key=Trigger.callback(Push, account, section),
                title=pad_title(
                    _('%s "%s" to Trakt.tv') %
                    (SyncMode.title(SyncMode.Push), section.title)),
                summary=Status.build(account, SyncMode.Push, section.key),
                thumb=R("icon-sync_up.png"),
                art=function_path('Cover.png',
                                  account_id=account.id,
                                  refresh=account.refreshed_ts)))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(
            DirectoryObject(key=Trigger.callback(Push, account),
                            title=pad_title(
                                _('%s all to Trakt.tv') %
                                SyncMode.title(SyncMode.Push)),
                            summary=Status.build(account, SyncMode.Push),
def ListMessages(days=14, version='latest', viewed=False, *args, **kwargs):
    # Cast `viewed` to boolean
    if type(viewed) is str:
        if viewed == 'None':
            viewed = None
        else:
            viewed = viewed == 'True'

    # Retrieve messages
    messages = list(List(
        days=try_convert(days, int),
        version=version,
        viewed=viewed
    ).order_by(
        Message.last_logged_at.desc()
    ).limit(50))

    total_messages = List(
        days=try_convert(days, int),
        version=version,
    ).count()

    # Construct container
    oc = ObjectContainer(
        title2=_("Messages")
    )

    # Add "Dismiss All" button
    if viewed is False and len(messages) > 1:
        oc.add(DirectoryObject(
            key=Callback(DismissMessages),
            title=pad_title(_("Dismiss all"))
        ))

    # Add interface messages
    for record in InterfaceMessages.records:
        # Pick object thumb
        if record.level >= logging.WARNING:
            thumb = R("icon-error.png")
        else:
            thumb = R("icon-notification.png")

        # Add object
        oc.add(DirectoryObject(
            key=PLUGIN_PREFIX + '/messages/list',
            title=pad_title('[%s] %s' % (logging.getLevelName(record.level).capitalize(), record.message)),
            thumb=thumb
        ))

    # Add stored messages
    for m in messages:
        if m.type is None or\
           m.summary is None:
            continue

        # Pick thumb
        if m.type == Message.Type.Exception:
            thumb = R("icon-exception-viewed.png") if m.viewed else R("icon-exception.png")
        elif m.type == Message.Type.Info:
            thumb = R("icon-notification-viewed.png") if m.viewed else R("icon-notification.png")
        elif m.type in CONNECTION_TYPES:
            thumb = R("icon-connection-viewed.png") if m.viewed else R("icon-connection.png")
        else:
            thumb = R("icon-error-viewed.png") if m.viewed else R("icon-error.png")

        # Add object
        oc.add(DirectoryObject(
            key=Callback(ViewMessage, error_id=m.id),
            title=pad_title('[%s] %s' % (Message.Type.title(m.type), m.summary)),
            thumb=thumb
        ))

    # Append "View All" button
    if len(messages) != 50 and len(messages) < total_messages:
        oc.add(DirectoryObject(
            key=Callback(ListMessages, days=None, viewed=None),
            title=pad_title(_("View All"))
        ))

    return oc
Example #30
0
def ListMessages(days=14, version='latest', viewed=False, *args, **kwargs):
    # Cast `viewed` to boolean
    if type(viewed) is str:
        if viewed == 'None':
            viewed = None
        else:
            viewed = viewed == 'True'

    # Retrieve messages
    messages = list(
        List(days=try_convert(days, int), version=version,
             viewed=viewed).order_by(Message.last_logged_at.desc()).limit(50))

    total_messages = List(
        days=try_convert(days, int),
        version=version,
    ).count()

    # Construct container
    oc = ObjectContainer(title2=_("Messages"))

    # Add "Dismiss All" button
    if viewed is False and len(messages) > 1:
        oc.add(
            DirectoryObject(key=Callback(DismissMessages),
                            title=pad_title(_("Dismiss all"))))

    # Add interface messages
    for record in InterfaceMessages.records:
        # Pick object thumb
        if record.level >= logging.WARNING:
            thumb = R("icon-error.png")
        else:
            thumb = R("icon-notification.png")

        # Add object
        oc.add(
            DirectoryObject(key=PLUGIN_PREFIX + '/messages/list',
                            title=pad_title('[%s] %s' % (logging.getLevelName(
                                record.level).capitalize(), record.message)),
                            thumb=thumb))

    # Add stored messages
    for m in messages:
        if m.type is None or\
           m.summary is None:
            continue

        # Pick thumb
        if m.type == Message.Type.Exception:
            thumb = R("icon-exception-viewed.png") if m.viewed else R(
                "icon-exception.png")
        elif m.type == Message.Type.Info:
            thumb = R("icon-notification-viewed.png") if m.viewed else R(
                "icon-notification.png")
        elif m.type in CONNECTION_TYPES:
            thumb = R("icon-connection-viewed.png") if m.viewed else R(
                "icon-connection.png")
        else:
            thumb = R("icon-error-viewed.png") if m.viewed else R(
                "icon-error.png")

        # Add object
        oc.add(
            DirectoryObject(
                key=Callback(ViewMessage, error_id=m.id),
                title=pad_title('[%s] %s' %
                                (Message.Type.title(m.type), m.summary)),
                thumb=thumb))

    # Append "View All" button
    if len(messages) != 50 and len(messages) < total_messages:
        oc.add(
            DirectoryObject(key=Callback(ListMessages, days=None, viewed=None),
                            title=pad_title(_("View All"))))

    return oc