From: rochecompaan Date: Mon, 21 Jan 2002 16:33:20 +0000 (+0000) Subject: You can now use the roundup-admin tool to pack the database X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1a977aa6d6559983cb68418af5505462d05ed11b;p=roundup.git You can now use the roundup-admin tool to pack the database git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@574 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 67d1cad..10091cf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,6 +11,7 @@ Feature: for arguments are specified for link or mutlilink properties. . modified unit test to check nosy and assignedto when specified as arguments + . you can now use the roundup-admin tool pack the database Fixed: . handle attachments with no name (eg tnef) diff --git a/roundup/admin.py b/roundup/admin.py index 34ec404..679315c 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -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.5 2002-01-21 16:33:19 rochecompaan Exp $ import sys, os, getpass, getopt, re, UserDict, shlex try: @@ -857,6 +857,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\d\d\d\d-\d\d?-\d\d?)? # yyyy-mm-dd + (?P(\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 +1035,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# 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 # diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 6b5bb2e..bfdc142 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.23 2002-01-18 04:32:04 richard Exp $ +#$Id: back_anydbm.py,v 1.24 2002-01-21 16:33:20 rochecompaan Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -320,6 +320,43 @@ class Database(hyperdb.Database): res.append((nodeid, date_obj, self.journaltag, action, params)) return res + def pack(self, pack_before): + ''' delete all journal entries before 'pack_before' ''' + if DEBUG: + print 'packjournal', (self, pack_before) + + pack_before = pack_before.get_tuple() + + classes = self.getclasses() + + # TODO: factor this out to method - we're already doing it in + # _opendb. + db_type = '' + path = os.path.join(os.getcwd(), self.dir, classes[0]) + if os.path.exists(path): + db_type = whichdb.whichdb(path) + if not db_type: + raise hyperdb.DatabaseError, "Couldn't identify database type" + elif os.path.exists(path+'.db'): + db_type = 'dbm' + + for classname in classes: + db_name = 'journals.%s'%classname + db = self._opendb(db_name, 'w') + + for key in db.keys(): + journal = marshal.loads(db[key]) + l = [] + for entry in journal: + (nodeid, date_stamp, self.journaltag, action, + params) = entry + if date_stamp > pack_before or action == 'create': + l.append(entry) + db[key] = marshal.dumps(l) + if db_type == 'gdbm': + db.reorganize() + db.close() + # # Basic transaction support @@ -407,6 +444,10 @@ class Database(hyperdb.Database): # #$Log: not supported by cvs2svn $ +#Revision 1.23 2002/01/18 04:32:04 richard +#Rollback was breaking because a message hadn't actually been written to the file. Needs +#more investigation. +# #Revision 1.22 2002/01/14 02:20:15 richard # . changed all config accesses so they access either the instance or the # config attriubute on the db. This means that all config is obtained from diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index 9a2406a..8a12af1 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: hyperdb.py,v 1.51 2002-01-21 03:01:29 richard Exp $ +# $Id: hyperdb.py,v 1.52 2002-01-21 16:33:19 rochecompaan Exp $ __doc__ = """ Hyperdatabase implementation, especially field types. @@ -211,6 +211,11 @@ transaction. ''' raise NotImplementedError + def pack(self, pack_before): + ''' pack the database + ''' + raise NotImplementedError + def commit(self): ''' Commit the current transactions. @@ -1060,6 +1065,9 @@ def Choice(name, *options): # # $Log: not supported by cvs2svn $ +# Revision 1.51 2002/01/21 03:01:29 richard +# brief docco on the do_journal argument +# # Revision 1.50 2002/01/19 13:16:04 rochecompaan # Journal entries for link and multilink properties can now be switched on # or off. diff --git a/test/test_db.py b/test/test_db.py index 9632d36..1412b73 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_db.py,v 1.15 2002-01-19 13:16:04 rochecompaan Exp $ +# $Id: test_db.py,v 1.16 2002-01-21 16:33:20 rochecompaan Exp $ import unittest, os, shutil @@ -239,6 +239,16 @@ class anydbmDBTestCase(MyTestCase): self.assertEqual('unlink', action) self.assertEqual(('issue', '1', 'fixer'), params) + def testPack(self): + self.db.issue.create(title="spam", status='1') + self.db.issue.set('1', status='2') + self.db.commit() + + pack_before = date.Date(". + 1d") + self.db.pack(pack_before) + journal = self.db.getjournal('issue', '1') + self.assertEqual(1, len(journal)) + def testRetire(self): pass @@ -334,6 +344,10 @@ def suite(): # # $Log: not supported by cvs2svn $ +# Revision 1.15 2002/01/19 13:16:04 rochecompaan +# Journal entries for link and multilink properties can now be switched on +# or off. +# # Revision 1.14 2002/01/16 07:02:57 richard # . lots of date/interval related changes: # - more relaxed date format for input