<filename>python_source/fotobox/hardware/storage.py
from fotobox import misc
from fotobox.file_system import USB_MOUNT_POINT, DCIM_PATH, IMG_CARD_PATH, mkdir_if_not_exist
import json


class UsbStorage(object):
    def __init__(self):
        # getting information about usb drive and mount usb-drive
        lsblk = json.loads(misc.execute_bash_command(['lsblk', '-JO']))
        for device in lsblk['blockdevices']:
            self.MOUNT_PATH = USB_MOUNT_POINT
            mkdir_if_not_exist(self.MOUNT_PATH)

            if device['name'] == "sda":
                vol = device['children'][0]
                self.name = vol['name']
                self.uuid = vol['uuid']
                self.volume_path = vol['path']
                self.fs_type = vol['fstype']
                self.mount_point = vol['mountpoint']

                mount_command: [str] = ['sudo', 'mount', '-t', self.fs_type, self.volume_path, self.MOUNT_PATH]
                if self.fs_type == "fat" or self.fs_type == "ntfs":
                    mount_command.append("-o")
                    mount_command.append("umask=000")

                misc.execute_bash_command(mount_command)

        # initializing file directories
        mkdir_if_not_exist(DCIM_PATH)
        mkdir_if_not_exist(IMG_CARD_PATH)

    def is_mounted(self):
        return self.mount_point == self.MOUNT_PATH
