[mhonarc] parse command line



commit b6d04075f96e69806d52e93fefaeba8ab7ba2e05
Author: Olav Vitters <olav vitters nl>
Date:   Mon Feb 11 22:26:19 2013 +0100

    parse command line

 archive.py |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/archive.py b/archive.py
index b26febf..207f106 100755
--- a/archive.py
+++ b/archive.py
@@ -3,12 +3,11 @@
 import os
 import os.path
 import sys
+import gzip
+import argparse
 
 
-print >>sys.stderr, "INCOMPLETE"
-sys.exit(1)
-
-class Archiver
+class Archiver:
     PUBLIC_ARCHIVE_DIR = "/var/lib/mailman/archives/public"
     PUBLIC_RCFILE = "/home/admin/mhonarc/public-rc/base.rc"
     PRIVATE_ARCHIVE_DIR = "/var/lib/mailman/archives/private"
@@ -38,13 +37,15 @@ class Archiver
         rcfile = self.PRIVATE_RCFILE if self.private else self.PUBLIC_RCFILE
 
 #        system (<<EOT);
-#        mhonarc -umask 022 -rcfile $rcfile -add -outdir $dir $tmpname -definevar "ARCHDATE=$self->{olddir} LISTNAME=$self->{listname}" >> /var/log/mailman/archive 2>&1Â
+#        mhonarc -umask 022 -rcfile $rcfile -add -outdir $dir $tmpname -definevar "ARCHDATE=$self->{olddir} LISTNAME=$self->{listname}" >> /var/log/mailman/archive 2>&1
 #        EOT
 
         if os.path.exists("%s.txt" % path):
-            #system ("cat < $tmpname >> $dir.txt");
+            fp = open("%s.txt" % path, 'ab')
         else:
-            #system ("gzip -c < $tmpname >> $dir.txt.gz");
+            fp = gzip.GzipFile("%s.txt.gz" % path, 'ab')
+        fp.write(open(tmpname, 'rb').read())
+        fp.close()
 
         if last:
             os.remove(self.tmpname)
@@ -55,6 +56,7 @@ class Archiver
 
         else:
             # XXX - reopen tmpname
+            pass
 
 
     def handle_message(self, msg):
@@ -83,14 +85,27 @@ class Archiver
             self.last_parseable_time = received_time_text
 
 
+def main():
+    description = """Archive email using mhonarc from individual files or an Unix mbox."""
+    epilog="""Report bugs to https://bugzilla.gnome.org/enter_bug.cgi?product=sysadmin""";
+    parser = argparse.ArgumentParser(description=description,epilog=epilog)
+    parser.add_argument('--debug',   action='store_true')
+    parser.add_argument('--private', action='store_true')
+    parser.add_argument('--listname')
 
+    group = parser.add_mutually_exclusive_group()
+    group.add_argument('--makeindex', action='store_true')
+    group.add_argument('infile', nargs='?', type=argparse.FileType('r'),
+                       default=sys.stdin)
 
 
 
 
+    options = parser.parse_args()
 
 
-
-
-
+if __name__ == "__main__":
+    main()
+    print >>sys.stderr, "INCOMPLETE"
+    sys.exit(1)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]