summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: be218d5)
raw | patch | inline | side by side (parent: be218d5)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 21 Aug 2002 07:07:27 +0000 (07:07 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 21 Aug 2002 07:07:27 +0000 (07:07 +0000) |
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.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@981 57a73879-2fb5-44c3-a270-3262357dd7e2
- 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.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@981 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/backends/back_anydbm.py | patch | blob | history | |
roundup/date.py | patch | blob | history |
index 27d8ae76274a7b76da22504724d925a5dac46ae5..ffbe3ed496c4c7fd081dfeaff2a419e90ef5b2a6 100644 (file)
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-#$Id: back_anydbm.py,v 1.61 2002-08-19 02:53:27 richard Exp $
+#$Id: back_anydbm.py,v 1.62 2002-08-21 07:07:27 richard 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
if isinstance(prop, Password):
d[k] = str(v)
elif isinstance(prop, Date) and v is not None:
- d[k] = v.get_tuple()
+ d[k] = v.serialise()
elif isinstance(prop, Interval) and v is not None:
- d[k] = v.get_tuple()
+ d[k] = v.serialise()
else:
d[k] = v
return d
def doSaveJournal(self, classname, nodeid, action, params):
# handle supply of the special journalling parameters (usually
# supplied on importing an existing database)
- if params.has_key('creator'):
- journaltag = self.user.get(params['creator'], 'username')
- del params['creator']
+ if isinstance(params, type({})):
+ if params.has_key('creator'):
+ journaltag = self.user.get(params['creator'], 'username')
+ del params['creator']
+ else:
+ journaltag = self.journaltag
+ if params.has_key('created'):
+ journaldate = params['created'].serialise()
+ del params['created']
+ else:
+ journaldate = date.Date().serialise()
+ if params.has_key('activity'):
+ del params['activity']
+
+ # serialise the parameters now
+ if action in ('set', 'create'):
+ params = self.serialise(classname, params)
else:
journaltag = self.journaltag
- if params.has_key('created'):
- journaldate = params['created'].get_tuple()
- del params['created']
- else:
- journaldate = date.Date().get_tuple()
- if params.has_key('activity'):
- del params['activity']
-
- # serialise the parameters now
- if action in ('set', 'create'):
- params = self.serialise(classname, params)
+ journaldate = date.Date().serialise()
# create the journal entry
entry = (nodeid, journaldate, journaltag, action, params)
+ print 'doSaveJournal', entry
if __debug__:
print >>hyperdb.DEBUG, 'doSaveJournal', entry
#
#$Log: not supported by cvs2svn $
+#Revision 1.61 2002/08/19 02:53:27 richard
+#full database export and import is done
+#
#Revision 1.60 2002/08/19 00:23:19 richard
#handle "unset" initial Link values (!)
#
diff --git a/roundup/date.py b/roundup/date.py
index a7f212a553c0ca3c15a9a96db610c37afe49beb6..e180e6c7b9e711d7cc9a4d45a01c66954f0a414e 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: date.py,v 1.23 2002-07-18 23:07:08 richard Exp $
+# $Id: date.py,v 1.24 2002-08-21 07:07:27 richard Exp $
__doc__ = """
Date, time and time interval handling.
<Date 2000-08-14.03:13:00>
>>> Date("14:25", -5)
<Date 2000-06-25.19:25:00>
+
+ The date format 'yyyymmddHHMMSS' (year, month, day, hour,
+ minute, second) is the serialisation format returned by the serialise()
+ method, and is accepted as an argument on instatiation.
'''
def __init__(self, spec='.', offset=0):
"""Construct a date given a specification and a time zone offset.
return str
def set(self, spec, offset=0, date_re=re.compile(r'''
- (((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
- (?P<n>\.)? # .
- (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
- (?P<o>.+)? # offset
- ''', re.VERBOSE)):
+ (((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
+ (?P<n>\.)? # .
+ (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
+ (?P<o>.+)? # offset
+ ''', re.VERBOSE), serialised_re=re.compile('''
+ (?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2}) # yyyymmdd
+ (?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2}) # HHMMSS
+ ''', re.VERBOSE)):
''' set the date to the value in spec
'''
- m = date_re.match(spec)
+ m = serialised_re.match(spec)
if not m:
- raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].[[h]h:mm[:ss]]'
- '[offset]')
+ m = date_re.match(spec)
+ if not m:
+ raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].'
+ '[[h]h:mm[:ss]][offset]')
+
info = m.groupdict()
# get the current date/time using the offset
self.year, self.month, self.day, self.hour, self.minute, \
self.second, x, x, x = time.gmtime(ts)
- if info['o']:
+ if info.get('o', None):
self.applyInterval(Interval(info['o']))
def __repr__(self):
return (self.year, self.month, self.day, self.hour, self.minute,
self.second, 0, 0, 0)
+ def serialise(self):
+ return '%4d%02d%02d%02d%02d%02d'%(self.year, self.month,
+ self.day, self.hour, self.minute, self.second)
+
class Interval:
'''
Date intervals are specified using the suffixes "y", "m", and "d". The
days (or over/underflow from hours/mins/secs) will do that, and
days-per-month and leap years are accounted for. Leap seconds are not.
+ The interval format 'syyyymmddHHMMSS' (sign, year, month, day, hour,
+ minute, second) is the serialisation format returned by the serialise()
+ method, and is accepted as an argument on instatiation.
+
TODO: more examples, showing the order of addition operation
'''
def __init__(self, spec, sign=1):
r = cmp(getattr(self, attr), getattr(other, attr))
if r: return r
return 0
-
+
def __str__(self):
"""Return this interval as a string."""
sign = {1:'+', -1:'-'}[self.sign]
l.append('%d:%02d'%(self.hour, self.minute))
return ' '.join(l)
- def set(self, spec, interval_re = re.compile('''
- \s*
- (?P<s>[-+])? # + or -
- \s*
- ((?P<y>\d+\s*)y)? # year
- \s*
- ((?P<m>\d+\s*)m)? # month
- \s*
- ((?P<w>\d+\s*)w)? # week
- \s*
- ((?P<d>\d+\s*)d)? # day
- \s*
- (((?P<H>\d+):(?P<M>\d+))?(:(?P<S>\d+))?)? # time
- \s*
- ''', re.VERBOSE)):
+ def set(self, spec, interval_re=re.compile('''
+ \s*(?P<s>[-+])? # + or -
+ \s*((?P<y>\d+\s*)y)? # year
+ \s*((?P<m>\d+\s*)m)? # month
+ \s*((?P<w>\d+\s*)w)? # week
+ \s*((?P<d>\d+\s*)d)? # day
+ \s*(((?P<H>\d+):(?P<M>\d+))?(:(?P<S>\d+))?)? # time
+ \s*''', re.VERBOSE), serialised_re=re.compile('''
+ (?P<s>[+-])(?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2})
+ (?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2})''', re.VERBOSE)):
''' set the date to the value in spec
'''
self.year = self.month = self.week = self.day = self.hour = \
self.minute = self.second = 0
self.sign = 1
- m = interval_re.match(spec)
+ m = serialised_re.match(spec)
if not m:
- raise ValueError, _('Not an interval spec: [+-] [#y] [#m] [#w] '
- '[#d] [[[H]H:MM]:SS]')
+ m = interval_re.match(spec)
+ if not m:
+ raise ValueError, _('Not an interval spec: [+-] [#y] [#m] [#w] '
+ '[#d] [[[H]H:MM]:SS]')
info = m.groupdict()
for group, attr in {'y':'year', 'm':'month', 'w':'week', 'd':'day',
'H':'hour', 'M':'minute', 'S':'second'}.items():
- if info[group] is not None:
+ if info.getr(group, None) is not None:
setattr(self, attr, int(info[group]))
if self.week:
return s
def get_tuple(self):
- return (self.year, self.month, self.day, self.hour, self.minute,
- self.second)
+ return (self.sign, self.year, self.month, self.day, self.hour,
+ self.minute, self.second)
+
+ def serialise(self):
+ return '%s%4d%02d%02d%02d%02d%02d'%(self.sign, self.year, self.month,
+ self.day, self.hour, self.minute, self.second)
def test():
#
# $Log: not supported by cvs2svn $
+# Revision 1.23 2002/07/18 23:07:08 richard
+# Unit tests and a few fixes.
+#
# Revision 1.22 2002/07/14 06:05:50 richard
# . fixed the date module so that Date(". - 2d") works
#