[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Implement the missing pieces of client-side fragment re...
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv2956/lib/mixminion
Modified Files:
ClientMain.py ClientUtils.py Main.py
Log Message:
Implement the missing pieces of client-side fragment reassembly
Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -d -r1.160 -r1.161
--- ClientMain.py 2 Mar 2004 05:40:14 -0000 1.160
+++ ClientMain.py 2 Mar 2004 06:05:32 -0000 1.161
@@ -1911,3 +1911,107 @@
days = "<1"
print "%2d packets for %s (oldest is %s days old)"%(
count, server, days)
+
+_LIST_FRAGMENTS_USAGE = """\
+Usage: %(cmd)s [options]
+ -h, --help Print this usage message and exit.
+ -v, --verbose Display extra debugging messages.
+ -f <file>, --config=<file> Use a configuration file other than ~.mixminionrc
+ (You can also use MIXMINIONRC=FILE)
+
+EXAMPLES:
+ Describe the state of fragmented messages currently being reassembled.
+ %(cmd)s
+""".strip()
+
+def listFragments(cmd, args):
+ options, args = getopt.getopt(args, "hvQf:D:",
+ ["help", "verbose", "quiet", "config=",
+ 'download-directory=',])
+ try:
+ parser = CLIArgumentParser(options, wantConfig=1, wantLog=1,
+ wantClient=1, wantClientDirectory=1)
+ except UsageError, e:
+ e.dump()
+ print _LIST_FRAGMENTS_USAGE % { 'cmd' : cmd }
+ sys.exit(1)
+
+ parser.init()
+ client = parser.client
+
+ try:
+ clientLock()
+ res = client.pool.formatMessageList()
+ finally:
+ clientUnlock()
+
+ if not res:
+ print "(No fragments being reassembled)"
+ return
+
+ for line in res:
+ print line
+
+
+_REASSEMBLE_USAGE = """\
+Usage: %(cmd)s [options] <message-id> ...
+ -h, --help Print this usage message and exit.
+ -v, --verbose Display extra debugging messages.
+ -f <file>, --config=<file> Use a configuration file other than ~.mixminionrc
+ (You can also use MIXMINIONRC=FILE)
+""".strip()
+
+def reassemble(cmd, args):
+ options, args = getopt.getopt(args, "hvQf:D:Po:",
+ ["help", "verbose", "quiet", "config=",
+ 'download-directory=','--purge',
+ '--output'])
+ reassemble = 1
+ if cmd.endswith("purge-fragments"):
+ reassemble = 0
+ try:
+ parser = CLIArgumentParser(options, wantConfig=1, wantLog=1,
+ wantClient=1, wantClientDirectory=1)
+ except UsageError, e:
+ e.dump()
+ print _REASSEMBLE_USAGE % { 'cmd' : cmd }
+ print """\
+ -P, --purge Remove the message from the pool.
+ -o <file>, --output=<file> Write the message to a file instead of stdout
+""".strip()
+ sys.exit(1)
+ purge = not reassemble
+ outfilename = None
+ for o,v in options:
+ if o in ('-o', '--output'):
+ outfilename = v
+ elif o in ("-P", "--purge"):
+ purge = 1
+
+ if not args:
+ print "No message-IDs provided."
+ return
+
+ parser.init()
+ client = parser.client
+
+ closeoutfile = 0
+ if reassemble:
+ out = sys.stdout
+ if outfilename not in ('-',None):
+ out = open(outfilename, 'r')
+ closeoutfile = 1
+
+ try:
+ clientLock()
+ for msgid in args:
+ if reassemble:
+ msg = client.pool.getMessage(msgid)
+ if purge:
+ client.pool.removeMessage(msgid)
+ if reassemble:
+ out.write(msg)
+ finally:
+ clientUnlock()
+ if reassemble and closeoutfile:
+ out.close()
Index: ClientUtils.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientUtils.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- ClientUtils.py 2 Mar 2004 05:40:14 -0000 1.21
+++ ClientUtils.py 2 Mar 2004 06:05:32 -0000 1.22
@@ -932,7 +932,9 @@
def formatMessageList(self):
msgs = self.listMessages()
result = []
- for msgid in msgs.keys():
+ msgids = msgs.keys()
+ msgids.sort()
+ for msgid in msgids:
result.append(msgid+(": to <%(nym)s>. %(size)s bytes (%(have)s/%(need)s packets received)"
% msgs[msgid]))
return result
Index: Main.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Main.py,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- Main.py 1 Mar 2004 07:02:06 -0000 1.69
+++ Main.py 2 Mar 2004 06:05:32 -0000 1.70
@@ -131,6 +131,9 @@
"inspect-queue" : ( 'mixminion.ClientMain', 'listQueue' ),
"clean-queue" : ( 'mixminion.ClientMain', 'cleanQueue' ),
"ping" : ( 'mixminion.ClientMain', 'runPing' ),
+ "list-fragments" : ( 'mixminion.ClientMain', 'list-fragments' ),
+ "reassemble" : ( 'mixminion.ClientMain', 'reassemble' ),
+ "purge-fragments" :( 'mixminion.ClientMain', 'reassemble' ),
"server-start" : ( 'mixminion.server.ServerMain', 'runServer' ),
"server-stop" : ( 'mixminion.server.ServerMain', 'signalServer' ),
"server-reload" : ( 'mixminion.server.ServerMain', 'signalServer' ),