[Nym3-commit] r434 - in trunk: . nymbaron/Server
jr at conuropsis.org
jr at conuropsis.org
Sat Dec 3 23:18:51 CET 2005
Author: jr
Date: 2005-12-03 23:18:50 +0100 (Sat, 03 Dec 2005)
New Revision: 434
Modified:
trunk/TODO
trunk/nymbaron/Server/Main.py
Log:
- rewrite the argument parser of the server
Warning : this breaks the old interface
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2005-12-01 23:43:08 UTC (rev 433)
+++ trunk/TODO 2005-12-03 22:18:50 UTC (rev 434)
@@ -22,6 +22,9 @@
- periodically scan for emails that need to be relayed [server]
- periodically scan for synopses that have stayed that need to be encrypted
[server]
+ - add a "shell" to the client
+ - add send queues to the client and the server
+ - fix number of messages awaiting on the server
o fix bugs in encOldSyn (not defined global variables) [server]
. use clean_surbs once in a while (while adding surbs to a surbfile, the
surbfile is cleaned) [server]
Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py 2005-12-01 23:43:08 UTC (rev 433)
+++ trunk/nymbaron/Server/Main.py 2005-12-03 22:18:50 UTC (rev 434)
@@ -29,7 +29,7 @@
This package contains an implementation of a nymbaron server."""
import sys
-import getopt
+from optparse import OptionParser, make_option
import nymbaron.Server.User as User
import nymbaron.Server.Config as Config
import nymbaron.Message as Message
@@ -40,6 +40,31 @@
lifeCycle = User.lifeCycle
"""The life cycle of a mail received by the server for a nym"""
+usage_string = """Usage: nymbarond <command> [arguments]
+where <command> is one of:
+ \thelp\t\tDisplays this help
+ \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
+ \tencode-synopses\tEncrypt synopses that are still in clear"""
+
+def readMessage(filename):
+ if filename:
+ try:
+ f = open(filename, "r")
+ msg = f.read()
+ f.close()
+ except IOError:
+ print("Can't read requested file")
+ sys.exit(1)
+ else:
+ try:
+ msg = sys.stdin.read()
+ except KeyboardInterrupt:
+ print "Interrupted by the user"
+ sys.exit(2)
+ return msg
+
# Try to load the configuration file.
try:
import os
@@ -279,37 +304,52 @@
print inst
sys.exit(2) #TODO error code
-def main(argv):
- optlist, pholder = getopt.getopt(argv[1:], 'D:d:m')
- for o, a in optlist:
- if o == "-D":
- config.DEBUG = True
-
- for o, a in optlist:
- if o == "-d": # mail delivery
- try:
- processIncoming(a, sys.stdin.read())
- except KeyboardInterrupt:
- print "Interrupted by the User"
- sys.exit(2)
- sys.exit(0)
- if o == "-m":
- try:
- msg = sys.stdin.read()
- except KeyboardInterrupt:
- print "Interrupted by the User"
- sys.exit(2)
- try:
- processMessage(msg)
- except Exception:
- # see if we got a base64 encoded message.
- import base64
- import re
- m = re.search("binary\\n\\n(.*)\\n---", msg, re.S)
- if m:
- processMessage(base64.decodestring(m.group(1)))
- else: sys.stderr.write("Unable to find valid control message")
- sys.exit(0)
+def main(args):
+ if len(args) < 2:
+ print usage_string
+ sys.exit(1)
+ #TODO load the config file here?
+ if args[1] == "deliver":
+ parser = OptionParser(usage =
+ """nymbarond deliver [options]
+ Deliver a message to a nym account.""")
+ parser.add_option("-n", "--nym", action = "store", dest = "nym",
+ help = "The nym to which deliver the message")
+ parser.add_option("-f", "--file", action = "store",
+ dest = "file", help = "The file to read the message " +
+ "from, or stdin if omitted")
+ (options, args) = parser.parse_args(args[2:])
+ if not options.nym:
+ print ("You must provide a nym to which the message is adressed")
+ sys.exit(1)
+ processIncoming(options.nym, readMessage(options.file))
+ sys.exit(0)
+ if args[1] == "process":
+ parser = OptionParser(usage =
+ """nymbarond process [options]
+ Process a command message.""")
+ parser.add_option("-f", "--file", action = "store",
+ dest = "file", help = "The file to read the message " +
+ "from, or stdin if omitted")
+ (options, args) = parser.parse_args(args[2:])
+ try:
+ processMessage(readMessage(options.file))
+ except Exception:#TODO catch a more detailed exception
+ # see if we got a base64 encoded message.
+ import base64
+ import re
+ m = re.search("binary\\n\\n(.*)\\n---", msg, re.S)
+ if m:
+ processMessage(base64.decodestring(m.group(1)))
+ else:
+ sys.stderr.write("Unable to find valid control message")
+ sys.exit(0)
+ if args[1] == "help":
+ print usage_string
+ sys.exit(0)
+ # Unknown command
+ sys.stderr.write("Error: unknown command \"" + args[1] + "\"\n")
+ sys.exit(1)
if __name__ == '__main__':
main(sys.argv)
More information about the Nym3-commit
mailing list