(adapter, ifname, pid, ule, existing_dvbnet_interfaces)
Start DVB network interface

    Args:
        adapter                    : DVB adapter index
        ifname                     : DVB network interface name
        pid                        : PID to listen to
        ule                        : Whether to use ULE framing
        existing_dvbnet_interfaces : List of dvbnet interfaces already
                                     configured for the adapter
Start DVB network interface
Start DVB network interface
def _dvbnet_single(adapter, ifname, pid, ule, existing_dvbnet_interfaces):
    """Start DVB network interface

    Args:
        adapter                    : DVB adapter index
        ifname                     : DVB network interface name
        pid                        : PID to listen to
        ule                        : Whether to use ULE framing
        existing_dvbnet_interfaces : List of dvbnet interfaces already
                                     configured for the adapter

    """

    assert (pid >= 32 and pid <= 8190), "PID not insider range 32 to 8190"

    if (ule):
        encapsulation = 'ULE'
    else:
        encapsulation = 'MPE'

    # Check if the interface already exists
    res = subprocess.call(["ip", "addr", "show", "dev", ifname],
                          stdout=subprocess.DEVNULL,
                          stderr=subprocess.DEVNULL)
    os_interface_exists = (res == 0)
    matching_dvbnet_if = None

    # When the network interface exists in the OS, we also need to check if the
    # matching dvbnet device is configured according to what we want now
    if (os_interface_exists):
        print("Network interface %s already exists" % (ifname))

        for interface in existing_dvbnet_interfaces:
            if (interface['name'] == ifname):
                matching_dvbnet_if = interface
                break

    # Our indication that interface exists comes from "ip addr show
    # dev". However, it is possible that dvbnet does not have any interface
    # associated to an adapter, so check if we found anything:
    cfg_interface = False
    if (len(existing_dvbnet_interfaces) > 0
            and matching_dvbnet_if is not None):
        # Compare to desired configurations
        if (matching_dvbnet_if['pid'] != pid
                or matching_dvbnet_if['encapsulation'] != encapsulation):
            cfg_interface = True

        if (matching_dvbnet_if['pid'] != pid):
            print("Current PID is %d. Set it to %d" %
                  (matching_dvbnet_if['pid'], pid))

        if (matching_dvbnet_if['encapsulation'] != encapsulation):
            print("Current encapsulation is %s. Set it to %s" %
                  (matching_dvbnet_if['encapsulation'], encapsulation))
    else:
        cfg_interface = True

    # Create interface in case it doesn't exist or needs to be re-created
    if (cfg_interface):
        # If interface exists, but must be re-created, remove the existing one
        # first
        if (os_interface_exists):
            _rm_dvbnet_interface(adapter, ifname, verbose=False)

        ule_arg = "-U" if ule else ""

        if (runner.dry):
            print("Create interface {}:".format(ifname))

        runner.run(["dvbnet", "-a", adapter, "-p",
                    str(pid), ule_arg],
                   root=True)
    else:
        print("Network interface %s already configured correctly" % (ifname))
def _dvbnet_single ( adapter , ifname , pid , ule , existing_dvbnet_interfaces ) : assert ( pid >= 32 and pid <= 8190 ) , "PID not insider range 32 to 8190" if ( ule ) : encapsulation = 'ULE' else : encapsulation = 'MPE' # Check if the interface already exists res = subprocess . call ( [ "ip" , "addr" , "show" , "dev" , ifname ] , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL ) os_interface_exists = ( res == 0 ) matching_dvbnet_if = None # When the network interface exists in the OS, we also need to check if the # matching dvbnet device is configured according to what we want now if ( os_interface_exists ) : print ( "Network interface %s already exists" % ( ifname ) ) for interface in existing_dvbnet_interfaces : if ( interface [ 'name' ] == ifname ) : matching_dvbnet_if = interface break # Our indication that interface exists comes from "ip addr show # dev". However, it is possible that dvbnet does not have any interface # associated to an adapter, so check if we found anything: cfg_interface = False if ( len ( existing_dvbnet_interfaces ) > 0 and matching_dvbnet_if is not None ) : # Compare to desired configurations if ( matching_dvbnet_if [ 'pid' ] != pid or matching_dvbnet_if [ 'encapsulation' ] != encapsulation ) : cfg_interface = True if ( matching_dvbnet_if [ 'pid' ] != pid ) : print ( "Current PID is %d. Set it to %d" % ( matching_dvbnet_if [ 'pid' ] , pid ) ) if ( matching_dvbnet_if [ 'encapsulation' ] != encapsulation ) : print ( "Current encapsulation is %s. Set it to %s" % ( matching_dvbnet_if [ 'encapsulation' ] , encapsulation ) ) else : cfg_interface = True # Create interface in case it doesn't exist or needs to be re-created if ( cfg_interface ) : # If interface exists, but must be re-created, remove the existing one # first if ( os_interface_exists ) : _rm_dvbnet_interface ( adapter , ifname , verbose = False ) ule_arg = "-U" if ule else "" if ( runner . dry ) : print ( "Create interface {}:" . format ( ifname ) ) runner . run ( [ "dvbnet" , "-a" , adapter , "-p" , str ( pid ) , ule_arg ] , root = True ) else : print ( "Network interface %s already configured correctly" % ( ifname ) )