Esempio n. 1
0
def get_cdrom_drives():
    """List available disc drives on the machine
    """
    # add default drive from libdiscid to the list
    drives = list(DEFAULT_DRIVES)

    if IS_WIN:
        GetLogicalDrives = windll.kernel32.GetLogicalDrives
        GetDriveType = windll.kernel32.GetDriveTypeW
        DRIVE_CDROM = 5
        mask = GetLogicalDrives()
        for i in range(26):
            if mask >> i & 1:
                drive = chr(i + ord("A")) + ":"
                if GetDriveType(drive) == DRIVE_CDROM:
                    drives.append(drive)

    elif IS_LINUX and AUTO_DETECT_DRIVES:
        # Read info from /proc/sys/dev/cdrom/info
        cdinfo = QFile(LINUX_CDROM_INFO)
        if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
            drive_names = []
            drive_audio_caps = []
            while True:
                line = bytes(cdinfo.readLine()).decode()
                if not line:
                    break
                if ":" in line:
                    key, values = line.split(':')
                    if key == 'drive name':
                        drive_names = values.split()
                    elif key == 'Can play audio':
                        drive_audio_caps = [v == '1' for v in values.split()]
                        break  # no need to continue past this line
            # Show only drives that are capable of playing audio
            for index, drive in enumerate(drive_names):
                if drive_audio_caps[index]:
                    device = '/dev/%s' % drive
                    symlink_target = QFile.symLinkTarget(device)
                    if symlink_target != '':
                        device = symlink_target
                    drives.append(device)

    else:
        config = get_config()
        for device in config.setting["cd_lookup_device"].split(","):
            # Need to filter out empty strings,
            # particularly if the device list is empty
            if device.strip() != '':
                drives.append(device.strip())

    # make sure no drive is listed twice (given by multiple sources)
    return sorted(uniqify(drives))
Esempio n. 2
0
File: cdrom.py Progetto: zas/picard
def get_cdrom_drives():
    """List available disc drives on the machine
    """
    # add default drive from libdiscid to the list
    drives = list(DEFAULT_DRIVES)

    if IS_WIN:
        GetLogicalDrives = windll.kernel32.GetLogicalDrives
        GetDriveType = windll.kernel32.GetDriveTypeW
        DRIVE_CDROM = 5
        mask = GetLogicalDrives()
        for i in range(26):
            if mask >> i & 1:
                drive = chr(i + ord("A")) + ":"
                if GetDriveType(drive) == DRIVE_CDROM:
                    drives.append(drive)

    elif IS_LINUX and QFile.exists(LINUX_CDROM_INFO):
        # Read info from /proc/sys/dev/cdrom/info
        cdinfo = QFile(LINUX_CDROM_INFO)
        if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
            drive_names = []
            drive_audio_caps = []
            while True:
                line = bytes(cdinfo.readLine()).decode()
                if not line:
                    break
                if ":" in line:
                    key, values = line.split(':')
                    if key == 'drive name':
                        drive_names = values.split()
                    elif key == 'Can play audio':
                        drive_audio_caps = [v == '1' for v in values.split()]
                        break  # no need to continue past this line
            # Show only drives that are capable of playing audio
            for index, drive in enumerate(drive_names):
                if drive_audio_caps[index]:
                    device = '/dev/%s' % drive
                    symlink_target = QFile.symLinkTarget(device)
                    if symlink_target != '':
                        device = symlink_target
                    drives.append(device)

    else:
        for device in config.setting["cd_lookup_device"].split(","):
            # Need to filter out empty strings,
            # particularly if the device list is empty
            if device.strip() != '':
                drives.append(device.strip())

    # make sure no drive is listed twice (given by multiple sources)
    return sorted(uniqify(drives))