[Nym3-commit] r128 - trunk/nym3/Client
nym3-devel@lists.noreply.org
nym3-devel@lists.noreply.org
Wed, 25 Aug 2004 01:52:42 +0200
Author: jr
Date: 2004-08-25 01:52:41 +0200 (Wed, 25 Aug 2004)
New Revision: 128
Modified:
trunk/nym3/Client/Main.py
trunk/nym3/Client/User.py
Log:
- modify User.__init__ to generete idTag when needed (Client.User)
- add a option to tag an account being created (Client.Main)
Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py 2004-08-24 22:55:59 UTC (rev 127)
+++ trunk/nym3/Client/Main.py 2004-08-24 23:52:41 UTC (rev 128)
@@ -43,10 +43,23 @@
nym3.Client.Config.DEBUG = True
def setUser(option, opt, value, parser):
try:
- nymUser = User.User(value)
- except:
+ nymUser = User.User(idTag =value, create = 0)
+ except User.NoSuchUser:
print "the nym account %s does not exist" % value
sys.exit(2)
+
+ def setUserTagged(option, opt, value, parser):
+ try:
+ T = User.Tag()
+ nymUser = User.User(idTag = T[value], create = 0)
+ del T
+ except KeyError:
+ print "No account correspond to the tag %s" % value
+ sys.exit(2)
+ except User.NoSuchUser:
+ print "the nym account %s does not exist" % value
+ sys.exit(2)
+
def setDefaultUser():
setUser(None, "", Config.defaultUser, None)
@@ -71,11 +84,14 @@
help = "determine the user account to be used")
# ", Client.Config.DefaultUser by default")
# how helpful is that supposed to be to the user?
+ taggedUserOption = make_option("-t","--tag", action = "callback", callback = setUserTagged, type = "string", help = "determine the user account to be used from a tag")
if sys.argv[1] == 'setup':
parser.usage = "%prog setup [options] nym1 [nym2 [...]]"
+ parser.add_option("-t","--tag", dest = "tag", default = "", help = "the tag that the user wish to associate with the new account")
(options, args) = parser.parse_args(sys.argv[2:])
-
+ nymUser=User.User(tag = options.tag, create = 1)
+ #generate message to send
#if sys.argv[1] == 'control': #handling of fragments (pipe to mixminion ...
# pass
if sys.argv[1] == 'send-surb':
Modified: trunk/nym3/Client/User.py
===================================================================
--- trunk/nym3/Client/User.py 2004-08-24 22:55:59 UTC (rev 127)
+++ trunk/nym3/Client/User.py 2004-08-24 23:52:41 UTC (rev 128)
@@ -8,7 +8,16 @@
class AlreadySuchUser(Exception): pass
-class AlreadySuchTag(Exception): pass
+def generateIdTag():
+ while True:
+ tag = Mail.genMid(8)
+ rtag = Mail.mid2filename(tag)
+ path = Config.path + os.sep + rtag
+ #TODO do we add a lock here?
+ if not os.access(path, os.F_OK):
+ os.mkdir(path,0700)
+ return rtag
+
class Tag:
"""contains correspondance between account id and readable tag"""
@@ -20,6 +29,10 @@
self.save()
self._release()
+ def __getitem__(self, key):
+ if self.data == None:
+ self.load()
+ return self.data[key]
def _lock(self):
"""Lock the tag file"""
@@ -53,45 +66,49 @@
def store(self, tag, idTag):
if self.data == None:
- self._lock()
self.load()
if self.data.has_key(tag):
- raise AlreadySuchKey
+ print "The tag %s is already in use. IdTag %s is not user tagged" % tag, idTag
self.data[tag] = idTag
class User:
"""Hold user data"""
- def __init__(self, idTag = "", create = 0):
+
+ def __init__(self, idTag="", tag="", create = 0):
#TODO what is the criteria determining which account we must load? For the time being we only have a user account
"""0 : load user data correspondig to idTag, throw an error if the account doesn't exist
- 1 : create a new account (do not take into account idTag) throw an error if it already exist
+ 1 : create a new account (do not take into account idTag)
_ : load user data corresponding to idTag, create an account if the account doesn't exist, and in that case discard idTag
- username is of the form <nym>@<server>
+ tag is an optionnal string. if used when the account is created the association tag -> idTag is kept in the home.tag
"""
self.idTag = idTag
- self.home = Config.path + os.sep + idTag + os.sep
- self.datafile = self.home + 'data'
+ self.datafile = None
self.index = None
self.mbox = None
self.syn = None
self.data = None
self._lock()
try:
- if not os.access(self.home, os.F_OK):
+ self.home = self.homeDir()
+ if create == 1 or idTag == "" or not os.access(self.home,os.F_OK):
raise NoSuchUser
f = open(self.datafile, 'r')
- if create == 1:
- raise AlreadySuchUser
self.data = pickle.load(f)
f.close()
except NoSuchUser:
if create == 0:
raise
else:
- os.mkdir(home, 0700)
+ self.idTag = generateIdTag()
+ self.home = self.homeDir()
+ self.datafile = self.home + 'data'
self.data = Config.default_settings
+ if tag != "":
+ T = Tag()
+ T.store(tag,self.idTag)
+ del T
except IOError:
- print "the user account of %s contains some error : impossible to open %s" % username, self.datafile
+ print "the user account of idTag %s contains some error : impossible to open %s" % idTag, self.datafile
sys.exit(2)
def __del__(self):
@@ -109,13 +126,15 @@
def _lock(self):
"""Lock the user. For well behaved functions."""
- self.lock = mixminion.Common.Lockfile(Config.path + os.sep +
- self.username + '.lck')
+ self.lock = mixminion.Common.Lockfile(Config.path + os.sep + self.idTag + '.lck')
self.lock.acquire()
def _release(self):
self.lock.release()
+ def homeDir(self):
+ return Config.path + os.sep + self.idTag + os.sep
+
def load_mbox(self):
if not self.mbox == None: return
mbox = self.mboxfile()
@@ -176,6 +195,9 @@
pickle.dump(self.index, f)
f.close()
+ def _save_data(self):
+ pass
+
def generate_keys(self):
pass