浏览代码

Add --dry-run option to prune.

Dan Christensen 11 年之前
父节点
当前提交
5d2d3f1f93
共有 2 个文件被更改,包括 17 次插入5 次删除
  1. 8 2
      attic/archiver.py
  2. 9 3
      attic/testsuite/archiver.py

+ 8 - 2
attic/archiver.py

@@ -331,8 +331,11 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         for archive in keep:
             self.print_verbose('Keeping archive "%s"' % archive.name)
         for archive in to_delete:
-            self.print_verbose('Pruning archive "%s"', archive.name)
-            archive.delete(cache)
+            if args.dry_run:
+                self.print_verbose('Would prune     "%s"' % archive.name)
+            else:
+                self.print_verbose('Pruning archive "%s"' % archive.name)
+                archive.delete(cache)
         return self.exit_code
 
     helptext = {}
@@ -561,6 +564,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
                                           description=self.do_prune.__doc__,
                                           epilog=prune_epilog)
         subparser.set_defaults(func=self.do_prune)
+        subparser.add_argument('-n', '--dry-run', dest='dry_run',
+                               default=False, action='store_true',
+                               help='do not change repository')
         subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN',
                                help='keep all archives within this time interval')
         subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0,

+ 9 - 3
attic/testsuite/archiver.py

@@ -253,10 +253,16 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.attic('init', self.repository_location)
         self.attic('create', self.repository_location + '::test1', src_dir)
         self.attic('create', self.repository_location + '::test2', src_dir)
-        self.attic('prune', self.repository_location, '--daily=2')
+        output = self.attic('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
+        self.assert_in('Keeping archive "test2"', output)
+        self.assert_in('Would prune     "test1"', output)
         output = self.attic('list', self.repository_location)
-        assert 'test1' not in output
-        assert 'test2' in output
+        self.assert_in('test1', output)
+        self.assert_in('test2', output)
+        self.attic('prune', self.repository_location, '--keep-daily=2')
+        output = self.attic('list', self.repository_location)
+        self.assert_not_in('test1', output)
+        self.assert_in('test2', output)
 
     def test_usage(self):
         self.assert_raises(SystemExit, lambda: self.attic())