#!/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 . # To debug, one can create a tracing logfile by adding arguments like: # --trace=fsck --log=fsck.logfile 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) at_least_one_error = False for dirname in args: self.errors = False forest = larch.open_forest( allow_writes=self.settings['fix'], dirname=dirname) self.ts = ttystatus.TerminalStatus(period=0.1) self.ts['item'] = None self.ts['items'] = 0 self.ts['last_id'] = forest.last_id self.ts.format( 'Checking %Counter(item)/%Integer(last_id): %String(item)') self.ts.notify('fsck-larch for %s' % dirname) fsck = larch.fsck.Fsck(forest, self.warning, self.error, self.settings['fix']) fsck.run_fsck( ts = self.ts ) self.ts.finish() if self.errors: at_least_one_error = True else: print 'fsck-larch for %s: No errors found' % dirname 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()