Patch by cscott to load the profile keys lazily.
Some style and pylint complaints fixes by me. Fix #5538
This commit is contained in:
parent
f00eada898
commit
2b0b83aa09
@ -108,7 +108,7 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
|
|
||||||
separator = gtk.SeparatorToolItem()
|
separator = gtk.SeparatorToolItem()
|
||||||
separator.props.draw = False
|
separator.props.draw = False
|
||||||
separator.set_expand(True);
|
separator.set_expand(True)
|
||||||
self.insert(separator, -1)
|
self.insert(separator, -1)
|
||||||
separator.show()
|
separator.show()
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import logging
|
|||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
import hippo
|
import hippo
|
||||||
import rsvg
|
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
from sugar.graphics.style import Color
|
from sugar.graphics.style import Color
|
||||||
@ -58,6 +57,7 @@ class _SVGLoader(object):
|
|||||||
logging.error(
|
logging.error(
|
||||||
'Icon %s, entity %s is invalid.', file_name, entity)
|
'Icon %s, entity %s is invalid.', file_name, entity)
|
||||||
|
|
||||||
|
import rsvg # XXX this is very slow! why?
|
||||||
return rsvg.Handle(data=icon)
|
return rsvg.Handle(data=icon)
|
||||||
|
|
||||||
class _IconInfo(object):
|
class _IconInfo(object):
|
||||||
|
@ -61,17 +61,16 @@ class Profile(object):
|
|||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.nick_name = None
|
self.nick_name = None
|
||||||
self.color = None
|
self.color = None
|
||||||
self.pubkey = None
|
|
||||||
self.privkey_hash = None
|
|
||||||
self.jabber_server = DEFAULT_JABBER_SERVER
|
self.jabber_server = DEFAULT_JABBER_SERVER
|
||||||
self.jabber_registered = False
|
self.jabber_registered = False
|
||||||
self.backup1 = None
|
self.backup1 = None
|
||||||
|
self.sound_volume = DEFAULT_VOLUME
|
||||||
|
|
||||||
|
self._pubkey = None
|
||||||
|
self._privkey_hash = None
|
||||||
self._config_path = path
|
self._config_path = path
|
||||||
|
|
||||||
self._load_config()
|
self._load_config()
|
||||||
self._load_pubkey()
|
|
||||||
self._hash_private_key()
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
return self.nick_name is not None and \
|
return self.nick_name is not None and \
|
||||||
@ -84,7 +83,7 @@ class Profile(object):
|
|||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
parsed = cp.read([self._config_path])
|
cp.read([self._config_path])
|
||||||
|
|
||||||
if self.nick_name:
|
if self.nick_name:
|
||||||
_set_key(cp, 'Buddy', 'NickName', self.nick_name.encode('utf8'))
|
_set_key(cp, 'Buddy', 'NickName', self.nick_name.encode('utf8'))
|
||||||
@ -105,7 +104,7 @@ class Profile(object):
|
|||||||
|
|
||||||
def _load_config(self):
|
def _load_config(self):
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
parsed = cp.read([self._config_path])
|
cp.read([self._config_path])
|
||||||
|
|
||||||
if cp.has_option('Buddy', 'NickName'):
|
if cp.has_option('Buddy', 'NickName'):
|
||||||
name = cp.get('Buddy', 'NickName')
|
name = cp.get('Buddy', 'NickName')
|
||||||
@ -123,37 +122,36 @@ class Profile(object):
|
|||||||
self.backup1 = cp.get('Server', 'Backup1')
|
self.backup1 = cp.get('Server', 'Backup1')
|
||||||
if cp.has_option('Sound', 'Volume'):
|
if cp.has_option('Sound', 'Volume'):
|
||||||
self.sound_volume = float(cp.get('Sound', 'Volume'))
|
self.sound_volume = float(cp.get('Sound', 'Volume'))
|
||||||
else:
|
|
||||||
self.sound_volume = DEFAULT_VOLUME
|
|
||||||
|
|
||||||
del cp
|
del cp
|
||||||
|
|
||||||
def _load_pubkey(self):
|
def _load_pubkey(self):
|
||||||
self.pubkey = None
|
|
||||||
|
|
||||||
key_path = os.path.join(env.get_profile_path(), 'owner.key.pub')
|
key_path = os.path.join(env.get_profile_path(), 'owner.key.pub')
|
||||||
try:
|
try:
|
||||||
f = open(key_path, "r")
|
f = open(key_path, "r")
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
self.valid = False
|
|
||||||
logging.error("Error reading public key: %s" % e)
|
logging.error("Error reading public key: %s" % e)
|
||||||
return
|
return None
|
||||||
|
|
||||||
magic = "ssh-dss "
|
magic = "ssh-dss "
|
||||||
for l in lines:
|
for l in lines:
|
||||||
l = l.strip()
|
l = l.strip()
|
||||||
if not l.startswith(magic):
|
if not l.startswith(magic):
|
||||||
continue
|
continue
|
||||||
self.pubkey = l[len(magic):]
|
return l[len(magic):]
|
||||||
break
|
else:
|
||||||
if not self.pubkey:
|
|
||||||
logging.error("Error parsing public key.")
|
logging.error("Error parsing public key.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _get_pubkey(self):
|
||||||
|
# load on-demand.
|
||||||
|
if not self._pubkey:
|
||||||
|
self._pubkey = self._load_pubkey()
|
||||||
|
return self._pubkey
|
||||||
|
|
||||||
def _hash_private_key(self):
|
def _hash_private_key(self):
|
||||||
self.privkey_hash = None
|
|
||||||
|
|
||||||
key_path = os.path.join(env.get_profile_path(), 'owner.key')
|
key_path = os.path.join(env.get_profile_path(), 'owner.key')
|
||||||
try:
|
try:
|
||||||
f = open(key_path, "r")
|
f = open(key_path, "r")
|
||||||
@ -161,7 +159,7 @@ class Profile(object):
|
|||||||
f.close()
|
f.close()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
logging.error("Error reading private key: %s" % e)
|
logging.error("Error reading private key: %s" % e)
|
||||||
return
|
return None
|
||||||
|
|
||||||
key = ""
|
key = ""
|
||||||
for l in lines:
|
for l in lines:
|
||||||
@ -173,10 +171,20 @@ class Profile(object):
|
|||||||
key += l
|
key += l
|
||||||
if not len(key):
|
if not len(key):
|
||||||
logging.error("Error parsing public key.")
|
logging.error("Error parsing public key.")
|
||||||
|
return None
|
||||||
|
|
||||||
# hash it
|
# hash it
|
||||||
key_hash = util._sha_data(key)
|
key_hash = util._sha_data(key)
|
||||||
self.privkey_hash = util.printable_hash(key_hash)
|
return util.printable_hash(key_hash)
|
||||||
|
|
||||||
|
def _get_privkey_hash(self):
|
||||||
|
# load on-demand.
|
||||||
|
if not self._privkey_hash:
|
||||||
|
self._privkey_hash = self._hash_private_key()
|
||||||
|
return self._privkey_hash
|
||||||
|
|
||||||
|
privkey_hash = property(_get_privkey_hash)
|
||||||
|
pubkey = property(_get_pubkey)
|
||||||
|
|
||||||
def get_profile():
|
def get_profile():
|
||||||
global _profile
|
global _profile
|
||||||
|
Loading…
Reference in New Issue
Block a user