Save also the sugar session display and use it in sugar-activity.
This commit is contained in:
parent
a5d303f9ff
commit
6c5d28ecf5
@ -18,6 +18,16 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
|
||||||
|
from sugar import env
|
||||||
|
|
||||||
|
# Setup the environment so that we run inside the Sugar shell
|
||||||
|
cp = ConfigParser()
|
||||||
|
cp.read([env.get_profile_path("session.info")])
|
||||||
|
os.environ['DBUS_SESSION_BUS_ADDRESS'] = cp.get('Session', 'dbus_address')
|
||||||
|
os.environ['DISPLAY'] = cp.get('Session', 'display')
|
||||||
|
del cp
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import dbus
|
import dbus
|
||||||
@ -26,15 +36,6 @@ import dbus.glib
|
|||||||
from sugar.activity import bundleregistry
|
from sugar.activity import bundleregistry
|
||||||
from sugar.activity import activityfactory
|
from sugar.activity import activityfactory
|
||||||
from sugar.activity import activityfactoryservice
|
from sugar.activity import activityfactoryservice
|
||||||
from sugar import env
|
|
||||||
|
|
||||||
def _setup_bus_address():
|
|
||||||
'''Use the bus address of the running Sugar'''
|
|
||||||
bus_file = os.path.join(env.get_profile_path(), "session_bus_address")
|
|
||||||
f = open(bus_file, "r")
|
|
||||||
bus_name = f.read()
|
|
||||||
f.close()
|
|
||||||
os.environ['DBUS_SESSION_BUS_ADDRESS'] = bus_name
|
|
||||||
|
|
||||||
def _success_cb(handler, exit):
|
def _success_cb(handler, exit):
|
||||||
if exit:
|
if exit:
|
||||||
@ -47,8 +48,6 @@ def _error_cb(handler, err):
|
|||||||
def print_help(self):
|
def print_help(self):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
_setup_bus_address()
|
|
||||||
|
|
||||||
bundle = None
|
bundle = None
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
sys.path.insert(0, sys.argv[1])
|
sys.path.insert(0, sys.argv[1])
|
||||||
@ -55,9 +56,15 @@ if not key or not len(key):
|
|||||||
#
|
#
|
||||||
# WARNING!!! this is going away at some near future point, do not rely on it
|
# WARNING!!! this is going away at some near future point, do not rely on it
|
||||||
#
|
#
|
||||||
dsba_file = os.path.join(env.get_profile_path(), "session_bus_address")
|
dsba_file = os.path.join(env.get_profile_path(), "session.info")
|
||||||
f = open(dsba_file, "w")
|
f = open(dsba_file, "w")
|
||||||
f.write(os.environ["DBUS_SESSION_BUS_ADDRESS"])
|
|
||||||
|
cp = ConfigParser()
|
||||||
|
cp.add_section('Session')
|
||||||
|
cp.set('Session', 'dbus_address', os.environ['DBUS_SESSION_BUS_ADDRESS'])
|
||||||
|
cp.set('Session', 'display', gtk.gdk.display_get_default().get_name())
|
||||||
|
cp.write(f)
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
model = ShellModel()
|
model = ShellModel()
|
||||||
|
13
sugar/env.py
13
sugar/env.py
@ -34,20 +34,23 @@ def is_emulator():
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_profile_path():
|
def get_profile_path(path=None):
|
||||||
if os.environ.has_key('SUGAR_PROFILE'):
|
if os.environ.has_key('SUGAR_PROFILE'):
|
||||||
profile_id = os.environ['SUGAR_PROFILE']
|
profile_id = os.environ['SUGAR_PROFILE']
|
||||||
else:
|
else:
|
||||||
profile_id = 'default'
|
profile_id = 'default'
|
||||||
|
|
||||||
path = os.path.join(os.path.expanduser('~/.sugar'), profile_id)
|
base = os.path.join(os.path.expanduser('~/.sugar'), profile_id)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(base):
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(base)
|
||||||
except OSError, exc:
|
except OSError, exc:
|
||||||
print "Could not create user directory."
|
print "Could not create user directory."
|
||||||
|
|
||||||
return path
|
if path != None:
|
||||||
|
return os.path.join(base, path)
|
||||||
|
else:
|
||||||
|
return base
|
||||||
|
|
||||||
def get_user_activities_path():
|
def get_user_activities_path():
|
||||||
path = os.path.expanduser('~/Activities')
|
path = os.path.expanduser('~/Activities')
|
||||||
|
Loading…
Reference in New Issue
Block a user