Next / Previous / Contents / TCC Help System / NM Tech homepage

26.2. ClientConfig.__deviceCheck(): Check for devices of a given type

The deviceMap passed to this function is a dictionary obtained from GetHardware in which the keys are device types such as 'VIDEO' and the associated value is a list of two-element lists [detail, other]. We want the detail if present; the other is a dictionary that contains stuff we don't need to know.

If the deviceMap does have an entry for the desired device type, add to self.deviceList a two-element list “[devType, [detail]” for each instance of that device type. For example, if a client has two video cards, there will be two elements in self.deviceList of the form ["VIDEO", "model-info"].

hwscan3.py
# - - -   C l i e n t C o n f i g . _ _ d e v i c e C h e c k

    def __deviceCheck ( self, deviceMap, deviceType ):
        '''Extract from deviceMap any device details for type deviceType

          [ (deviceMap has the format of a value from
            hardMap[self.DEVICES]) and
            (deviceType is a string) ->
              if deviceMap has a key equal to deviceType ->
                self.deviceList  +:=  a list [deviceType,
                detail] for each device of that type in
                deviceMap
              else -> I ]
        '''

First we check to see if this client has any devices of type deviceType.n

hwscan3.py
        #-- 1 --
        # [ if deviceMap has a key that matches deviceType ->
        #     multiList  :=  deviceMap[deviceType]
        #   else -> return ]
        try:
            multiList  =  deviceMap[deviceType]
        except KeyError:
            return

At this point, multiList is a list with one member for each device of the right type. Each member is itself a two-element list [detail, other], where detail is a string describing the device's details, and other is a dictionary whose contents don't interest us.

Our job is to add to self.deviceList a two-element list of the form [devType, detail] for each instance of this device type in multiList.

hwscan3.py
        #-- 2 --
        # [ self.deviceList  +:=  two-element lists [devType,
        #       detail] for each element of multiList ]
        for detail, other in multiList:
            self.deviceList.append ( [deviceType, detail] )