[Nym3-commit] r126 - trunk/nym3/Client

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Tue, 24 Aug 2004 23:51:56 +0200


Author: jr
Date: 2004-08-24 23:51:53 +0200 (Tue, 24 Aug 2004)
New Revision: 126

Modified:
   trunk/nym3/Client/Main.py
   trunk/nym3/Client/User.py
Log:
- begin the setup command (Client.Main)
- class Tag to represent the correspondance between user friendly tag and random generated ones (Client.User)


Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py	2004-08-24 16:22:16 UTC (rev 125)
+++ trunk/nym3/Client/Main.py	2004-08-24 21:51:53 UTC (rev 126)
@@ -10,22 +10,22 @@
 def processMessage(msg):
     """process incoming control message
     """
-
-    sr = nym3.Message.StrReader(msg)
+      
+    sr = Message.StrReader(msg)
     comList = sr.readCommandCToSList()
     for com in comList:
-	if (com.ct() == 0):
-	    pass
-	elif (com.ct() == 1):
-	    pass
-	elif (com.ct() == 2):
-	    pass
-	elif (com.ct() == 3):
-	    pass
-	elif (com.ct() == 4):
-	    pass
-	elif (com.ct() == 5):
-	    pass
+        if (com.ct() == 0):
+            pass
+        elif (com.ct() == 1):
+            pass
+        elif (com.ct() == 2):
+            pass
+        elif (com.ct() == 3):
+            pass
+        elif (com.ct() == 4):
+            pass
+        elif (com.ct() == 5):
+            pass
 
 def setUpAccount(serverName):
     try:
@@ -49,7 +49,7 @@
             sys.exit(2)
 
     def setDefaultUser():
-        setUser(None, "", Config.defaultUser, None)
+        setUser(None,"",Config.defaultUser,None)
 
     def myParseArgs(p,l):
         ret = p.parse_args(l)
@@ -63,17 +63,13 @@
     nymUser = None
     
     #TODO put here options common to every command
-    parser.add_option("-D", "--debug", action = "callback", 
-		      callback = setDebug, help = "output message on stdout\
-		      instead of sending them through mixminion")
-    userOption = make_option("-u", "--user", action = "callback", 
-			     callback = setUser, type = "string", 
-			     help = "determine the user account to be used")
-    # ", Client.Config.DefaultUser by default")
-    # how helpful is that supposed to be to the user?
+    parser.add_option("-D","--debug", action = "callback", callback = setDebug, help = "output message on stdout instead of sending them through mixminion")
+    userOption = make_option("-u","--user", action = "callback", callback = setUser, type = "string", help = "determine the user account to be used, Client.Config.DefaultUser by default")
     
     if sys.argv[1] == 'setup':
-        pass
+        parser.usage = "%prog setup [options] nym1 [nym2 [...]]"
+        (options, args) = parser.parse_args(sys.argv[2:])
+         
     #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 16:22:16 UTC (rev 125)
+++ trunk/nym3/Client/User.py	2004-08-24 21:51:53 UTC (rev 126)
@@ -1,5 +1,6 @@
 import os
 import nym3.Client.Config as Config
+import nym3.Mail as Mail
 import mixminion.Common
 import nym3.Common as Common
 import mixminion.Crypto as _cr
@@ -7,18 +8,68 @@
 
 class AlreadySuchUser(Exception): pass
 
+class AlreadySuchTag(Exception): pass
 
+class Tag:
+    """contains correspondance between account id and readable tag"""
+    def __init__(self):
+        self.data = None
+
+    def __del__(self):
+        if self.data != None:
+            self.save()
+            self._release()
+
+
+    def _lock(self):
+        """Lock the tag file"""
+        self.lock = mixminion.Common.Lockfile(Config.path + os.sep + 'tag.lck')
+        self.lock.acquire()
+
+    def _release(self):
+        self.lock.release()
+
+    def tagfile(self):
+        return Config.path + os.sep + "tag" 
+
+    def load(self):
+        if not self.data == None: return
+        self._lock()
+	tag = self.tagfile()
+	try:
+	    f = open(tag, 'r')
+	    self.data = pickle.load(f)
+	    f.close()
+	except IOError:
+	    self.data = {}
+
+        
+    def save(self):
+        if self.data == None: return
+	tag = self.tagfile()
+	f = open(mbox, 'w')
+	pickle.dump(self.data, f)
+	f.close()
+
+    def store(self, tag, idTag):
+        if self.data == None:
+            self._lock()
+            self.load()
+        if self.data.has_key(tag):
+            raise AlreadySuchKey
+        self.data[tag] = idTag
+
 class User:
     """Hold user data"""
-    def __init__(self, username, create = 0):
+    def __init__(self, idTag="", 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 throw an error if the account doesn't exist
-        1 : create a new account throw an error if it already exist
-        _ : load user data create an account if the account doesn't exist
+        """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
+        _ : 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>
         """
-        self.username = username
-        self.home = Config.path + os.sep + username + os.sep
+        self.idTag = idTag
+        self.home = Config.path + os.sep + idTag + os.sep
         self.datafile = self.home + 'data'
 	self.index = None
 	self.mbox = None