[Nym3-commit] r489 - in trunk: nymbaron/Server tools/server
jr at conuropsis.org
jr at conuropsis.org
Sun Mar 19 15:45:40 CET 2006
Author: jr
Date: 2006-03-19 15:45:38 +0100 (Sun, 19 Mar 2006)
New Revision: 489
Modified:
trunk/nymbaron/Server/Main.py
trunk/tools/server/Account_handler.py
Log:
- Finish add-msg command in the account-handler
- Document readMessage
Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py 2006-03-18 21:08:26 UTC (rev 488)
+++ trunk/nymbaron/Server/Main.py 2006-03-19 14:45:38 UTC (rev 489)
@@ -69,6 +69,8 @@
config = None
def readMessage(filename):
+ """Reads an incoming message from file filename, or stdin if filename is
+ None."""
if filename:
try:
f = open(filename, "r")
Modified: trunk/tools/server/Account_handler.py
===================================================================
--- trunk/tools/server/Account_handler.py 2006-03-18 21:08:26 UTC (rev 488)
+++ trunk/tools/server/Account_handler.py 2006-03-19 14:45:38 UTC (rev 489)
@@ -2,22 +2,28 @@
import os
import sys
import binascii
+import time
import nymbaron.Mail as Mail
import nymbaron.Server.Config as Config
import nymbaron.Server.User as User
from nymbaron.Client.Main import get_account_from_nickname
-from nymbaron.Server.Main import load_config
+from nymbaron.Server.Main import load_config, readMessage
from nymbaron.Mail import XNymSeq
import nymbaron.Server.Main as Main
-config = None
-
usage_string = """Usage: account_handler <command> [arguments]
where command is one of:
\tadd-msg\t\tAdd synopses
- \tdisplay-synbox\tDsiplays the content of the synbox
+ \tdisplay-synbox\tDiplays the content of the synbox
\thelp\t\tDisplay this help"""
+test_msg = """From: admin at nymserver
+Subject: Test message
+
+This test message was added using the server Account_Handler. If your account
+isn't meant for testing purposes please report to your server administrator.
+"""
+
def main(args):
if len(args) < 2:
print usage_string
@@ -34,14 +40,16 @@
parser.add_option("-r", "--read-file", action = "store_true", dest =
"read_file", default = False, help = "whether to read the message \
from somewhere or generate a \"standard\" test message")
- parser.add_option("-f", "--file", action = "store",
- dest = "file", help = "if read_file is set: the file to read \
+ parser.add_option("-f", "--file", action = "store", dest = "file",
+ help = "if read_file is set: the file to read \
the message from, or stdin if omitted, otherwise: \
ignored")
parser.add_option("-a", "--age", action = "store", type = "int",
dest = "age", default = 0, help = "this option fakes the age \
of a message: age seconds are substracted from the \
- time of arrival of the message to the server.")
+ time of arrival of the message to the server. If the \
+ message is older as the younger message in the synbox, \
+ nothing is done.")
parser.add_option("-b", "--batch", action = "store", type = "int",
dest = "batch", default = 1, help = "repeats the add-msg \
behaviour 'batch' times.")
@@ -52,7 +60,7 @@
sys.exit(1)
else:
try:
- nymUser = User.User(options.nym, config)
+ nymUser = User.User(options.nym, Main.config)
except User.NoSuchUser:
print "No such user %s" % options.nym
sys.exit(73)
@@ -61,11 +69,26 @@
to read the message from a file. See --read-file option.\n\
Options inconsistency, doing nothing.")
sys.exit(1)
+ nymUser.load_synbox()
+ nymUser.load_index()
for i in range(options.batch):
- #TODO get_message
- #TODO store message
- #TODO tweak the stored message time of arrival.
- pass
+ if options.read_file:
+ msg = readMessage(options.file)
+ else:
+ msg = test_msg
+ now = int(time.time())
+ target_time = now - options.age
+ #the time of the last inserted message of the synbox
+ timeyoungest = nymUser.index[nymUser.syn[-1][0][-1]]['time']
+ if target_time < timeyoungest:
+ print "The message that would be inserted would be older " + \
+ "than the most recent message received by the " + \
+ "account. Retry with age parameter < %d. Aborting." % \
+ (now - timeyoungest)
+ sys.exit(2)
+ nymUser.store(msg)
+ midIns = nymUser.syn[-1][0][0]
+ nymUser.index[midIns]['time'] = target_time
sys.exit(0)
if args[1] == "help":
More information about the Nym3-commit
mailing list