from datetime import datetime
from expire import expire as default_expire_func


__all__ = ('BackupSimulator',)


try:
    from collections import OrderedDict    # Python 2.7
except ImportError:
    # Install from: http://pypi.python.org/pypi/ordereddict
    from ordereddict import OrderedDict


class BackupSimulator(object):
    """Helper to simulate making backups, and expire old ones, at
    various points in time.
    """

    def __init__(self, deltas, expire_func=default_expire_func):
        self.deltas = deltas
        self.expire_func = expire_func
        self.now = datetime.now()
        self.backups = OrderedDict()

    def go_to(self, dt):
        self.now = dt

    def go_by(self, td):
        self.now += td

    def backup(self, expire=True):
        self.backups[str(self.now)] = self.now
        if expire:
            return self.expire()

    def expire(self):
        keep = self.expire_func(self.backups, self.deltas)
        deleted = []
        for key in self.backups.keys():
            if not key in keep:
                deleted.append(key)
                del self.backups[key]
        return deleted, keep

@@ -72,16 +72,48 @@
 re_func%0A
+from config import parse_deltas%0A
 %0A%0A__all_
@@ -521,16 +521,101 @@
 _func):%0A
+        if isinstance(deltas, basestring):%0A            deltas = parse_deltas(deltas)%0A
         
@@ -742,24 +742,222 @@
 eredDict()%0A%0A
+    def add(self, backups):%0A        for dt in backups:%0A            if isinstance(dt, basestring):%0A                dt = datetime.strptime(dt, %22%25Y%25m%25d-%25H%25M%25S%22)%0A            self.backups%5Bstr(dt)%5D = dt%0A%0A
     def go_t
@@ -1093,41 +1093,23 @@
 elf.
-backups%5Bstr(self.now)%5D = self.now
+add(%5Bself.now%5D)
 %0A   

Allow using strings for deltas and dates.