[Nym3-commit] r504 - trunk/nymbaron/Server

laurent at conuropsis.org laurent at conuropsis.org
Tue Mar 21 17:21:23 CET 2006


Author: laurent
Date: 2006-03-21 17:21:22 +0100 (Tue, 21 Mar 2006)
New Revision: 504

Modified:
   trunk/nymbaron/Server/Main.py
Log:
Introduce the `purge-accounts' server command, to expire accounts.


Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py	2006-03-21 16:19:37 UTC (rev 503)
+++ trunk/nymbaron/Server/Main.py	2006-03-21 16:21:22 UTC (rev 504)
@@ -53,6 +53,7 @@
     \tdeliver\t\tDeliver a message to a nymholder
     \tprocess\t\tProcess a command message
     \tclean-surbs\tRemove used or outdated surbs from account surb files
+    \tpurge-accounts\tDelete inactive accounts
     \tencode-synopses\tEncrypt synopses that are still in clear"""
 
 class MalformedControlMessage(Exception):
@@ -114,6 +115,19 @@
             else:
                 fun(nymuser)
 
+def purgeAccount(account, timestamp):
+    """Check if the account given as argument has not received any
+       sign of activity from the user since a given timestamp.
+       If it is the case, delete it.
+    """
+    # Support for revision previous to r485, when lastSeen
+    # was introduced.
+    if not 'lastSeen' in account:
+        account['lastSeen'] = time.time()
+    if account['lastSeen'] < timestamp:
+        logger.info("Purging account %s" % account.username)
+        account.nuke()
+
 def isMsgBinary(msg):
     """ This function returns True is the message is binary.  It
     checks by looking at what percentage of characters are non-textual.
@@ -453,6 +467,15 @@
         mapAccount(User.User.clean_surbs)
         sys.exit(0)
 
+    if args[1] == "purge-accounts":
+        if config.purgeAfter is not None:
+            timestamp = time.time() - config.purgeAfter * 3600 * 24
+            mapAccount(purgeAccount, (timestamp,))
+        else:
+            sys.stdout.write("Please specify option [accounts] purgeAfter" +
+                             "for this command to work\n")
+        sys.exit(0)
+
     if args[1] == "encode-synopses":
         sys.exit(0)
     



More information about the Nym3-commit mailing list