Ejemplo n.º 1
0
def AddInfo(grph, node, entity_ids_arr):
    """This must add information about the dbus connection.
    Example: entity_id=['system', 'org.freedesktop.UDisks2']
    """

    try:
        bus_addr = entity_ids_arr[0]
        the_bus = lib_dbus.MakeBusFromAddress(bus_addr)

        connct_nam = entity_ids_arr[1]

        proxy = the_bus.get_object('org.freedesktop.DBus',
                                   '/org/freedesktop/DBus')

        # itf = proxy
        itf = dbus.Interface(proxy, 'org.freedesktop.DBus')

        pid = str(itf.GetConnectionUnixProcessID(connct_nam))
        uid = itf.GetConnectionUnixUser(connct_nam)
    except dbus.exceptions.DBusException as exc:
        # Could be: "org.freedesktop.DBus.Error.AccessDenied"
        logging.warning("AddInfo Caught=%s", str(exc))
        # Apparently happens with the first line.
        return
    usrnam = pwd.getpwuid(uid).pw_name

    node_proc = lib_uris.gUriGen.PidUri(pid)
    node_user = lib_uris.gUriGen.UserUri(usrnam)
    grph.add((node, pc.property_pid, node_proc))
    grph.add((node, pc.property_user, node_user))
Ejemplo n.º 2
0
def AddInfo(grph, node, entity_ids_arr):
    # Example: entity_id=['system', 'org.freedesktop.UDisks2']
    # sys.stderr.write("AddInfo entity_id=%s\n" % str(entity_ids_arr) )

    try:
        busAddr = entity_ids_arr[0]
        # sys.stderr.write("AddInfo busAddr=%s\n" % ( busAddr ) )
        theBus = lib_dbus.MakeBusFromAddress(busAddr)

        connctNam = entity_ids_arr[1]
        # sys.stderr.write("AddInfo connctNam=%s\n" % ( connctNam ) )

        proxy = theBus.get_object('org.freedesktop.DBus',
                                  '/org/freedesktop/DBus')
        # sys.stderr.write("AddInfo proxy=%s\n" % str( proxy ) )

        # itf = proxy
        itf = dbus.Interface(proxy, 'org.freedesktop.DBus')

        pid = str(itf.GetConnectionUnixProcessID(connctNam))
        uid = itf.GetConnectionUnixUser(connctNam)
        # sys.stderr.write("AddInfo pid=%s uid=%s\n" % ( pid, uid ) )
    except dbus.exceptions.DBusException:
        # Helas: "org.freedesktop.DBus.Error.AccessDenied"
        exc = sys.exc_info()[1]
        sys.stderr.write("AddInfo Caught=%s\n" % str(exc))
        # Apparently happens with the first line.
        return
    usrnam = pwd.getpwuid(uid).pw_name

    nodeProc = lib_common.gUriGen.PidUri(pid)
    nodeUser = lib_common.gUriGen.UserUri(usrnam)
    grph.add((node, pc.property_pid, nodeProc))
    grph.add((node, pc.property_user, nodeUser))
Ejemplo n.º 3
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    entity_type = "dbus/connection"

    Main.busAddr = cgiEnv.m_entity_id_dict["Bus"]
    Main.connectName = cgiEnv.m_entity_id_dict["Connect"]

    try:
        Main.theBus = lib_dbus.MakeBusFromAddress(Main.busAddr)
    except Exception as exc:
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" % (Main.busAddr, str(exc)))

    connectNode = lib_util.EntityUri(entity_type, Main.busAddr, Main.connectName)

    grph = cgiEnv.GetGraph()

    Main.localPropDbusPath = lib_util.NodeLiteral("dbus-path")

    try:
        _recursive_obj_walk(grph, "/", connectNode)
    except dbus.exceptions.DBusException as exc:
        lib_common.ErrorMessageHtml("Caught DBusException busAddr=%s %s" % (Main.busAddr, str(exc)))
    except dbus.proxies as exc:
        lib_common.ErrorMessageHtml("Caught proxies busAddr=%s %s" % (Main. busAddr, str(exc)))

    cgiEnv.OutCgiRdf()
