コード例 #1
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def unmount_volumes(disk_id):
    # all volumes on a disk have an index attached e.g. /dev/sdb1, /dev/sdb2
    cmd = "fdisk -l | grep '%s[0-9][0-9]*' | awk '{print $1}'" % disk_id
    output, _, _ = run_cmd(cmd)

    # it may also happen that the disk does not have volumes
    # in which case the loop below won't do anything
    for volume in output.splitlines():
        cmd = 'umount {}'.format(volume)
        _, error, return_code = run_cmd(cmd)
        if not return_code:
            debugger('volume {} successfully unmounted'.format(volume))
        else:
            debugger('[ERROR] ' + error.strip('\n'))
コード例 #2
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def unmount_volumes(disk_id):
    # all volumes on a disk have an index attached e.g. /dev/sdb1, /dev/sdb2
    cmd = "fdisk -l | grep '%s[0-9][0-9]*' | awk '{print $1}'" % disk_id
    output, _, _ = run_cmd(cmd)

    # it may also happen that the disk does not have volumes
    # in which case the loop below won't do anything
    for volume in output.splitlines():
        cmd = 'umount {}'.format(volume)
        _, error, return_code = run_cmd(cmd)
        if not return_code:
            debugger('volume {} successfully unmounted'.format(volume))
        else:
            debugger('[ERROR] ' + error.strip('\n'))
コード例 #3
0
def format_disk(disk_id):
    cmd = 'diskutil eraseDisk fat32 UNTITLED {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully erased and formatted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #4
0
ファイル: disk.py プロジェクト: wooyek/kano-burners
def get_disk_ids():
    cmd = "diskutil list | grep '/dev/'"
    output, error, return_code = run_cmd(cmd)

    if not return_code:
        return output.split()
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #5
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def format_disk(disk_id):
    cmd = 'mkdosfs -I -F 32 -v {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully erased and formatted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #6
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def format_disk(disk_id):
    cmd = 'diskutil eraseDisk fat32 UNTITLED {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully erased and formatted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #7
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def unmount_disk(disk_id):
    cmd = 'diskutil unmountDisk {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #8
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def get_disk_ids():
    cmd = "diskutil list | grep '/dev/'"
    output, error, return_code = run_cmd(cmd)

    if not return_code:
        return output.split()
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #9
0
def unmount_disk(disk_id):
    cmd = 'diskutil unmountDisk {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #10
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def format_disk(disk_id):
    cmd = 'mkdosfs -I -F 32 -v {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully erased and formatted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #11
0
ファイル: disk.py プロジェクト: wooyek/kano-burners
def unmount_disk(disk_id):
    cmd = 'diskutil unmountDisk {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR: {}] {}'.format(cmd, error.strip('\n')))
        raise disk_error(UNMOUNT_ERROR)
コード例 #12
0
ファイル: dependency.py プロジェクト: elyscape/kano-burners
def is_installed(programs_list):
    cmd = 'which {}'.format(' '.join(programs_list))
    output, error, return_code = run_cmd(cmd)

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))
        return True  # if something goes wrong here, it shouldn't be catastrophic

    return len(output.split()) == len(programs_list)
コード例 #13
0
ファイル: dependency.py プロジェクト: wooyek/kano-burners
def is_installed(programs_list):
    cmd = 'which {}'.format(' '.join(programs_list))
    output, error, return_code = run_cmd(cmd)

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))
        return True  # if something goes wrong here, it shouldn't be catastrophic

    return len(output.split()) == len(programs_list)
コード例 #14
0
ファイル: disk.py プロジェクト: langgaibo/kano-burners
def unmount_disk(disk_id):
    cmd = 'diskutil unmountDisk {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR: {}] {}'.format(cmd,  error.strip('\n')))
        raise disk_error(UNMOUNT_ERROR)
