Selaa lähdekoodia

Added "--hourly" option to "purge" subcommand

Jonas Borgström 13 vuotta sitten
vanhempi
sitoutus
3a00547f28
2 muutettua tiedostoa jossa 20 lisäystä ja 3 poistoa
  1. 7 3
      darc/archiver.py
  2. 13 0
      darc/test.py

+ 7 - 3
darc/archiver.py

@@ -235,15 +235,17 @@ class Archiver(object):
         cache = Cache(store, key)
         archives = list(sorted(Archive.list_archives(store, key, cache),
                                key=attrgetter('ts'), reverse=True))
-        if args.daily + args.weekly + args.monthly + args.yearly == 0:
-            self.print_error('At least one of the "daily", "weekly", "monthly" or "yearly" '
+        if args.hourly + args.daily + args.weekly + args.monthly + args.yearly == 0:
+            self.print_error('At least one of the "hourly", "daily", "weekly", "monthly" or "yearly" '
                              'settings must be specified')
             return 1
         if args.prefix:
             archives = [archive for archive in archives if archive.name.startswith(args.prefix)]
         keep = []
+        if args.hourly:
+            keep += purge_split(archives, '%Y-%m-%d %H', args.hourly)
         if args.daily:
-            keep += purge_split(archives, '%Y-%m-%d', args.daily)
+            keep += purge_split(archives, '%Y-%m-%d', args.daily, keep)
         if args.weekly:
             keep += purge_split(archives, '%Y-%V', args.weekly, keep)
         if args.monthly:
@@ -352,6 +354,8 @@ class Archiver(object):
 
         subparser = subparsers.add_parser('purge')
         subparser.set_defaults(func=self.do_purge)
+        subparser.add_argument('-H', '--hourly', dest='hourly', type=int, default=0,
+                               help='Number of hourly archives to keep')
         subparser.add_argument('-d', '--daily', dest='daily', type=int, default=0,
                                help='Number of daily archives to keep')
         subparser.add_argument('-w', '--weekly', dest='weekly', type=int, default=0,

+ 13 - 0
darc/test.py

@@ -121,6 +121,19 @@ class Test(unittest.TestCase):
         fd.close()
         self.darc('verify', self.store_path + '::test', exit_code=1)
 
+    def test_purge_store(self):
+        src_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
+        self.darc('init', '-p', '', self.store_path)
+        self.darc('create', self.store_path + '::test1', src_dir)
+        self.darc('create', self.store_path + '::test2', src_dir)
+        self.darc('purge', self.store_path, '--daily=2')
+        output = self.darc('list', self.store_path)
+        assert 'test1' in output
+        assert 'test2' in output
+        self.darc('purge', self.store_path, '--daily=2', '--really')
+        output = self.darc('list', self.store_path)
+        assert 'test1' not in output
+        assert 'test2' in output
 
 def suite():
     suite = unittest.TestSuite()