[Nym3-commit] r349 - trunk/nymbaron/Client

jr at conuropsis.org jr at conuropsis.org
Fri Oct 14 21:27:11 CEST 2005


Author: jr
Date: 2005-10-14 21:27:10 +0200 (Fri, 14 Oct 2005)
New Revision: 349

Modified:
   trunk/nymbaron/Client/Account.py
   trunk/nymbaron/Client/Main.py
Log:
- Account creation leaves the client files clean if aborted


Modified: trunk/nymbaron/Client/Account.py
===================================================================
--- trunk/nymbaron/Client/Account.py	2005-10-14 19:11:32 UTC (rev 348)
+++ trunk/nymbaron/Client/Account.py	2005-10-14 19:27:10 UTC (rev 349)
@@ -134,6 +134,16 @@
 	self._loadifneeded()
 	return self.nick2id.keys()
 
+    def remove(self, idTag):
+	self._loadifneeded()
+	self._lock()
+	if self.id2nick.has_key(idTag):
+	    nick = self.id2nick[idTag]
+	    del self.id2nick[idTag]
+	    del self.nick2id[nick]
+	    self._save()
+	self._release()
+	
 class Account:
     """Hold account data. Specifically, this means:
 
@@ -168,7 +178,6 @@
 	"""Load from an existing account, or create a new, or fail"""
 	# Some data related to the account are loaded only on demand,
 	# this includes the journal, the mailbox, the synbox.
-	self.lock = None
 	self.succeeded = True
 	self.config = config
 	# If home directory does not exist, create it:
@@ -176,11 +185,12 @@
 	    os.stat(config.path)
 	except OSError:
 	    os.makedirs(config.path)
-	tagmap = TagMap(config.path + os.sep + 'tagmap')
+	self.tagmap = TagMap(config.path + os.sep + 'tagmap')
 	if create:
 	    self.data = {}
 	    self.succeeded = False
-	    self['idTag'] = tagmap.getnewId(nickname)
+	    self['idTag'] = self.tagmap.getnewId(nickname)
+	    self._lock()
 	    # If the nick already existed, we're out of this because of
 	    # a thrown AlreadySuchAccount.
 	    # Create the dir that holds this account data
@@ -203,15 +213,19 @@
 	    self.journal_status = 'unloaded'
 	    self.mbox_status = 'unloaded'
 	    self.synbox_status = 'unloaded'
-	    idTag = tagmap.idFromNick(nickname)
+	    idTag = self.tagmap.idFromNick(nickname)
 	    self.base_path = config.path + os.sep + idTag
 	    self._load_data()
+	    self._lock()
 	    self.journal = None
 	    self.mbox = None
 	    self.synbox = None
 	    self.synbox_enc_status = None
+
+    def creationSuccess(self):
+	"Tells the system that this account is successfully initialized. Call
+	this method once the account is successfully setup."
 	self.succeeded = True
-	self._lock()
 
     def generateSurbs(self, n):
         """Generate surbs"""
@@ -376,12 +390,15 @@
 
     def __del__(self):
 	"""Flushes the user account to the disk"""
-	if not self.succeeded: return
-        self._save_synbox()
-        self._save_mbox()
-	self._save_journal()
-        self._save_data()
-        if self.lock: self._release()
+	if self.succeeded:
+	    self._save_synbox()
+	    self._save_mbox()
+	    self._save_journal()
+	    self._save_data()
+	else:
+	    os.removedirs(self.base_path)
+	    self.tagmap.remove(self['idTag'])
+	self._release()
 
     def _load_mbox(self):
 	"""Loads the mailbox from the disk"""

Modified: trunk/nymbaron/Client/Main.py
===================================================================
--- trunk/nymbaron/Client/Main.py	2005-10-14 19:11:32 UTC (rev 348)
+++ trunk/nymbaron/Client/Main.py	2005-10-14 19:27:10 UTC (rev 349)
@@ -379,7 +379,7 @@
 	    # TODO : warn for an empty passphrase.
 	    ui.display("Passphrases do not match.")
 	secring = Keyring.Keyring(config.secring_path, create = True)
-    
+
     idtag = secring.store(_cr.pk_encode_private_key(idKey))
     enctag = secring.store(_cr.pk_encode_private_key(encKey))
     admtag = secring.store(_cr.pk_encode_private_key(admKey))
@@ -399,6 +399,8 @@
     surbc.fromData(account.generateSurbs(7))
     account.sendControl([createc, newpkc, surbc], idKey, "create an account")
     account['handshake'] = "initiated"
+    #the creation of the account succeeded, we can keep the account
+    account.creationSuccess()
 
 def relayMessage(ui, config, nickname = None, to = None, input = None):
     body = None



More information about the Nym3-commit mailing list