Code

. roundup db: catch only IOError in getfile.
[roundup.git] / roundup / admin.py
index 34ec404e672527ce05817fbc137fdeceb4ad1b43..c2c8840e4cde7b1b39c00cccbd7cb5b38ee5bf58 100644 (file)
@@ -16,7 +16,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: admin.py,v 1.4 2002-01-14 06:51:09 richard Exp $
+# $Id: admin.py,v 1.7 2002-02-20 05:04:32 richard Exp $
 
 import sys, os, getpass, getopt, re, UserDict, shlex
 try:
@@ -209,7 +209,11 @@ Command help:
         initopts  -- init command options
         all       -- all available help
         '''
-        topic = args[0]
+        if len(args)>0:
+            topic = args[0]
+        else:
+            topic = 'help'
 
         # try help_ methods
         if self.help.has_key(topic):
@@ -832,6 +836,9 @@ Command help:
             while 1:
                 l = p.parse(line)
                 if l: break
+                line = f.readline()
+                if not line:
+                    raise ValueError, "Unexpected EOF during CSV parse"
 
             # make the new node's property map
             d = {}
@@ -857,6 +864,46 @@ Command help:
             apply(cl.create, (), d)
         return 0
 
+    def do_pack(self, args):
+        '''Usage: pack period | date
+
+Remove journal entries older than a period of time specified or
+before a certain date.
+
+A period is specified using the suffixes "y", "m", and "d". The
+suffix "w" (for "week") means 7 days.
+
+      "3y" means three years
+      "2y 1m" means two years and one month
+      "1m 25d" means one month and 25 days
+      "2w 3d" means two weeks and three days
+
+Date format is "YYYY-MM-DD" eg:
+    2001-01-01
+    
+        '''
+        if len(args) <> 1:
+            raise UsageError, _('Not enough arguments supplied')
+        
+        # are we dealing with a period or a date
+        value = args[0]
+        date_re = re.compile(r'''
+              (?P<date>\d\d\d\d-\d\d?-\d\d?)? # yyyy-mm-dd
+              (?P<period>(\d+y\s*)?(\d+m\s*)?(\d+d\s*)?)?
+              ''', re.VERBOSE)
+        m = date_re.match(value)
+        if not m:
+            raise ValueError, _('Invalid format')
+        m = m.groupdict()
+        if m['period']:
+            # TODO: need to fix date module.  one should be able to say
+            # pack_before = date.Date(". - %s"%value)
+            pack_before = date.Date(".") + date.Interval("- %s"%value)
+        elif m['date']:
+            pack_before = date.Date(value)
+        self.db.pack(pack_before)
+        return 0
+
     def run_command(self, args):
         '''Run a single command
         '''
@@ -995,6 +1042,15 @@ if __name__ == '__main__':
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.6  2002/01/23 07:27:19  grubert
+#  . allow abbreviation of "help" in admin tool too.
+#
+# Revision 1.5  2002/01/21 16:33:19  rochecompaan
+# You can now use the roundup-admin tool to pack the database
+#
+# Revision 1.4  2002/01/14 06:51:09  richard
+#  . #503164 ] create and passwords
+#
 # Revision 1.3  2002/01/08 05:26:32  rochecompaan
 # Missing "self" in props_from_args
 #