コード例 #15
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def unmount_disk(disk_id):
    # to unmount an entire disk, we first need to unmount all it's volumes
    unmount_volumes(disk_id)

    # now we can safely unmount the disk
    cmd = 'umount {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)
    if not return_code:
        debugger('disk {} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #16
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def unmount_disk(disk_id):
    # to unmount an entire disk, we first need to unmount all it's volumes
    unmount_volumes(disk_id)

    # now we can safely unmount the disk
    cmd = 'umount {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)
    if not return_code:
        debugger('disk {} successfully unmounted'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #17
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def get_disk_ids():
    cmd = "parted --list | grep 'Disk /dev/.*:' | awk '{print $2}'"
    output, error, return_code = run_cmd(cmd)

    disk_ids = []
    for id in output.splitlines():
        disk_ids.append(id[:-1])

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    return disk_ids
コード例 #18
0
ファイル: dependency.py プロジェクト: wooyek/kano-burners
def is_sufficient_space(required_mb):
    cmd = "df %s | grep -v 'Available' | awk '{print $4}'" % temp_path
    output, _, _ = run_cmd(cmd)

    try:
        free_space_mb = float(output.strip()) * 512 / BYTES_IN_MEGABYTE
    except:
        debugger('[ERROR] Failed parsing the line ' + output)
        return True

    debugger('Free space {0:.2f} MB in {1}'.format(free_space_mb, temp_path))
    return free_space_mb > required_mb
コード例 #19
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def get_disk_ids():
    cmd = "parted --list | grep 'Disk /dev/.*:' | awk '{print $2}'"
    output, error, return_code = run_cmd(cmd)

    disk_ids = []
    for id in output.splitlines():
        disk_ids.append(id[:-1])

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    return disk_ids
コード例 #20
0
ファイル: dependency.py プロジェクト: elyscape/kano-burners
def is_sufficient_space(path, required_mb):
    cmd = "df %s | grep -v 'Available' | awk '{print $4}'" % path
    output, _, _ = run_cmd(cmd)

    try:
        free_space_mb = float(output.strip()) * 512 / BYTES_IN_MEGABYTE
    except:
        debugger('[ERROR] Failed parsing the line ' + output)
        return True

    debugger('Free space {0:.2f} MB in {1}'.format(free_space_mb, path))
    return free_space_mb > required_mb
コード例 #21
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def eject_disk(disk_id):
    '''
    This method is used by the backendThread to ensure safe removal
    after burning finished successfully.
    '''

    cmd = 'diskutil eject {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully ejected'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #22
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def eject_disk(disk_id):
    '''
    This method is used by the backendThread to ensure safe removal
    after burning finished successfully.
    '''

    cmd = 'eject {}'.format(disk_id)
    _, error, return_code = run_cmd(cmd)

    if not return_code:
        debugger('{} successfully ejected'.format(disk_id))
    else:
        debugger('[ERROR] ' + error.strip('\n'))
コード例 #23
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def get_disk_sizes():
    cmd = "fdisk -l | grep 'Disk /dev/'"
    output, error, return_code = run_cmd(cmd)

    disk_sizes = []
    for line in sorted(output.splitlines()):
        size = line.split()[4]
        disk_sizes.append(float(size) / BYTES_IN_GIGABYTE)

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    return disk_sizes
コード例 #24
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def get_disk_names():
    cmd = "parted --list | grep 'Model:'"
    output, error, return_code = run_cmd(cmd)

    disk_names = []
    for name in output.splitlines():
        disk_names.append(' '.join(name.split()[1:-1]))

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    # grab the first line of the output and the name is from the 4th word onwards
    return disk_names
コード例 #25
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def get_disk_names():
    cmd = "parted --list | grep 'Model:'"
    output, error, return_code = run_cmd(cmd)

    disk_names = []
    for name in output.splitlines():
        disk_names.append(' '.join(name.split()[1:-1]))

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    # grab the first line of the output and the name is from the 4th word onwards
    return disk_names
コード例 #26
0
ファイル: disk.py プロジェクト: gerito1/kano-burners
def get_disk_sizes():
    cmd = "fdisk -l | grep 'Disk /dev/'"
    output, error, return_code = run_cmd(cmd)

    disk_sizes = []
    for line in sorted(output.splitlines()):
        size = line.split()[4]
        disk_sizes.append(float(size) / BYTES_IN_GIGABYTE)

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    return disk_sizes
コード例 #27
0
ファイル: burn.py プロジェクト: KanoComputing/kano-burners
def poll_burning_thread(thread):
    time.sleep(1)  # wait for dd to start
    debugger('Polling burner for progress..')
    cmd = 'kill -INFO `pgrep ^dd`'

    # as long as the burning thread is running, send SIGINFO
    # to dd to trigger progress output
    while thread.is_alive():
        _, error, return_code = run_cmd(cmd)
        if return_code:
            debugger('[ERROR] Sending signal to burning thread failed')
            return False
        time.sleep(0.3)
    return True
コード例 #28
0
ファイル: burn.py プロジェクト: wooyek/kano-burners
def poll_burning_thread(thread):
    time.sleep(1)  # wait for dd to start
    debugger('Polling burner for progress..')
    cmd = 'kill -INFO `pgrep ^dd`'

    # as long as the burning thread is running, send SIGINFO
    # to dd to trigger progress output
    while thread.is_alive():
        _, error, return_code = run_cmd(cmd)
        if return_code:
            debugger('[ERROR] Sending signal to burning thread failed')
            return False
        time.sleep(0.3)
    return True
コード例 #29
0
ファイル: disk.py プロジェクト: wooyek/kano-burners
def get_disk_name_size(disk_id):
    cmd = "parted {} unit B print".format(disk_id)
    output, error, return_code = run_cmd(cmd)

    disk_name = ''
    disk_size = 0

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    for line in output.splitlines():
        if 'Model:' in line:
            disk_name = ' '.join(line.split()[1:])
        if 'Disk {}:'.format(disk_id) in line:
            disk_size = float(line[:-1].split()[2]) / BYTES_IN_GIGABYTE

    if not disk_name or not disk_size:
        debugger('[ERROR] Parsing disk name and size failed')

    return disk_name, disk_size
コード例 #30
0
ファイル: disk.py プロジェクト: KanoComputing/kano-burners
def get_disk_name_size(disk_id):
    cmd = "parted {} unit B print".format(disk_id)
    output, error, return_code = run_cmd(cmd)

    disk_name = ''
    disk_size = 0

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    for line in output.splitlines():
        if 'Model:' in line:
            disk_name = ' '.join(line.split()[1:])
        if 'Disk {}:'.format(disk_id) in line:
            disk_size = float(line[:-1].split()[2]) / BYTES_IN_GIGABYTE

    if not disk_name or not disk_size:
        debugger('[ERROR] Parsing disk name and size failed')

    return disk_name, disk_size
コード例 #31
0
ファイル: disk.py プロジェクト: wooyek/kano-burners
def get_disk_name_size(disk_id):
    cmd = "diskutil info {}".format(disk_id)
    output, error, return_code = run_cmd(cmd)

    disk_name = ''
    disk_size = 0

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    for line in output.splitlines():
        if 'Device / Media Name:' in line:
            disk_name = ' '.join(line.split()[4:])
        if 'Total Size:' in line:
            disk_size = float(line.split()[4][1:]) / BYTES_IN_GIGABYTE

    if not disk_name or not disk_size:
        debugger('[ERROR] Parsing disk name and size failed')

    return disk_name, disk_size
コード例 #32
0
ファイル: disk.py プロジェクト: elyscape/kano-burners
def get_disk_name_size(disk_id):
    cmd = "diskutil info {}".format(disk_id)
    output, error, return_code = run_cmd(cmd)

    disk_name = ''
    disk_size = 0

    if return_code:
        debugger('[ERROR] ' + error.strip('\n'))

    for line in output.splitlines():
        if 'Device / Media Name:' in line:
            disk_name = ' '.join(line.split()[4:])
        if 'Total Size:' in line:
            disk_size = float(line.split()[4][1:]) / BYTES_IN_GIGABYTE

    if not disk_name or not disk_size:
        debugger('[ERROR] Parsing disk name and size failed')

    return disk_name, disk_size