tools/mpi2udev.py
def parse_mpi(mpi, hwdb):
    '''Print udev rule for given ConfigParser object.'''

    cp = configparser.RawConfigParser()
    assert cp.read(mpi, encoding='UTF-8')

    rule = ''

    for name in ['usbvendor', 'usbproduct', 'usbmodel', 'usbmanufacturer']:
        try:
            value = cp.get('Device', name)
            rule += mpi2udev[name] % value + ', '
        except configparser.NoOptionError:
            continue


    # if using hwdb and no info other than idVendor+idProduct was found, we don't need to write
    # an udev rule
    if hwdb and not rule:
        return

    try:
        usbids = {}
        for usbid in cp.get('Device', 'devicematch').split(';'):
            if len(usbid.split(':')) != 3:
                continue
            (subsystem, vid, pid) = usbid.split(':')
            if subsystem != "usb":
                continue
            if vid in usbids:
                usbids[vid].append(pid)
            else:
                usbids[vid] = [ pid ]

        for vid, pids in usbids.items():
            rule += 'ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s"'% (vid, '|'.join(pids)) + ', '
    except configparser.NoOptionError:
        pass

    # if no information was found, don't write a rule at all
    if not rule:
        return

    try:
        m = cp.get('Device', 'product')
        rule = ('# %s\n' % m) + rule
    except configparser.NoOptionError:
        pass

    rule += 'ENV{ID_MEDIA_PLAYER}="%s"' % os.path.splitext(os.path.basename(mpi))[0]

    # do we have an icon?
    try:
        icon = cp.get('Device', 'icon')
        # breaks media player detection : https://bugs.launchpad.net/ubuntu/+source/gvfs/+bug/657609
        # rule += ', ENV{UDISKS_PRESENTATION_ICON_NAME}="%s"' % icon
    except configparser.NoOptionError:
        pass

    # empty line between blocks
    rule += '\n\n'

    # write bytes so that we are independent of the locale
    os.write(sys.stdout.fileno(), rule.encode('UTF-8'))
Print udev rule for given ConfigParser object.
Print udev rule for given ConfigParser object.
Print udev rule for given ConfigParser object .
def parse_mpi(mpi, hwdb):
    cp = configparser.RawConfigParser()
    assert cp.read(mpi, encoding='UTF-8')
    rule = ''
    for name in ['usbvendor', 'usbproduct', 'usbmodel', 'usbmanufacturer']:
        try:
            value = cp.get('Device', name)
            rule += mpi2udev[name] % value + ', '
        except configparser.NoOptionError:
            continue
    if hwdb and not rule:
        return
    try:
        usbids = {}
        for usbid in cp.get('Device', 'devicematch').split(';'):
            if len(usbid.split(':')) != 3:
                continue
            (subsystem, vid, pid) = usbid.split(':')
            if subsystem != "usb":
                continue
            if vid in usbids:
                usbids[vid].append(pid)
            else:
                usbids[vid] = [ pid ]
        for vid, pids in usbids.items():
            rule += 'ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s"'% (vid, '|'.join(pids)) + ', '
    except configparser.NoOptionError:
        pass
    if not rule:
        return
    try:
        m = cp.get('Device', 'product')
        rule = ('# %s\n' % m) + rule
    except configparser.NoOptionError:
        pass
    rule += 'ENV{ID_MEDIA_PLAYER}="%s"' % os.path.splitext(os.path.basename(mpi))[0]
    try:
        icon = cp.get('Device', 'icon')
    except configparser.NoOptionError:
        pass
    rule += '\n\n'
    os.write(sys.stdout.fileno(), rule.encode('UTF-8'))
def parse_mpi ( mpi , hwdb ) : cp = configparser . RawConfigParser ( ) assert cp . read ( mpi , encoding = 'UTF-8' ) rule = '' for name in [ 'usbvendor' , 'usbproduct' , 'usbmodel' , 'usbmanufacturer' ] : try : value = cp . get ( 'Device' , name ) rule += mpi2udev [ name ] % value + ', ' except configparser . NoOptionError : continue if hwdb and not rule : return try : usbids = { } for usbid in cp . get ( 'Device' , 'devicematch' ) . split ( ';' ) : if len ( usbid . split ( ':' ) ) != 3 : continue ( subsystem , vid , pid ) = usbid . split ( ':' ) if subsystem != "usb" : continue if vid in usbids : usbids [ vid ] . append ( pid ) else : usbids [ vid ] = [ pid ] for vid , pids in usbids . items ( ) : rule += 'ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s"' % ( vid , '|' . join ( pids ) ) + ', ' except configparser . NoOptionError : pass if not rule : return try : m = cp . get ( 'Device' , 'product' ) rule = ( '# %s\n' % m ) + rule except configparser . NoOptionError : pass rule += 'ENV{ID_MEDIA_PLAYER}="%s"' % os . path . splitext ( os . path . basename ( mpi ) ) [ 0 ] try : icon = cp . get ( 'Device' , 'icon' ) except configparser . NoOptionError : pass rule += '\n\n' os . write ( sys . stdout . fileno ( ) , rule . encode ( 'UTF-8' ) )
Print udev rule for given ConfigParser object.
Print udev rule for given ConfigParser object .
'''Print udev rule for given ConfigParser object.''' # if using hwdb and no info other than idVendor+idProduct was found, we don't need to write # an udev rule # if no information was found, don't write a rule at all # do we have an icon? # breaks media player detection : https://bugs.launchpad.net/ubuntu/+source/gvfs/+bug/657609 # rule += ', ENV{UDISKS_PRESENTATION_ICON_NAME}="%s"' % icon # empty line between blocks # write bytes so that we are independent of the locale
mpi
hwdb