Beispiel #1
0
def parseEnv(line1, line2):
    try:
        if not line1 or not line2:
            return False
        if not line1.startswith("DBUS_SESSION_BUS_ADDRESS=") or not line2.startswith("DBUS_SESSION_BUS_PID="):
            return False
        arr = line2.split("=")
        pid = arr[1].strip().strip('"')
        if not osx.checkPID(int(pid), "dbus-daemon"):
            return False
        line1 = line1.strip()
        loc = line1.find("=")
        address = line1[loc + 1 :]
        address = address.strip().strip('"')
        return [address, pid]
    except Exception, e:
        print "Invalid dbus.env file", e
        return False
Beispiel #2
0
def parseEnv(line1, line2):
	try:
		if not line1 or not line2:
			return False
		if (not line1.startswith("DBUS_SESSION_BUS_ADDRESS=") or
		not line2.startswith("DBUS_SESSION_BUS_PID=")):
			return False
		arr = line2.split("=")
		pid = arr[1].strip().strip('"')
		if not osx.checkPID(int(pid), "dbus-daemon"):
			return False
		line1 = line1.strip()
		loc = line1.find("=")
		address = line1[loc + 1:]
		address = address.strip().strip('"')
		return [address, pid]
	except Exception, e:
		print "Invalid dbus.env file", e
		return False
Beispiel #3
0
def load(start):
    # Look for existing external session and just use it if it exists
    if (
        ("DBUS_SESSION_BUS_ADDRESS" in os.environ)
        and ("DBUS_SESSION_BUS_PID" in os.environ)
        and osx.checkPID(int(os.environ["DBUS_SESSION_BUS_PID"]), "dbus-daemon")
    ):
        return True

        # Look for our own internal session
    env = readEnv()
    if env:
        # We have a valid existing dbus session, yay
        setEnv(env)
        return True

        # Initialize the machine's UUID if not done yet
    checkUUID()

    if start:
        # None found, start a new session
        print "Starting new dbus session"
        # cmd = os.path.join(osx.nsapp.getBundlePath(),
        # 		  "Contents/Resources/bin/dbus-launch --exit-with-session")
        cmd = _GTK_BASE + "/bin/dbus-launch --exit-with-session"
        ret = commands.getstatusoutput(cmd)
        arr = ret[1].split("\n")
        if len(arr) != 2:
            print "Failed to start internal dbus session:"
            print ret[1]
            return
        env = parseEnv(arr[0].strip(), arr[1].strip())
        if not env:
            print "Failed to start internal dbus session:"
            print ret[1]
            return
        setEnv(env)
        writeEnv(env)
        return True
    return False
Beispiel #4
0
def load(start):
	# Look for existing external session and just use it if it exists
	if (('DBUS_SESSION_BUS_ADDRESS' in os.environ) and
		('DBUS_SESSION_BUS_PID' in os.environ) and
		osx.checkPID(int(os.environ['DBUS_SESSION_BUS_PID']), 'dbus-daemon')):
		return True

	# Look for our own internal session
	env = readEnv()
	if env:
		# We have a valid existing dbus session, yay
		setEnv(env)
		return True

	# Initialize the machine's UUID if not done yet
	checkUUID()

	if start:
		# None found, start a new session
		print "Starting new dbus session"
		#cmd = os.path.join(osx.nsapp.getBundlePath(),
		#		  "Contents/Resources/bin/dbus-launch --exit-with-session")
		cmd = _GTK_BASE + "/bin/dbus-launch --exit-with-session"
		ret = commands.getstatusoutput(cmd)
		arr = ret[1].split("\n")
		if len(arr) != 2:
			print "Failed to start internal dbus session:"
			print ret[1]
			return
		env = parseEnv(arr[0].strip(), arr[1].strip())
		if not env:
			print "Failed to start internal dbus session:"
			print ret[1]
			return
		setEnv(env)
		writeEnv(env)
		return True
	return False