Skip to content

Commit 2006eec

Browse files
author
Richard Jones
committed
Preparing to turn back on link/unlink journal events.
By default these are turned off. I've: - fixed back_anydbm so it can journal those events again (had broken it with recent changes) - changed the serialisation format for dates and intervals to use a numbers-only (and sign for Intervals) string instead of tuple-of-ints. Much smaller.
1 parent 57c4c8f commit 2006eec

File tree

2 files changed

+79
-49
lines changed

2 files changed

+79
-49
lines changed

roundup/backends/back_anydbm.py

Lines changed: 25 additions & 17 deletions
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.61 2002-08-19 02:53:27 richard Exp $
18+
#$Id: back_anydbm.py,v 1.62 2002-08-21 07:07:27 richard 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
@@ -342,9 +342,9 @@ def serialise(self, classname, node):
342342
if isinstance(prop, Password):
343343
d[k] = str(v)
344344
elif isinstance(prop, Date) and v is not None:
345-
d[k] = v.get_tuple()
345+
d[k] = v.serialise()
346346
elif isinstance(prop, Interval) and v is not None:
347-
d[k] = v.get_tuple()
347+
d[k] = v.serialise()
348348
else:
349349
d[k] = v
350350
return d
@@ -605,25 +605,30 @@ def getCachedJournalDB(self, classname):
605605
def doSaveJournal(self, classname, nodeid, action, params):
606606
# handle supply of the special journalling parameters (usually
607607
# supplied on importing an existing database)
608-
if params.has_key('creator'):
609-
journaltag = self.user.get(params['creator'], 'username')
610-
del params['creator']
608+
if isinstance(params, type({})):
609+
if params.has_key('creator'):
610+
journaltag = self.user.get(params['creator'], 'username')
611+
del params['creator']
612+
else:
613+
journaltag = self.journaltag
614+
if params.has_key('created'):
615+
journaldate = params['created'].serialise()
616+
del params['created']
617+
else:
618+
journaldate = date.Date().serialise()
619+
if params.has_key('activity'):
620+
del params['activity']
621+
622+
# serialise the parameters now
623+
if action in ('set', 'create'):
624+
params = self.serialise(classname, params)
611625
else:
612626
journaltag = self.journaltag
613-
if params.has_key('created'):
614-
journaldate = params['created'].get_tuple()
615-
del params['created']
616-
else:
617-
journaldate = date.Date().get_tuple()
618-
if params.has_key('activity'):
619-
del params['activity']
620-
621-
# serialise the parameters now
622-
if action in ('set', 'create'):
623-
params = self.serialise(classname, params)
627+
journaldate = date.Date().serialise()
624628

625629
# create the journal entry
626630
entry = (nodeid, journaldate, journaltag, action, params)
631+
print 'doSaveJournal', entry
627632

628633
if __debug__:
629634
print >>hyperdb.DEBUG, 'doSaveJournal', entry
@@ -1907,6 +1912,9 @@ def __init__(self, db, classname, **properties):
19071912

19081913
#
19091914
#$Log: not supported by cvs2svn $
1915+
#Revision 1.61 2002/08/19 02:53:27 richard
1916+
#full database export and import is done
1917+
#
19101918
#Revision 1.60 2002/08/19 00:23:19 richard
19111919
#handle "unset" initial Link values (!)
19121920
#

roundup/date.py

Lines changed: 54 additions & 32 deletions
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: date.py,v 1.23 2002-07-18 23:07:08 richard Exp $
18+
# $Id: date.py,v 1.24 2002-08-21 07:07:27 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -75,6 +75,10 @@ class Date:
7575
<Date 2000-08-14.03:13:00>
7676
>>> Date("14:25", -5)
7777
<Date 2000-06-25.19:25:00>
78+
79+
The date format 'yyyymmddHHMMSS' (year, month, day, hour,
80+
minute, second) is the serialisation format returned by the serialise()
81+
method, and is accepted as an argument on instatiation.
7882
'''
7983
def __init__(self, spec='.', offset=0):
8084
"""Construct a date given a specification and a time zone offset.
@@ -210,17 +214,23 @@ def pretty(self):
210214
return str
211215

212216
def set(self, spec, offset=0, date_re=re.compile(r'''
213-
(((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
214-
(?P<n>\.)? # .
215-
(((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
216-
(?P<o>.+)? # offset
217-
''', re.VERBOSE)):
217+
(((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
218+
(?P<n>\.)? # .
219+
(((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
220+
(?P<o>.+)? # offset
221+
''', re.VERBOSE), serialised_re=re.compile('''
222+
(?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2}) # yyyymmdd
223+
(?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2}) # HHMMSS
224+
''', re.VERBOSE)):
218225
''' set the date to the value in spec
219226
'''
220-
m = date_re.match(spec)
227+
m = serialised_re.match(spec)
221228
if not m:
222-
raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].[[h]h:mm[:ss]]'
223-
'[offset]')
229+
m = date_re.match(spec)
230+
if not m:
231+
raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].'
232+
'[[h]h:mm[:ss]][offset]')
233+
224234
info = m.groupdict()
225235

