本文整理汇总了Python中sugar3.profile.get_profile函数的典型用法代码示例。如果您正苦于以下问题:Python get_profile函数的具体用法?Python get_profile怎么用?Python get_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_profile函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_profile
def create_profile(name, color=None):
if not color:
color = XoColor()
client = GConf.Client.get_default()
client.set_string('/desktop/sugar/user/nick', name)
client.set_string('/desktop/sugar/user/color', color.to_string())
client.suggest_sync()
if profile.get_pubkey() and profile.get_profile().privkey_hash:
logging.info('Valid key pair found, skipping generation.')
return
# Generate keypair
import commands
keypath = os.path.join(env.get_profile_path(), 'owner.key')
if os.path.exists(keypath):
os.rename(keypath, keypath + '.broken')
logging.warning('Existing private key %s moved to %s.broken',
keypath, keypath)
if os.path.exists(keypath + '.pub'):
os.rename(keypath + '.pub', keypath + '.pub.broken')
logging.warning('Existing public key %s.pub moved to %s.pub.broken',
keypath, keypath)
logging.debug("Generating user keypair")
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, )
(s, o) = commands.getstatusoutput(cmd)
if s != 0:
logging.error('Could not generate key pair: %d %s', s, o)
logging.debug("User keypair generated")
示例2: _ensure_server_account
def _ensure_server_account(self, account_paths):
for account_path in account_paths:
if "gabble" in account_path:
logging.debug("Already have a Gabble account")
account = _Account(account_path)
account.enable()
return account
logging.debug("Still dont have a Gabble account, creating one")
nick = self._settings_user.get_string("nick")
server = self._settings_collaboration.get_string("jabber-server")
key_hash = get_profile().privkey_hash
params = {
"account": self._get_jabber_account_id(),
"password": key_hash,
"server": server,
"resource": "sugar",
"require-encryption": True,
"ignore-ssl-errors": True,
"register": True,
"old-ssl": True,
"port": dbus.UInt32(5223),
}
properties = {ACCOUNT + ".Enabled": True, ACCOUNT + ".Nickname": nick, ACCOUNT + ".ConnectAutomatically": True}
bus = dbus.Bus()
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH)
account_manager = dbus.Interface(obj, ACCOUNT_MANAGER)
account_path = account_manager.CreateAccount("gabble", "jabber", "jabber", params, properties)
return _Account(account_path)
示例3: __init__
def __init__(self):
BaseBuddyModel.__init__(self)
client = GConf.Client.get_default()
self.props.nick = client.get_string('/desktop/sugar/user/nick')
color = client.get_string('/desktop/sugar/user/color')
self.props.color = XoColor(color)
self.props.key = get_profile().pubkey
self.connect('notify::nick', self.__property_changed_cb)
self.connect('notify::color', self.__property_changed_cb)
bus = dbus.SessionBus()
bus.add_signal_receiver(
self.__name_owner_changed_cb,
signal_name='NameOwnerChanged',
dbus_interface='org.freedesktop.DBus')
bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH)
for service in bus_object.ListNames(
dbus_interface=dbus.BUS_DAEMON_IFACE):
if service.startswith(CONNECTION + '.'):
path = '/%s' % service.replace('.', '/')
Connection(service, path, bus,
ready_handler=self.__connection_ready_cb)
示例4: check_profile
def check_profile():
profile = get_profile()
path = os.path.join(env.get_profile_path(), 'config')
if os.path.exists(path):
profile.convert_profile()
return profile.is_valid()
示例5: create_profile
def create_profile(user_profile):
settings = Gio.Settings('org.sugarlabs.user')
settings.set_string('nick', user_profile.nickname)
colors = user_profile.colors
if colors is None:
colors = XoColor()
settings.set_string('color', colors.to_string())
if user_profile.gender is not None:
settings.set_string('gender', user_profile.gender)
else:
settings.set_string('gender', '')
settings.set_int('birth-timestamp',
calculate_birth_timestamp(user_profile.age))
# settings.sync()
# DEPRECATED
from gi.repository import GConf
client = GConf.Client.get_default()
client.set_string('/desktop/sugar/user/nick', user_profile.nickname)
client.set_string('/desktop/sugar/user/color', colors.to_string())
if user_profile.gender is not None:
client.set_string('/desktop/sugar/user/gender', user_profile.gender)
client.set_int('/desktop/sugar/user/birth_timestamp',
calculate_birth_timestamp(user_profile.age))
client.suggest_sync()
if profile.get_pubkey() and profile.get_profile().privkey_hash:
logging.info('Valid key pair found, skipping generation.')
return
# Generate keypair
keypath = os.path.join(env.get_profile_path(), 'owner.key')
if os.path.exists(keypath):
os.rename(keypath, keypath + '.broken')
logging.warning('Existing private key %s moved to %s.broken',
keypath, keypath)
if os.path.exists(keypath + '.pub'):
os.rename(keypath + '.pub', keypath + '.pub.broken')
logging.warning('Existing public key %s.pub moved to %s.pub.broken',
keypath, keypath)
logging.debug("Generating user keypair")
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, )
(s, o) = subprocess.getstatusoutput(cmd)
if s != 0:
logging.error('Could not generate key pair: %d %s', s, o)
logging.debug("User keypair generated")
示例6: _get_published_name
def _get_published_name(self):
"""Construct the published name based on the public key
Limit the name to be only 8 characters maximum. The avahi
service name has a 64 character limit. It consists of
the room name, the published name and the host name.
"""
public_key_hash = sha1(get_profile().pubkey).hexdigest()
return public_key_hash[:8]
示例7: register_laptop
def register_laptop(url=_REGISTER_URL):
profile = get_profile()
if _have_ofw_tree():
sn = _read_mfg_data(os.path.join(_OFW_TREE, _MFG_SN))
uuid_ = _read_mfg_data(os.path.join(_OFW_TREE, _MFG_UUID))
elif _have_proc_device_tree():
sn = _read_mfg_data(os.path.join(_PROC_TREE, _MFG_SN))
uuid_ = _read_mfg_data(os.path.join(_PROC_TREE, _MFG_UUID))
else:
sn = _generate_serial_number()
uuid_ = str(uuid.uuid1())
sn = sn or 'SHF00000000'
uuid_ = uuid_ or '00000000-0000-0000-0000-000000000000'
nick = get_nick_name()
settings = Gio.Settings('org.sugarlabs.collaboration')
jabber_server = settings.get_string('jabber-server')
_store_identifiers(sn, uuid_, jabber_server)
if jabber_server:
url = 'http://' + jabber_server + ':8080/'
if sys.hexversion < 0x2070000:
server = xmlrpclib.ServerProxy(url, _TimeoutTransport())
else:
socket.setdefaulttimeout(_REGISTER_TIMEOUT)
server = xmlrpclib.ServerProxy(url)
try:
data = server.register(sn, nick, uuid_, profile.pubkey)
except (xmlrpclib.Error, TypeError, socket.error):
logging.exception('Registration: cannot connect to server')
raise RegisterError(_('Cannot connect to the server.'))
finally:
socket.setdefaulttimeout(None)
if data['success'] != 'OK':
logging.error('Registration: server could not complete request: %s',
data['error'])
raise RegisterError(_('The server could not complete the request.'))
settings.set_string('jabber-server', data['jabberserver'])
settings = Gio.Settings('org.sugarlabs')
settings.set_string('backup-url', data['backupurl'])
# DEPRECATED
from gi.repository import GConf
client = GConf.Client.get_default()
client.set_string(
'/desktop/sugar/collaboration/jabber_server', data['jabberserver'])
client.set_string('/desktop/sugar/backup_url', data['backupurl'])
return True
示例8: create_profile
def create_profile(user_profile):
settings = Gio.Settings('org.sugarlabs.user')
if user_profile.nickname in [None, '']:
nick = settings.get_string('nick')
if nick is not None:
logging.debug('recovering old nickname %s' % (nick))
user_profile.nickname = nick
settings.set_string('nick', user_profile.nickname)
colors = user_profile.colors
if colors is None:
colors = XoColor()
settings.set_string('color', colors.to_string())
genderpicker.save_gender(user_profile.gender)
agepicker.save_age(user_profile.age)
# DEPRECATED
from gi.repository import GConf
client = GConf.Client.get_default()
client.set_string('/desktop/sugar/user/nick', user_profile.nickname)
client.set_string('/desktop/sugar/user/color', colors.to_string())
client.suggest_sync()
if profile.get_pubkey() and profile.get_profile().privkey_hash:
logging.info('Valid key pair found, skipping generation.')
return
# Generate keypair
keypath = os.path.join(env.get_profile_path(), 'owner.key')
if os.path.exists(keypath):
os.rename(keypath, keypath + '.broken')
logging.warning('Existing private key %s moved to %s.broken',
keypath, keypath)
if os.path.exists(keypath + '.pub'):
os.rename(keypath + '.pub', keypath + '.pub.broken')
logging.warning('Existing public key %s.pub moved to %s.pub.broken',
keypath, keypath)
logging.debug("Generating user keypair")
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, )
(s, o) = commands.getstatusoutput(cmd)
if s != 0:
logging.error('Could not generate key pair: %d %s', s, o)
logging.debug("User keypair generated")
示例9: check_profile
def check_profile():
profile = get_profile()
path = os.path.join(os.path.expanduser('~/.sugar'), 'debug')
if not os.path.exists(path):
profile.create_debug_file()
path = os.path.join(env.get_profile_path(), 'config')
if os.path.exists(path):
profile.convert_profile()
return profile.is_valid()
示例10: _ensure_server_account
def _ensure_server_account(self, account_paths):
for account_path in account_paths:
if 'gabble' in account_path:
logging.debug('Already have a Gabble account')
account = _Account(account_path)
account.enable()
return account
logging.debug('Still dont have a Gabble account, creating one')
client = GConf.Client.get_default()
nick = client.get_string('/desktop/sugar/user/nick')
server = client.get_string('/desktop/sugar/collaboration'
'/jabber_server')
key_hash = get_profile().privkey_hash
params = {
'account': self._get_jabber_account_id(),
'password': key_hash,
'server': server,
'resource': 'sugar',
'require-encryption': True,
'ignore-ssl-errors': True,
'register': True,
'old-ssl': True,
'port': dbus.UInt32(5223),
}
properties = {
ACCOUNT + '.Enabled': True,
ACCOUNT + '.Nickname': nick,
ACCOUNT + '.ConnectAutomatically': True,
}
bus = dbus.Bus()
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH)
account_manager = dbus.Interface(obj, ACCOUNT_MANAGER)
account_path = account_manager.CreateAccount('gabble', 'jabber',
'jabber', params,
properties)
return _Account(account_path)
示例11: _seed_xs_cookie
def _seed_xs_cookie(cookie_jar):
"""Create a HTTP Cookie to authenticate with the Schoolserver.
Do nothing if the laptop is not registered with Schoolserver, or
if the cookie already exists.
"""
client = GConf.Client.get_default()
backup_url = client.get_string('/desktop/sugar/backup_url')
if backup_url == '':
_logger.debug('seed_xs_cookie: Not registered with Schoolserver')
return
jabber_server = client.get_string(
'/desktop/sugar/collaboration/jabber_server')
soup_uri = Soup.URI()
soup_uri.set_scheme('xmpp')
soup_uri.set_host(jabber_server)
soup_uri.set_path('/')
xs_cookie = cookie_jar.get_cookies(soup_uri, for_http=False)
if xs_cookie is not None:
_logger.debug('seed_xs_cookie: Cookie exists already')
return
pubkey = profile.get_profile().pubkey
cookie_data = {'color': profile.get_color().to_string(),
'pkey_hash': sha1(pubkey).hexdigest()}
expire = int(time.time()) + 10 * 365 * 24 * 60 * 60
xs_cookie = Soup.Cookie()
xs_cookie.set_name('xoid')
xs_cookie.set_value(json.dumps(cookie_data))
xs_cookie.set_domain(jabber_server)
xs_cookie.set_path('/')
xs_cookie.set_max_age(expire)
cookie_jar.add_cookie(xs_cookie)
_logger.debug('seed_xs_cookie: Updated cookie successfully')
示例12: _get_jabber_account_id
def _get_jabber_account_id(self):
public_key_hash = sha1(get_profile().pubkey).hexdigest()
server = self._settings_collaboration.get_string('jabber-server')
return '%[email protected]%s' % (public_key_hash, server)
示例13: _get_jabber_account_id
def _get_jabber_account_id(self):
public_key_hash = sha1(get_profile().pubkey).hexdigest()
client = GConf.Client.get_default()
server = client.get_string('/desktop/sugar/collaboration'
'/jabber_server')
return '%[email protected]%s' % (public_key_hash, server)