Start intro if config is absent or corrupted.

Cleanups.
master
Marco Pesenti Gritti 17 years ago
parent 72857326d2
commit e2beb5b566

@ -1,3 +1,4 @@
* #2119 If config is missing start intro. (marco)
* #2083 Fix centering of items in the spread box. (marco) * #2083 Fix centering of items in the spread box. (marco)
* #2486 In the intro screen name page enter goes to next page. (marco) * #2486 In the intro screen name page enter goes to next page. (marco)
* #2570 Accept correctly image drops from Record. * #2570 Accept correctly image drops from Record.

@ -232,10 +232,13 @@ class IntroWindow(gtk.Window):
# Generate keypair # Generate keypair
import commands import commands
keypath = os.path.join(env.get_profile_path(), "owner.key") keypath = os.path.join(env.get_profile_path(), "owner.key")
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % keypath if not os.path.isfile(keypath):
(s, o) = commands.getstatusoutput(cmd) cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % keypath
if s != 0: (s, o) = commands.getstatusoutput(cmd)
logging.error("Could not generate key pair: %d" % s) if s != 0:
logging.error("Could not generate key pair: %d" % s)
else:
logging.error("Keypair exists, skip generation.")
gtk.main_quit() gtk.main_quit()
return False return False

@ -74,8 +74,7 @@ _start_matchbox()
_setup_translations() _setup_translations()
# Do initial setup if needed # Do initial setup if needed
key = profile.get_pubkey() if not profile.is_valid():
if not key or not len(key):
win = intro.IntroWindow() win = intro.IntroWindow()
win.show_all() win.show_all()
gtk.main() gtk.main()

@ -49,6 +49,7 @@ class _Profile(object):
privkey_hash -- SHA has of the child's public key privkey_hash -- SHA has of the child's public key
""" """
def __init__(self): def __init__(self):
self.valid = True
self.name = None self.name = None
self.color = None self.color = None
self.pubkey = None self.pubkey = None
@ -56,26 +57,29 @@ class _Profile(object):
self.server = None self.server = None
self.server_registered = False self.server_registered = False
self.backup1 = None self.backup1 = None
self._config_path = os.path.join(env.get_profile_path(), 'config')
self._load() self._load()
def update(self): def update(self):
self._load() self._load()
def _load(self): def _load(self):
cp = ConfigParser() self._load_config()
config_path = os.path.join(env.get_profile_path(), 'config')
parsed = cp.read([config_path])
self._load_config(cp)
del cp
self._load_pubkey() self._load_pubkey()
self._hash_private_key() self._hash_private_key()
def _load_config(self, cp): def _load_config(self):
cp = ConfigParser()
parsed = 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')
# decode nickname from ascii-safe chars to unicode # decode nickname from ascii-safe chars to unicode
self.name = name.decode("utf-8") self.name = name.decode("utf-8")
else:
self.valid = False
if cp.has_option('Buddy', 'Color'): if cp.has_option('Buddy', 'Color'):
self.color = XoColor(cp.get('Buddy', 'Color')) self.color = XoColor(cp.get('Buddy', 'Color'))
@ -91,6 +95,8 @@ class _Profile(object):
if cp.has_option('Server', 'Backup1'): if cp.has_option('Server', 'Backup1'):
self.backup1 = cp.get('Server', 'Backup1') self.backup1 = cp.get('Server', 'Backup1')
del cp
def _load_pubkey(self): def _load_pubkey(self):
self.pubkey = None self.pubkey = None
@ -100,6 +106,7 @@ class _Profile(object):
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
@ -142,20 +149,23 @@ class _Profile(object):
def set_key(self, section, key, value): def set_key(self, section, key, value):
cp = ConfigParser() cp = ConfigParser()
config_path = os.path.join(env.get_profile_path(), 'config') parsed = cp.read([self._config_path])
parsed = cp.read([config_path])
if not cp.has_section(section): if not cp.has_section(section):
cp.add_section(section) cp.add_section(section)
cp.set(section, key, value) cp.set(section, key, value)
f = open(config_path, 'w') f = open(self._config_path, 'w')
cp.write(f) cp.write(f)
f.close() f.close()
self._load_config(cp)
del cp del cp
self._load_config()
def is_valid():
return _profile.valid
def get_nick_name(): def get_nick_name():
return _profile.name return _profile.name

Loading…
Cancel
Save