Example #1
0
def index( request ):
    """Interface for mounting/unmounting drives and setting active device
    """
    devices = storage.devices()
    # device state
    for device in devices:
        device['state'] = []
        if device['mounted']:
            device['state'].append('mounted')
        if device['mounting']:
            device['state'].append('mounting')
        if device['linked']:
            device['state'].append('linked')
    # put form data for each action button in devices
    for device in devices:
        device['action_forms'] = []
        for action in device.get('actions'):
            form = {
                'url': reverse(
                    'storage-operation', args=(action, device['devicetype'],)),
                'action': action,
            }
            device['action_forms'].append(form)
    return render(request, 'storage/index.html', {
        'devices': devices,
    })
Example #2
0
def mount_in_bkgnd(devicetype, devicefile):
    device = None
    for d in storage.devices():
        if d['devicefile'] == devicefile:
            device = d
    if not device:
        raise Exception('Device %s not in list of devices' % devicefile)
    
    if devicetype == 'hd':
        assert False
    elif devicetype == 'usb':
        return mount_usb(device)
    return
Example #3
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,
    }