コード例 #1
0
def sitewide(request):
    """Variables that need to be inserted into all templates.
    """
    #label = storage.drive_label(mount_path)
    #mount_path = storage.base_path(request)
    label = request.session.get('storage_label', None)
    mount_path = request.session.get('storage_mount_path', None)
    device = {
        'path': '???',
        'type': 'unknown',
        'label': 'no storage',
        'more_info': '',
        'disk_space': '',
        'mounted': 0,
        'linked': 0,
        'status': '',
    }
    for d in storage.devices():
        if mount_path and d.get('mountpath',None) \
        and (d['mountpath'] == mount_path) and d['linked']:
            device = d
    device['type_label'] = BOOTSTRAP_COLORS['red']
    device['space_label'] = BOOTSTRAP_COLORS['red']
    device['status_label'] = BOOTSTRAP_COLORS['red']
    if device['mounted'] and device['linked']:
        device['type_label'] = BOOTSTRAP_COLORS['green']
        device['status_label'] = BOOTSTRAP_COLORS['green']
    # space
    space = storage.disk_space(mount_path)
    if space:
        for key,val in space.iteritems():
            device[key] = val
        # color of disk space pill
        percent = int(space.get('percent', 0))
        if percent:
            if   percent <= STORAGE_WARNING_THRESHOLD:
                device['space_label'] = BOOTSTRAP_COLORS['green']
            elif percent <= STORAGE_DANGER_THRESHOLD:
                device['type_label'] = BOOTSTRAP_COLORS['yellow']
                device['space_label'] = BOOTSTRAP_COLORS['yellow']
                device['status_label'] = BOOTSTRAP_COLORS['yellow']
            else:
                device['type_label'] = BOOTSTRAP_COLORS['red']
                device['space_label'] = BOOTSTRAP_COLORS['red']
                device['status_label'] = BOOTSTRAP_COLORS['red']
                device['disk_full_warning'] = STORAGE_DANGER_WARNING % (percent)
    return {
        'storage': device,
    }
コード例 #2
0
def sitewide(request):
    """Variables that need to be inserted into all templates.
    """
    storage_mount_path = storage.base_path(request)
    stype = storage.storage_type(storage_mount_path)
    sstatus = storage.storage_status(storage_mount_path)
    dspace = storage.disk_space(storage_mount_path)
    # change color of disk space pill
    if dspace and dspace.get('percent',None):
        if    dspace['percent'] <= 10: dspace['label'] = BOOTSTRAP_COLORS['red']
        elif  dspace['percent'] <= 30: dspace['label'] = BOOTSTRAP_COLORS['yellow']
        else:                          dspace['label'] = BOOTSTRAP_COLORS['green']
    return {
        'storage_root': storage_mount_path,
        'storage_type': stype,
        'storage_status': sstatus,
        'storage_space': dspace,
    }
コード例 #3
0
ファイル: tests_storage.py プロジェクト: gjost/ddr-cmdln-bkup
def test_disk_space():
    data = storage.disk_space('/')
    assert data.get('total')
    assert data.get('used')
    assert data.get('free')
    assert data.get('percent')
コード例 #4
0
ファイル: tests_storage.py プロジェクト: raux/ddr-cmdln
def test_disk_space():
    data = storage.disk_space('/')
    assert data.get('total')
    assert data.get('used')
    assert data.get('free')
    assert data.get('percent')