Esempio n. 1
0
def list_uuids():
    items = []
    for res in Host.find({'disks': {'$exists': True}}):
        for disk in res['disks']:
            disk['host'] = res['host']
            items.append(disk)

    return serialize({'result': items})
Esempio n. 2
0
def list_services():
    items = []
    for name in sorted(dmon.list()):
        items.append({
            'name': name,
            'script': dmon.get(name),
            'status': dmon.get_pid(name) is not None,
        })
    return serialize({'result': items})
Esempio n. 3
0
def list_settings():
    settings = {}
    for section in ('media_filters', 'search_filters', 'media_langs',
            'subtitles_langs', 'sync', 'paths', 'opensubtitles',
            'netflix', 'filestube', 'rutracker', 'email', 'google_api',
            'google_api_credentials', 'google_drive'):
        settings[section] = Settings.get_settings(section)
    _set_default_settings(settings)
    return serialize({'result': settings})
Esempio n. 4
0
def list_services():
    items = []
    for name in sorted(dmon.list()):
        items.append({
                'name': name,
                'script': dmon.get(name),
                'status': dmon.get_pid(name) is not None,
                })
    return serialize({'result': items})
Esempio n. 5
0
def list_media(type, skip, limit):
    cache = {}
    spec = {}

    category = request.args.get('category')
    if category:
        if type in ('search', 'similar'):
            spec['category'] = category
        else:
            spec['info.subtype'] = category
    query = request.args.get('query')
    if query:
        spec.update(_get_search_spec(query))

    sort = request.args.get('sort', 'date')
    if sort == 'name':
        sort = [('name', ASCENDING)]
    elif sort == 'rating':
        sort = [('rating', DESCENDING)]
    else:
        sort = [('date', DESCENDING), ('created', DESCENDING)]

    params = {'sort': sort, 'skip': skip, 'limit': limit}
    items = []

    if type == 'media':
        for res in Media.find(spec, **params):
            search = Media.get_search(res)
            items.append(_get_object(res, type=type,
                    has_search=_has_search(cache, search),
                    has_similar=_has_similar(cache, search)))

    elif type == 'release':
        for res in Release.find(spec, **params):
            search = Release.get_search(res)
            items.append(_get_object(res, type=type,
                    has_search=_has_search(cache, search),
                    has_similar=_has_similar(cache, search)))

    elif type == 'search':
        for res in Search.find(spec, **params):
            items.append(_get_object(res, type=type,
                    has_search=True,
                    has_similar=_has_similar(cache, res)))

    elif type == 'similar':
        for res in SimilarSearch.find(spec, **params):
            items.append(_get_object(res, type=type,
                    has_similar=True))

    return serialize({'result': items})
Esempio n. 6
0
def list_hosts():
    items = []
    for res in Host.find(sort=[('seen', DESCENDING)]):
        res['all_users'] = []
        res['logged_users'] = []
        for user in res.get('users', []):
            res['all_users'].append(user['_id'])
            if user.get('logged'):
                user_ = get_user(user['_id'])
                if user_:
                    res['logged_users'].append(user_['name'])

        items.append(res)

    return serialize({'result': items})
Esempio n. 7
0
def list_syncs():
    now = datetime.utcnow()
    items = []
    for res in Sync.find(sort=[('processed', DESCENDING)]):
        res['name'] = '%s to %s' % (_get_params_str(res['src']), _get_params_str(res['dst']))
        if res.get('transfer_id'):
            transfer = Transfer.find_one({'_id': ObjectId(res['transfer_id'])})
        else:
            transfer = None
        res['transfer'] = transfer or {}
        if not transfer:
            res['status'] = 'pending'
        elif transfer['finished'] and transfer['finished'] > now - timedelta(hours=res['recurrence'] + 24):
            res['status'] = 'ok'
        else:
            res['status'] = 'queued'

        items.append(res)

    return serialize({'result': items})
Esempio n. 8
0
def list_syncs():
    now = datetime.utcnow()
    sync_recurrence = timedelta(minutes=Settings.get_settings('sync')['recurrence'])
    items = []
    for res in Sync.find():
        date_ = res.get('processed')
        if date_ and date_ + sync_recurrence > now:
            res['status'] = 'ok'
        else:
            res['status'] = 'pending'

        media_id = res['parameters'].get('id')
        if not media_id:
            src = res['category']
        else:
            media = Media.get(media_id)
            src = media['name'] if media else media_id

        user = get_user(res['user'])
        dst = user['name'] if user else res['user']
        res['name'] = '%s to %s' % (src, dst)
        items.append(res)

    return serialize({'result': items})
Esempio n. 9
0
def get_search_results():
    data = request.json
    if not data.get('id'):
        return jsonify(error='missing id')
    id = ObjectId(data['id'])

    items = {}
    for res in Result.find({'search_id': id}, sort=[('date', DESCENDING)]):
        urls = res['url']
        if not isinstance(urls, (tuple, list)):
            urls = [urls]
        for i, url in enumerate(urls):
            seeds = res.get('seeds')
            if seeds == 0:
                continue
            items.setdefault(res['type'], [])
            item = {'url': url, 'size': res['size'], 'seeds': seeds}
            if len(urls) > 1:
                item['title'] = '%s (%s/%s)' % (res['title'], i + 1, len(urls))
            else:
                item['title'] = res['title']
            items[res['type']].append(item)

    return serialize({'result': items})
Esempio n. 10
0
def list_users():
    items = []
    for res in User.find(sort=[('name', ASCENDING)]):
        if not res.get('paths'):
            res['paths'] = {}

        res['status'] = False
        res['hosts'] = []
        logged = []
        for host in Host.find({'users': {'$elemMatch': {
                '_id': res['_id'],
                'logged': {'$exists': True},
                }}}):
            res['hosts'].append(host['host'])
            for user in host['users']:
                if user['_id'] == res['_id']:
                    logged.append(user['logged'])
                    if host['alive']:
                        res['status'] = True

        res['logged'] = max(logged) if logged else None
        items.append(res)

    return serialize({'result': items})
Esempio n. 11
0
def list_settings():
    settings = {}
    for section in ('general', 'paths', 'transmission',
            'torrent', 'sabnzbd', 'rsync'):
        settings[section] = Settings.get_settings(section)
    return serialize({'result': settings})
Esempio n. 12
0
def list_transfers():
    items = [_get_transfer(t) for t in Transfer.find({'finished': None})]
    return serialize({'result': items})
Esempio n. 13
0
def list_users():
    users = [_get_user(u) for u in get_users()]
    return serialize({'result': users})
Esempio n. 14
0
def list_settings():
    settings = {}
    for section in ('host', 'sync', 'email'):
        settings[section] = Settings.get_settings(section)
    return serialize({'result': settings})