Example #1
0
def getDeviceInfo(busId):
    if not os.path.exists(consts.config_file):
        return

    doc = piksemel.parse(consts.config_file)

    cardTag = None
    for tag in doc.tags("Card"):
        if tag.getAttribute("busId") == busId:
            cardTag = tag
            break

    if not cardTag:
        return

    device = VideoDevice(busId=busId)

    device.saved_vendor_id  = cardTag.getTagData("VendorId")
    device.saved_product_id = cardTag.getTagData("ProductId")

    driver = cardTag.getTagData("Driver")
    activeConfigTag = cardTag.getTag("ActiveConfig")

    if driver:
        device.driver = driver
    elif activeConfigTag:
        driver = activeConfigTag.getTagData("Driver")
        if driver:
            device.driver = driver

    depth = cardTag.getTagData("Depth")
    if depth:
        device.depth = int(depth)

    def addMonitor(output, tag):
        mon = Monitor()
        mon.vendor = tag.getTagData("Vendor") or ""
        mon.model  = tag.getTagData("Model") or "Unknown Monitor"
        mon.hsync  = tag.getTagData("HorizSync") or mon.hsync
        mon.vref   = tag.getTagData("VertRefresh") or mon.vref
        device.monitors[output] = mon

    # Get output info
    outputsTag = cardTag.getTag("Outputs")
    if outputsTag:
        for outputTag in outputsTag.tags("Output"):
            name = outputTag.getAttribute("name")
            output = Output(name)
            device.outputs[name] = output

            enabled = outputTag.getTagData("Enabled")
            if enabled:
                output.setEnabled(enabled == "true")
            ignored = outputTag.getTagData("Ignored")
            if ignored:
                output.setIgnored(ignored == "true")

            mode = outputTag.getTagData("Mode") or ""
            rate = outputTag.getTagData("RefreshRate") or ""
            output.setMode(mode, rate)

            rotation = outputTag.getTagData("Rotation")
            if rotation:
                output.setOrientation(rotation)

            rightOf = outputTag.getTagData("RightOf")
            below = outputTag.getTagData("Below")
            if rightOf:
                output.setPosition("RightOf", rightOf)
            elif below:
                output.setPosition("Below", below)

            monitorTag = outputTag.getTag("Monitor")
            if monitorTag:
                addMonitor(name, monitorTag)

    return device
Example #2
0
def getDeviceInfo(busId):
    configFile = os.path.join(zorgConfigDir, zorgConfig)
    if not os.path.exists(configFile):
        return

    doc = piksemel.parse(configFile)

    cardTag = None
    for tag in doc.tags("Card"):
        if tag.getAttribute("busId") == busId:
            cardTag = tag
            break

    if not cardTag:
        return

    device = VideoDevice(busId=busId)

    device.saved_vendor_id = cardTag.getTagData("VendorId")
    device.saved_product_id = cardTag.getTagData("ProductId")

    probeResultTag = cardTag.getTag("ProbeResult")
    probeResult = {}
    for tag in probeResultTag.tags("Value"):
        key = tag.getAttribute("key")
        child = tag.firstChild()
        if child:
            value = child.data()
        else:
            value = ""
        probeResult[key] = value

    activeConfigTag = cardTag.getTag("ActiveConfig")

    driverTag = activeConfigTag.getTag("Driver")
    device.driver = driverTag.firstChild().data()
    device.package = driverTag.getAttribute("package")

    device.depth = activeConfigTag.getTagData("Depth")

    activeOutputs = []
    modes = {}

    def addMonitor(output, tag):
        mon = Monitor()
        mon.vendor = tag.getTagData("Vendor") or ""
        mon.model = tag.getTagData("Model") or "Unknown Monitor"
        mon.hsync = tag.getTagData("HorizSync") or mon.hsync
        mon.vref = tag.getTagData("VertRefresh") or mon.vref
        device.monitors[output] = mon

    outputTag = activeConfigTag.getTag("Output")
    name = outputTag.firstChild().data()
    activeOutputs.append(name)
    mode = outputTag.getAttribute("mode")
    if mode:
        modes[name] = mode

    monitorTag = activeConfigTag.getTag("Monitor")
    if monitorTag:
        addMonitor(name, monitorTag)

    outputTag = activeConfigTag.getTag("SecondOutput")
    if outputTag:
        name = outputTag.firstChild().data()
        activeOutputs.append(name)
        mode = outputTag.getAttribute("mode")
        if mode:
            modes[name] = mode

        monitorTag = activeConfigTag.getTag("SecondMonitor")
        if monitorTag:
            addMonitor(name, monitorTag)

    device.desktop_setup = activeConfigTag.getTagData("DesktopSetup")

    device.probe_result = probeResult
    device.active_outputs = activeOutputs
    device.modes = modes

    return device