def unlink(request, devicetype, basepath): device = None for d in devices(): if d.get('basepath') == basepath: device = d if not device: raise Exception('No device with basepath %s.' % basepath) ddrstorage.unlink() _unmount_common(request) if os.path.exists(settings.MEDIA_BASE): return 'err','Device %s could not be unlinked.' % device['label'] return 'ok','Device %s has been unlinked.' % device['label']
def mount_hdd( request, device ): """ @param request: Django request object; used to access session. @param mount_path: Absolute path to mounted device; "/ddr" will be appended. """ logger.debug('mount_hdd(%s, %s)' % (device['mountpath'], device['label'])) logger.debug('device: %s' % device) ddrstorage.unlink() ddrstorage.link(device['mountpath']) _mount_common(request, device['devicefile'], device['label'], device['mountpath']) MB = settings.MEDIA_BASE if os.path.exists(MB) and os.path.islink(MB) and os.access(MB,os.W_OK): messages.success(request, '<strong>%s</strong> is now the active device.' % device['mountpath']) else: messages.error(request, 'Could not make <strong>%s</strong> the active device.' % device['mountpath']) return device['mountpath']
def unmount_usb(request, device): """Removes /var/www/ddr/media symlink, unmounts requested device, gives feedback. @param request: Django request object; used to access session. @param device: dict containing device info. See DDR.storage.devices. """ logger.debug('unmount(%s, %s)' % (device['devicefile'], device['label'])) unmounted = ddrstorage.umount(device['devicefile']) logger.debug('unmounted: %s' % unmounted) ddrstorage.unlink() _unmount_common(request) if unmounted: msg = STORAGE_MESSAGES['UNMOUNT_SUCCESS'].format(device['label']) messages.success(request, msg) elif unmounted == False: msg = STORAGE_MESSAGES['UNMOUNT_FAIL_1'].format( device['devicefile'], device['label'], stat, mounted) messages.warning(request, msg) else: msg = STORAGE_MESSAGES['UNMOUNT_FAIL'].format( devicefile, label, stat, mounted) messages.error(request, msg) return unmounted
def mount_usb( request, device ): """Mounts requested device, adds /var/www/ddr/media symlink, gives feedback. """ logger.debug('mount_usb(devicefile=%s, label=%s)' % (device['devicefile'], device['label'])) logger.debug('device: %s' % device) mount_path = ddrstorage.mount(device['devicefile'], device['label']) logger.debug('mount_path: %s' % mount_path) if mount_path: ddrstorage.unlink() if device.get('mountpath'): ddrstorage.link(device['mountpath']) _mount_common(request, device['devicefile'], device['label'], device['mountpath']) msg = STORAGE_MESSAGES['MOUNT_SUCCESS'].format(device['label']) messages.success(request, msg) elif mount_path == False: msg = STORAGE_MESSAGES['MOUNT_FAIL_PATH'].format( device['devicefile'], device['label'], stat, mount_path) messages.warning(request, msg) else: msg = STORAGE_MESSAGES['MOUNT_FAIL'].format( device['devicefile'], device['label'], stat, mount_path) messages.error(request, msg) return mount_path