diff options
-rw-r--r-- | obnamlib/plugins/forget_plugin.py | 57 | ||||
-rw-r--r-- | without-tests | 1 |
2 files changed, 58 insertions, 0 deletions
diff --git a/obnamlib/plugins/forget_plugin.py b/obnamlib/plugins/forget_plugin.py new file mode 100644 index 00000000..4aae3d71 --- /dev/null +++ b/obnamlib/plugins/forget_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2010 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +import datetime + +import obnamlib + + +class ForgetPlugin(obnamlib.ObnamPlugin): + + '''Forget generations.''' + + def enable(self): + self.app.register_command('forget', self.forget) + self.app.config.new_string(['keep'], + 'policy for what generations to keep ' + 'when forgetting') + + def forget(self, args): + fs = self.app.fsf.new(self.app.config['store']) + self.store = obnamlib.Store(fs) + self.store.lock_host(self.app.config['hostname']) + + if args: + for genid in args: + self.store.remove_generation(genid) + elif self.app.config['keep']: + genlist = [] + dt = datetime.datetime(1970, 1, 1, 0, 0, 0) + for genid in self.store.list_generations(): + start, end = self.store.get_generation_times(genid) + genlist.append((genid, dt.fromtimestamp(end))) + + fp = obnamlib.ForgetPolicy() + rules = fp.parse(self.app.config['keep']) + keeplist = fp.match(rules, genlist) + keepids = set(genid for genid, dt in keeplist) + + for genid, dt in genlist: + if genid not in keepids: + self.store.remove_generation(genid) + + self.store.commit_host() + diff --git a/without-tests b/without-tests index ea4dee5f..c6cc2419 100644 --- a/without-tests +++ b/without-tests @@ -16,3 +16,4 @@ ./test-plugins/aaa_hello_plugin.py ./test-plugins/wrongversion_plugin.py +./obnamlib/plugins/forget_plugin.py |