226236
# get the current date/time using the offset
@@ -245,7 +255,7 @@ def set(self, spec, offset=0, date_re=re.compile(r'''
245255
self.year, self.month, self.day, self.hour, self.minute, \
246256
self.second, x, x, x = time.gmtime(ts)
247257

248-
if info['o']:
258+
if info.get('o', None):
249259
self.applyInterval(Interval(info['o']))
250260

251261
def __repr__(self):
@@ -262,6 +272,10 @@ def get_tuple(self):
262272
return (self.year, self.month, self.day, self.hour, self.minute,
263273
self.second, 0, 0, 0)
264274

275+
def serialise(self):
276+
return '%4d%02d%02d%02d%02d%02d'%(self.year, self.month,
277+
self.day, self.hour, self.minute, self.second)
278+
265279
class Interval:
266280
'''
267281
Date intervals are specified using the suffixes "y", "m", and "d". The
@@ -290,6 +304,10 @@ class Interval:
290304
days (or over/underflow from hours/mins/secs) will do that, and
291305
days-per-month and leap years are accounted for. Leap seconds are not.
292306
307+
The interval format 'syyyymmddHHMMSS' (sign, year, month, day, hour,
308+
minute, second) is the serialisation format returned by the serialise()
309+
method, and is accepted as an argument on instatiation.
310+
293311
TODO: more examples, showing the order of addition operation
294312
'''
295313
def __init__(self, spec, sign=1):
@@ -311,7 +329,7 @@ def __cmp__(self, other):
311329
r = cmp(getattr(self, attr), getattr(other, attr))
312330
if r: return r
313331
return 0
314-
332+
315333
def __str__(self):
316334
"""Return this interval as a string."""
317335
sign = {1:'+', -1:'-'}[self.sign]
@@ -325,35 +343,32 @@ def __str__(self):
325343
l.append('%d:%02d'%(self.hour, self.minute))
326344
return ' '.join(l)
327345

328-
def set(self, spec, interval_re = re.compile('''
329-
\s*
330-
(?P<s>[-+])? # + or -
331-
\s*
332-
((?P<y>\d+\s*)y)? # year
333-
\s*
334-
((?P<m>\d+\s*)m)? # month
335-
\s*
336-
((?P<w>\d+\s*)w)? # week
337-
\s*
338-
((?P<d>\d+\s*)d)? # day
339-
\s*
340-
(((?P<H>\d+):(?P<M>\d+))?(:(?P<S>\d+))?)? # time
341-
\s*
342-
''', re.VERBOSE)):
346+
def set(self, spec, interval_re=re.compile('''
347+
\s*(?P<s>[-+])? # + or -
348+
\s*((?P<y>\d+\s*)y)? # year
349+
\s*((?P<m>\d+\s*)m)? # month
350+
\s*((?P<w>\d+\s*)w)? # week
351+
\s*((?P<d>\d+\s*)d)? # day
352+
\s*(((?P<H>\d+):(?P<M>\d+))?(:(?P<S>\d+))?)? # time
353+
\s*''', re.VERBOSE), serialised_re=re.compile('''
354+
(?P<s>[+-])(?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2})
355+
(?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2})''', re.VERBOSE)):
343356
''' set the date to the value in spec
344357
'''
345358
self.year = self.month = self.week = self.day = self.hour = \
346359
self.minute = self.second = 0
347360
self.sign = 1
348-
m = interval_re.match(spec)
361+
m = serialised_re.match(spec)
349362
if not m:
350-
raise ValueError, _('Not an interval spec: [+-] [#y] [#m] [#w] '
351-
'[#d] [[[H]H:MM]:SS]')
363+
m = interval_re.match(spec)
364+
if not m:
365+
raise ValueError, _('Not an interval spec: [+-] [#y] [#m] [#w] '
366+
'[#d] [[[H]H:MM]:SS]')
352367

353368
info = m.groupdict()
354369
for group, attr in {'y':'year', 'm':'month', 'w':'week', 'd':'day',
355370
'H':'hour', 'M':'minute', 'S':'second'}.items():
356-
if info[group] is not None:
371+
if info.getr(group, None) is not None:
357372
setattr(self, attr, int(info[group]))
358373

359374
if self.week:
@@ -416,8 +431,12 @@ def pretty(self):
416431
return s
417432

418433
def get_tuple(self):
419-
return (self.year, self.month, self.day, self.hour, self.minute,
420-
self.second)
434+
return (self.sign, self.year, self.month, self.day, self.hour,
435+
self.minute, self.second)
436+
437+
def serialise(self):
438+
return '%s%4d%02d%02d%02d%02d%02d'%(self.sign, self.year, self.month,
439+
self.day, self.hour, self.minute, self.second)
421440

422441

423442
def test():
@@ -442,6 +461,9 @@ def test():
442461

443462
#
444463
# $Log: not supported by cvs2svn $
464+
# Revision 1.23 2002/07/18 23:07:08 richard
465+
# Unit tests and a few fixes.
466+
#
445467
# Revision 1.22 2002/07/14 06:05:50 richard
446468
# . fixed the date module so that Date(". - 2d") works
447469
#

0 commit comments

Comments
 (0)