Ejemplo n.º 4
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    busAddr = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    try:
        theBus = lib_dbus.MakeBusFromAddress(busAddr)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" %
                                    (busAddr, str(exc)))

    nodeBus = lib_util.EntityUri("dbus/bus", busAddr)

    # This property should maybe stored at the central file.
    localPropDbusConnect = lib_common.MakeProp("dbus connect")
    localPropDbusWellKnown = lib_common.MakeProp("well known")

    Main.connectNameToNode = dict()

    def GetConnectNode(busAddr, connectName):
        try:
            return Main.connectNameToNode[connectName]
        except KeyError:
            connectNode = lib_util.EntityUri("dbus/connection", busAddr,
                                             connectName)
            Main.connectNameToNode[connectName] = connectNode
            return connectNode

    for connectName in theBus.list_names():
        connectNode = GetConnectNode(busAddr, connectName)

        try:
            ownrNam = theBus.get_name_owner(connectName)
            sys.stderr.write("connectName=%s ownr=%s\n" %
                             (connectName, ownrNam))
            if connectName != ownrNam:
                ownrNode = GetConnectNode(busAddr, ownrNam)
                sys.stderr.write("TO CONNECT %s\n" % (connectName))

                # TODO: BUG, Display does not work if "Well Known" property.
                # grph.add( (ownrNode, localPropDbusWellKnown, connectNode ) )
                grph.add((ownrNode, localPropDbusConnect, connectNode))
        except ValueError:
            sys.stderr.write("22 CONNECT %s\n" % (connectName))
            grph.add((nodeBus, localPropDbusConnect, connectNode))

    # TODO: The ordering is: 1.1,1.11,1.2, so we should have a special sort function.

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [localPropDbusConnect, localPropDbusWellKnown])
Ejemplo n.º 5
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    bus_addr = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    try:
        the_bus = lib_dbus.MakeBusFromAddress(bus_addr)
    except Exception as exc:
        lib_common.ErrorMessageHtml("bus_addr=%s Caught:%s" %
                                    (bus_addr, str(exc)))

    node_bus = lib_util.EntityUri("dbus/bus", bus_addr)

    # This property should maybe stored at the central file.
    local_prop_dbus_connect = lib_common.MakeProp("dbus connect")
    local_prop_dbus_well_known = lib_common.MakeProp("well known")

    Main.connectNameToNode = dict()

    def get_connect_node(bus_addr, connect_name):
        try:
            return Main.connectNameToNode[connect_name]
        except KeyError:
            connectNode = lib_util.EntityUri("dbus/connection", bus_addr,
                                             connect_name)
            Main.connectNameToNode[connect_name] = connectNode
            return connectNode

    for connect_name in the_bus.list_names():
        connect_node = get_connect_node(bus_addr, connect_name)

        try:
            ownr_nam = the_bus.get_name_owner(connect_name)
            logging.debug("connect_name=%s ownr=%s", connect_name, ownr_nam)
            if connect_name != ownr_nam:
                ownr_node = get_connect_node(bus_addr, ownr_nam)
                logging.debug("TO CONNECT %s", connect_name)

                # TODO: BUG, Display does not work if "Well Known" property.
                # grph.add((ownr_node, local_prop_dbus_well_known, connect_node))
                grph.add((ownr_node, local_prop_dbus_connect, connect_node))
        except ValueError:
            logging.debug("22 CONNECT %s", connect_name)
            grph.add((node_bus, local_prop_dbus_connect, connect_node))

    # TODO: The ordering is: 1.1,1.11,1.2, so we should use natsort.

    cgiEnv.OutCgiRdf("LAYOUT_RECT",
                     [local_prop_dbus_connect, local_prop_dbus_well_known])
Ejemplo n.º 6
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    entity_type = "dbus/connection"
    # entity_id = cgiEnv.m_entity_id
    # entity_ids_arr = lib_util.EntityIdToArray( entity_type, entity_id )
    # entity_ids_dict = lib_util.SplitMoniker(entity_id)

    # busAddr = entity_ids_arr[0]
    # connectName = entity_ids_arr[1]
    Main.busAddr = cgiEnv.m_entity_id_dict["Bus"]
    Main.connectName = cgiEnv.m_entity_id_dict["Connect"]

    try:
        Main.theBus = lib_dbus.MakeBusFromAddress(Main.busAddr)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("busAddr=%s Caught:%s" %
                                    (Main.busAddr, str(exc)))

    connectNode = lib_util.EntityUri(entity_type, Main.busAddr,
                                     Main.connectName)

    grph = cgiEnv.GetGraph()

    Main.localPropDbusPath = lib_common.NodeLiteral("dbus-path")

    try:
        RecursiveObjWalk(grph, "/", connectNode)
    except dbus.exceptions.DBusException as exc:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught DBusException busAddr=%s %s" %
                                    (Main.busAddr, str(exc)))
    except dbus.proxies as exc:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught proxies busAddr=%s %s" %
                                    (Main.busAddr, str(exc)))

    cgiEnv.OutCgiRdf()