[Nym3-commit] r173 - trunk/nym3/Client
laurent at conuropsis.org
laurent at conuropsis.org
Tue Apr 5 17:59:41 CEST 2005
Author: laurent
Date: 2005-04-05 17:59:38 +0200 (Tue, 05 Apr 2005)
New Revision: 173
Modified:
trunk/nym3/Client/Account.py
trunk/nym3/Client/Config.py
trunk/nym3/Client/Main.py
Log:
Improve config handling.
Modified: trunk/nym3/Client/Account.py
===================================================================
--- trunk/nym3/Client/Account.py 2005-04-04 20:11:37 UTC (rev 172)
+++ trunk/nym3/Client/Account.py 2005-04-05 15:59:38 UTC (rev 173)
@@ -43,21 +43,25 @@
class TagMap:
"""Contains mapping between idTag and nickname"""
- def __init__(self):
+ def __init__(self, filename):
self.id2nick = {}
self.nick2id = {}
+ self.filename = filename
+ def __del__(self):
+ if self.lock: self._release()
+
def _lock(self):
"""Lock the tagmap file"""
- self.lock = mixminion.Common.Lockfile(Config.path + os.sep +
- 'tagmap.lck')
+ self.lock = mixminion.Common.Lockfile(self.filename + '.lck')
self.lock.acquire()
def _release(self):
self.lock.release()
+ self.lock = None
def _tagfile(self):
- return Config.path + os.sep + "tagmap"
+ return self.filename
def _load(self):
tag = self._tagfile()
@@ -95,6 +99,7 @@
self._lock()
self._load()
if self.nick2id.has_key(nick):
+ self._release()
raise AlreadySuchAccount()
while True:
tag = Mail.genMid(8)
@@ -109,7 +114,7 @@
class Account:
"""Hold account data"""
- def __init__(self, nickname, create = 0):
+ def __init__(self, config, nickname, create = 0):
"""Load from an existing account, or create a new, or fail"""
# Set data to dummy values
self.idTag = None
@@ -118,13 +123,17 @@
self.mbox = None
self.syn = None
self.params = None
+ self.lock = None
+ self.config = config
+
if create == 1:
- tagmap = TagMap()
+ tagmap = TagMap(config.path + os.sep + 'tagmap')
self.idTag = tagmap.getnewId(nickname)
# If the nick already existed, we're out of this because of
# a thrown AlreadySuchAccount.
# Everything below this line has not been reread and can be considered
# work in progress.
+ self._lock()
def __del__(self):
@@ -133,7 +142,7 @@
self._save_synbox()
self._save_mbox()
self._save_data()
- self._release()
+ if self.lock: self._release()
def __getitem__(self, key):
"""Gets user account field as in a hashtable"""
@@ -145,7 +154,7 @@
def _lock(self):
"""Locks the user. For well behaved functions."""
- self.lock = mixminion.Common.Lockfile(Config.path + os.sep + self.idTag + '.lck')
+ self.lock = mixminion.Common.Lockfile(self.config.path + os.sep + self.idTag + '.lck')
self.lock.acquire()
def _release(self):
Modified: trunk/nym3/Client/Config.py
===================================================================
--- trunk/nym3/Client/Config.py 2005-04-04 20:11:37 UTC (rev 172)
+++ trunk/nym3/Client/Config.py 2005-04-05 15:59:38 UTC (rev 173)
@@ -1,5 +1,5 @@
# $Id$
-#
+# -*- coding: utf-8 -*-
# Copyright (c) 2004,2005 Jean-René Reinhard <jr at komite.net>
# and Laurent Fousse <laurent at komite.net>.
#
@@ -22,18 +22,17 @@
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-DEBUG = False
-"""Tells the client whether he should send the messages he generates through
-mixminion or output them on stdout"""
+class Config:
+
+ def __init__(self):
+ #Tells the client whether he should send the messages he generates
+ # through mixminion or output them on stdout
+ self.DEBUG = False
+ #The path to the directory containing the user accounts
+ self.path = '.'
-path = '.'
-"""The path to the directory containing the user accounts"""
+ #address where surbs point to"""
+ self.defaultAddress = "smtp:nobody at nowhere.net"
-defaultUser = "nym at server"
-"""idTag of the default account"""
-
-defaultAddress = "smtp:nobody at nowhere.net"
-"""address where surbs point to"""
-
-default_settings = { 'address' : defaultAddress }
-"""default_settings"""
+ def load_from_file(self, filename):
+ pass
Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py 2005-04-04 20:11:37 UTC (rev 172)
+++ trunk/nym3/Client/Main.py 2005-04-05 15:59:38 UTC (rev 173)
@@ -66,7 +66,7 @@
elif (com.ct() == 5):
pass
-def setupAccount(ui, serverName = None, usernamelist = None,
+def setupAccount(config, ui, serverName = None, usernamelist = None,
emailAddress = None, nickname = None):
"""Tries to setup a new account on the given server"""
if not nickname:
@@ -74,7 +74,7 @@
while True: # chose a suitable account name
account = None
try:
- account = Account.Account(nickname, create = 1)
+ account = Account.Account(config, nickname, create = 1)
except Account.AlreadySuchAccount:
ui.display("This account name is already in use")
nickname = ui.prompt("New account name")
@@ -114,7 +114,8 @@
myusernamelist = []
if options.username:
myusernamelist = string.split(options.username, ":")
- setupAccount(ui, serverName = options.server,
+ config = Config.Config() # TODO load from file
+ setupAccount(config, ui, serverName = options.server,
usernamelist = myusernamelist,
emailAddress = options.email, nickname = options.nickname)
More information about the Nym3-commit
mailing list