示例#1
0
 def test_remove_all(self):
     files = []
     new_date = timestamp_before(weeks=1)
     for n in range(10):
         fname = 'foo'+str(n)
         filename = self.mkfile(fname)
         os.utime(filename, (new_date, new_date))
         files.append(filename)
     
     for filename in files:
         assert os.path.exists(filename), filename
     cleanup_directory(self.tmpdir, timestamp_before())
     for filename in files:
         assert not os.path.exists(filename), filename
         assert not os.path.exists(os.path.dirname(filename)), filename
示例#2
0
    def test_remove_all(self):
        files = []
        new_date = timestamp_before(weeks=1)
        for n in range(10):
            fname = 'foo' + str(n)
            filename = self.mkfile(fname)
            os.utime(filename, (new_date, new_date))
            files.append(filename)

        for filename in files:
            assert os.path.exists(filename), filename
        cleanup_directory(self.tmpdir, timestamp_before())
        for filename in files:
            assert not os.path.exists(filename), filename
            assert not os.path.exists(os.path.dirname(filename)), filename
示例#3
0
 def test_no_remove(self):
     dirs = [self.mkdir('dir' + str(n)) for n in range(10)]
     for d in dirs:
         assert os.path.exists(d), d
     cleanup_directory(self.tmpdir, timestamp_before(minutes=1))
     for d in dirs:
         assert os.path.exists(d), d
示例#4
0
 def test_no_remove(self):
     dirs = [self.mkdir('dir'+str(n)) for n in range(10)]
     for d in dirs:
         assert os.path.exists(d), d
     cleanup_directory(self.tmpdir, timestamp_before(minutes=1))
     for d in dirs:
         assert os.path.exists(d), d
示例#5
0
 def test_file_handler(self):
     files = []
     file_handler_calls = []
     def file_handler(filename):
         file_handler_calls.append(filename)
     new_date = timestamp_before(weeks=1)
     for n in range(10):
         fname = 'foo'+str(n)
         filename = self.mkfile(fname)
         os.utime(filename, (new_date, new_date))
         files.append(filename)
     
     for filename in files:
         assert os.path.exists(filename), filename
     cleanup_directory(self.tmpdir, timestamp_before(), file_handler=file_handler)
     for filename in files:
         assert os.path.exists(filename), filename
     
     assert set(files) == set(file_handler_calls)
示例#6
0
    def test_file_handler(self):
        files = []
        file_handler_calls = []

        def file_handler(filename):
            file_handler_calls.append(filename)

        new_date = timestamp_before(weeks=1)
        for n in range(10):
            fname = 'foo' + str(n)
            filename = self.mkfile(fname)
            os.utime(filename, (new_date, new_date))
            files.append(filename)

        for filename in files:
            assert os.path.exists(filename), filename
        cleanup_directory(self.tmpdir,
                          timestamp_before(),
                          file_handler=file_handler)
        for filename in files:
            assert os.path.exists(filename), filename

        assert set(files) == set(file_handler_calls)
示例#7
0
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" % (conf["time"], ))
    deltas = {}
    for delta_type in ('weeks', 'days', 'hours', 'minutes'):
        deltas[delta_type] = conf.get(delta_type, 0)
    return timestamp_before(**deltas)
示例#8
0
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" %
                (conf["time"], ))
    deltas = {}
    for delta_type in ('weeks', 'days', 'hours', 'minutes'):
        deltas[delta_type] = conf.get(delta_type, 0)
    return timestamp_before(**deltas)
示例#9
0
 def test_remove_empty_dirs(self):
     os.makedirs(os.path.join(self.tmpdir, 'foo', 'bar', 'baz'))
     cleanup_directory(self.tmpdir, timestamp_before(minutes=-1))
     assert not os.path.exists(os.path.join(self.tmpdir, 'foo'))
示例#10
0
 def test_no_directory(self):
     cleanup_directory(os.path.join(self.tmpdir, 'invalid'),
                       timestamp_before())
示例#11
0
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" % (conf["time"], ))
    if 'mtime' in conf:
        datasource = abspath(conf['mtime'])
        try:
            return os.path.getmtime(datasource)
        except OSError, ex:
            raise SeedConfigurationError(
                "can't parse last modified time from file '%s'." % (datasource, ), ex)
    deltas = {}
    for delta_type in ('weeks', 'days', 'hours', 'minutes'):
        deltas[delta_type] = conf.get(delta_type, 0)
    return timestamp_before(**deltas)


class LevelsList(object):
    def __init__(self, levels=None):
        self.levels = levels

    def for_grid(self, grid):
        uniqe_valid_levels = set(l for l in self.levels if 0 <= l <= (grid.levels-1))
        return sorted(uniqe_valid_levels)

class LevelsRange(object):
    def __init__(self, level_range=None):
        self.level_range = level_range

    def for_grid(self, grid):
示例#12
0
 def test_remove_empty_dirs(self):
     os.makedirs(os.path.join(self.tmpdir, 'foo', 'bar', 'baz'))
     cleanup_directory(self.tmpdir, timestamp_before(minutes=-1))
     assert not os.path.exists(os.path.join(self.tmpdir, 'foo'))
示例#13
0
 def test_no_directory(self):
     cleanup_directory(os.path.join(self.tmpdir, 'invalid'), timestamp_before())