* 'VirtualMailManager/VirtualMailManager.py'
authorPascal Volk <neverseen@users.sourceforge.net>
Fri, 18 Apr 2008 03:46:11 +0000
changeset 19 bf9a03c476fc
parent 18 c98e08791ee8
child 20 55146c78b3fb
* 'VirtualMailManager/VirtualMailManager.py' * 'VirtualMailManager/Account.py' * 'vmm' - added support to get user (e-mail address) by users id
ChangeLog
VirtualMailManager/Account.py
VirtualMailManager/VirtualMailManager.py
VirtualMailManager/constants/ERROR.py
vmm
--- a/ChangeLog	Tue Apr 15 02:49:21 2008 +0000
+++ b/ChangeLog	Fri Apr 18 03:46:11 2008 +0000
@@ -1,4 +1,10 @@
 === 0.0.0 ===
+2008-04-18  Pascal Volk  <neverseen@users.sourceforge.net>
+
+	* VirtualMailManager/Account.py: Implemented getAccountByID()
+	* VirtualMailManager/VirtualMailManager.py (VirtualMailManager): 
+	* vmm: Implemented user_byID()
+
 2008-04-15  Pascal Volk  <neverseen@users.sourceforge.net>
 
 	* VirtualMailManager/Account.py (Account.modify()): 
--- a/VirtualMailManager/Account.py	Tue Apr 15 02:49:21 2008 +0000
+++ b/VirtualMailManager/Account.py	Fri Apr 18 03:46:11 2008 +0000
@@ -183,3 +183,26 @@
         else:
             raise VMMAccountException(("Account doesn't exists",
                 ERR.NO_SUCH_ACCOUNT))
+
+
+def getAccountByID(uid, dbh):
+    try:
+        uid = long(uid)
+    except ValueError:
+        raise VMMAccountException(('uid must be an int/long.',
+            ERR.INVALID_AGUMENT))
+    if uid < 1:
+        raise VMMAccountException(('uid must be greater than 0.',
+            ERR.INVALID_AGUMENT))
+    dbc = dbh.cursor()
+    dbc.execute("SELECT local_part||'@'||domains.domainname AS address, uid,\
+ gid FROM users LEFT JOIN domains USING(gid) WHERE uid=%s", uid)
+    info = dbc.fetchone()
+    dbc.close()
+    if info is None:
+        raise VMMAccountException(("Account doesn't exists",
+            ERR.NO_SUCH_ACCOUNT))
+    keys = ['address', 'uid', 'gid']
+    info = dict(zip(keys, info))
+    return info
+
--- a/VirtualMailManager/VirtualMailManager.py	Tue Apr 15 02:49:21 2008 +0000
+++ b/VirtualMailManager/VirtualMailManager.py	Fri Apr 18 03:46:11 2008 +0000
@@ -490,6 +490,11 @@
             info['disk usage'] = self.__getDiskUsage('%(maildir)s' % info)
         return info
 
+    def user_byID(self, uid):
+        from Account import getAccountByID
+        self.__dbConnect()
+        return getAccountByID(uid, self.__dbh)
+
     def user_password(self, emailaddress, password):
         acc = self.__getAccount(emailaddress)
         acc.modify('password', self.__pwhash(password))
--- a/VirtualMailManager/constants/ERROR.py	Tue Apr 15 02:49:21 2008 +0000
+++ b/VirtualMailManager/constants/ERROR.py	Fri Apr 18 03:46:11 2008 +0000
@@ -22,18 +22,19 @@
 DOMAIN_TOO_LONG = 35
 FOUND_DOTS_IN_PATH = 36
 INVALID_ADDRESS = 37
-INVALID_OPTION = 38
-INVALID_SECTION = 39
-LOCALPART_INVALID = 40
-LOCALPART_TOO_LONG = 41
-MAILDIR_PERM_MISMATCH = 42
-MAILLOCATION_INIT = 43
-NOT_EXECUTABLE = 44
-NO_SUCH_ACCOUNT = 45
-NO_SUCH_ALIAS = 46
-NO_SUCH_BINARY = 47
-NO_SUCH_DIRECTORY = 48
-NO_SUCH_DOMAIN = 49
-TRANSPORT_INIT = 50
-UNKNOWN_MAILLOCATION_ID = 51
-UNKNOWN_TRANSPORT_ID = 52
+INVALID_AGUMENT = 38
+INVALID_OPTION = 39
+INVALID_SECTION = 40
+LOCALPART_INVALID = 41
+LOCALPART_TOO_LONG = 42
+MAILDIR_PERM_MISMATCH = 43
+MAILLOCATION_INIT = 44
+NOT_EXECUTABLE = 45
+NO_SUCH_ACCOUNT = 46
+NO_SUCH_ALIAS = 47
+NO_SUCH_BINARY = 48
+NO_SUCH_DIRECTORY = 49
+NO_SUCH_DOMAIN = 50
+TRANSPORT_INIT = 51
+UNKNOWN_MAILLOCATION_ID = 52
+UNKNOWN_TRANSPORT_ID = 53
--- a/vmm	Tue Apr 15 02:49:21 2008 +0000
+++ b/vmm	Fri Apr 18 03:46:11 2008 +0000
@@ -45,6 +45,7 @@
   aa    aliasadd        alias@domain.tld user@domain.tld
   ai    aliasinfo       alias@domain.tld
   ad    aliasdelete     alias@domain.tld user@domain.tld*
+  gu    getuser         userid
   cf    configure                        section*
   h     help
   v     version
@@ -251,6 +252,13 @@
     else:
         vmm.alias_delete(sys.argv[2].lower(), sys.argv[3].lower())
 
+def user_byID():
+    global argc
+    if argc < 3:
+        usage(EXIT.MISSING_ARGS, 'Missing userid')
+    else:
+        _printInfo(vmm.user_byID(sys.argv[2]), 'Account')
+
 def showWarnings():
     if vmm.hasWarnings():
         print '\nWarnings:'
@@ -303,6 +311,8 @@
             alias_info()
         elif sys.argv[1] in ['ad', 'aliasdelete']:
             alias_delete()
+        elif sys.argv[1] in ['gu', 'getuser']:
+            user_byID()
         elif sys.argv[1] in ['h', 'help']:
             usage()
         elif sys.argv[1] in ['v', 'version']: