Skip to content

Commit 3932ea2

Browse files
author
Roche Compaan
committed
You can now use the roundup-admin tool to pack the database
1 parent 6b18aff commit 3932ea2

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Feature:
1111
for arguments are specified for link or mutlilink properties.
1212
. modified unit test to check nosy and assignedto when specified as
1313
arguments
14+
. you can now use the roundup-admin tool pack the database
1415

1516
Fixed:
1617
. handle attachments with no name (eg tnef)

roundup/admin.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.4 2002-01-14 06:51:09 richard Exp $
19+
# $Id: admin.py,v 1.5 2002-01-21 16:33:19 rochecompaan Exp $
2020

2121
import sys, os, getpass, getopt, re, UserDict, shlex
2222
try:
@@ -857,6 +857,46 @@ def do_import(self, args):
857857
apply(cl.create, (), d)
858858
return 0
859859

860+
def do_pack(self, args):
861+
'''Usage: pack period | date
862+
863+
Remove journal entries older than a period of time specified or
864+
before a certain date.
865+
866+
A period is specified using the suffixes "y", "m", and "d". The
867+
suffix "w" (for "week") means 7 days.
868+
869+
"3y" means three years
870+
"2y 1m" means two years and one month
871+
"1m 25d" means one month and 25 days
872+
"2w 3d" means two weeks and three days
873+
874+
Date format is "YYYY-MM-DD" eg:
875+
2001-01-01
876+
877+
'''
878+
if len(args) <> 1:
879+
raise UsageError, _('Not enough arguments supplied')
880+
881+
# are we dealing with a period or a date
882+
value = args[0]
883+
date_re = re.compile(r'''
884+
(?P<date>\d\d\d\d-\d\d?-\d\d?)? # yyyy-mm-dd
885+
(?P<period>(\d+y\s*)?(\d+m\s*)?(\d+d\s*)?)?
886+
''', re.VERBOSE)
887+
m = date_re.match(value)
888+
if not m:
889+
raise ValueError, _('Invalid format')
890+
m = m.groupdict()
891+
if m['period']:
892+
# TODO: need to fix date module. one should be able to say
893+
# pack_before = date.Date(". - %s"%value)
894+
pack_before = date.Date(".") + date.Interval("- %s"%value)
895+
elif m['date']:
896+
pack_before = date.Date(value)
897+
self.db.pack(pack_before)
898+
return 0
899+
860900
def run_command(self, args):
861901
'''Run a single command
862902
'''
@@ -995,6 +1035,9 @@ def main(self):
9951035

9961036
#
9971037
# $Log: not supported by cvs2svn $
1038+
# Revision 1.4 2002/01/14 06:51:09 richard
1039+
# . #503164 ] create and passwords
1040+
#
9981041
# Revision 1.3 2002/01/08 05:26:32 rochecompaan
9991042
# Missing "self" in props_from_args
10001043
#

roundup/backends/back_anydbm.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.23 2002-01-18 04:32:04 richard Exp $
18+
#$Id: back_anydbm.py,v 1.24 2002-01-21 16:33:20 rochecompaan Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -320,6 +320,43 @@ def getjournal(self, classname, nodeid):
320320
res.append((nodeid, date_obj, self.journaltag, action, params))
321321
return res
322322

323+
def pack(self, pack_before):
324+
''' delete all journal entries before 'pack_before' '''
325+
if DEBUG:
326+
print 'packjournal', (self, pack_before)
327+
328+
pack_before = pack_before.get_tuple()
329+
330+
classes = self.getclasses()
331+
332+
# TODO: factor this out to method - we're already doing it in
333+
# _opendb.
334+
db_type = ''
335+
path = os.path.join(os.getcwd(), self.dir, classes[0])
336+
if os.path.exists(path):
337+
db_type = whichdb.whichdb(path)
338+
if not db_type:
339+
raise hyperdb.DatabaseError, "Couldn't identify database type"
340+
elif os.path.exists(path+'.db'):
341+
db_type = 'dbm'
342+
343+
for classname in classes:
344+
db_name = 'journals.%s'%classname
345+
db = self._opendb(db_name, 'w')
346+
347+
for key in db.keys():
348+
journal = marshal.loads(db[key])
349+
l = []
350+
for entry in journal:
351+
(nodeid, date_stamp, self.journaltag, action,
352+
params) = entry
353+
if date_stamp > pack_before or action == 'create':
354+
l.append(entry)
355+
db[key] = marshal.dumps(l)
356+
if db_type == 'gdbm':
357+
db.reorganize()
358+
db.close()
359+
323360

324361
#
325362
# Basic transaction support
@@ -407,6 +444,10 @@ def rollback(self):
407444

408445
#
409446
#$Log: not supported by cvs2svn $
447+
#Revision 1.23 2002/01/18 04:32:04 richard
448+
#Rollback was breaking because a message hadn't actually been written to the file. Needs
449+
#more investigation.
450+
#
410451
#Revision 1.22 2002/01/14 02:20:15 richard
411452
# . changed all config accesses so they access either the instance or the
412453
# config attriubute on the db. This means that all config is obtained from

roundup/hyperdb.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.51 2002-01-21 03:01:29 richard Exp $
18+
# $Id: hyperdb.py,v 1.52 2002-01-21 16:33:19 rochecompaan Exp $
1919

2020
__doc__ = """
2121
Hyperdatabase implementation, especially field types.
@@ -211,6 +211,11 @@ def getjournal(self, classname, nodeid):
211211
'''
212212
raise NotImplementedError
213213

214+
def pack(self, pack_before):
215+
''' pack the database
216+
'''
217+
raise NotImplementedError
218+
214219
def commit(self):
215220
''' Commit the current transactions.
216221
@@ -1060,6 +1065,9 @@ def Choice(name, *options):
10601065

10611066
#
10621067
# $Log: not supported by cvs2svn $
1068+
# Revision 1.51 2002/01/21 03:01:29 richard
1069+
# brief docco on the do_journal argument
1070+
#
10631071
# Revision 1.50 2002/01/19 13:16:04 rochecompaan
10641072
# Journal entries for link and multilink properties can now be switched on
10651073
# or off.

test/test_db.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.15 2002-01-19 13:16:04 rochecompaan Exp $
18+
# $Id: test_db.py,v 1.16 2002-01-21 16:33:20 rochecompaan Exp $
1919

2020
import unittest, os, shutil
2121

@@ -239,6 +239,16 @@ def testJournals(self):
239239
self.assertEqual('unlink', action)
240240
self.assertEqual(('issue', '1', 'fixer'), params)
241241

242+
def testPack(self):
243+
self.db.issue.create(title="spam", status='1')
244+
self.db.issue.set('1', status='2')
245+
self.db.commit()
246+
247+
pack_before = date.Date(". + 1d")
248+
self.db.pack(pack_before)
249+
journal = self.db.getjournal('issue', '1')
250+
self.assertEqual(1, len(journal))
251+
242252
def testRetire(self):
243253
pass
244254

@@ -334,6 +344,10 @@ def suite():
334344

335345
#
336346
# $Log: not supported by cvs2svn $
347+
# Revision 1.15 2002/01/19 13:16:04 rochecompaan
348+
# Journal entries for link and multilink properties can now be switched on
349+
# or off.
350+
#
337351
# Revision 1.14 2002/01/16 07:02:57 richard
338352
# . lots of date/interval related changes:
339353
# - more relaxed date format for input

0 commit comments

Comments
 (0)