#!/usr/bin/python # Copyright 2010, 2011 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 . import cliapp import logging import sys import tracing import ttystatus import larch.fsck class Fsck(cliapp.Application): def add_settings(self): self.settings.string_list(['trace'], 'add PATTERN to trace patterns', metavar='PATTERN') self.settings.boolean(['fix'], 'fix problems found?') def process_args(self, args): for pattern in self.settings['trace']: tracing.trace_add_pattern(pattern) self.ts = ttystatus.TerminalStatus(period=0.1) self.ts['check'] = 0 self.ts['checks'] = 0 self.ts['checkname'] = '' self.ts.add(ttystatus.PercentDone('check', 'checks', decimals=2)) self.ts.add(ttystatus.Literal(' ')) self.ts.add(ttystatus.RemainingTime('check', 'checks')) self.ts.add(ttystatus.Literal(' remaining; now: ')) self.ts.add(ttystatus.String('checkname')) self.errors = False for dirname in args: self.ts.notify('fsck-larch for %s' % dirname) forest = larch.open_forest(dirname=dirname) fsck = larch.fsck.Fsck(forest, self.warning, self.error, self.settings['fix']) fsck.find_work() self.ts['checks'] = len(fsck.work) self.ts['check'] = 0 for work in fsck.work: self.ts['check'] += 1 self.ts['checkname'] = str(work) work.do() self.ts.finish() if self.errors: sys.exit(1) def error(self, msg): self.errors = True self.ts.notify(msg) logging.error(msg) def warning(self, msg): self.ts.notify(msg) logging.warning(msg) if __name__ == '__main__': Fsck().run()