From 5993da289ea43e60231135c0410318bbb10eafaf Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 12 Feb 2011 23:33:50 +0000 Subject: Use cliapp for main program. --- summain | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'summain') diff --git a/summain b/summain index d89a36c..58ac582 100755 --- a/summain +++ b/summain @@ -1,5 +1,5 @@ #!/usr/bin/python -# Copyright (C) 2010 Lars Wirzenius +# Copyright (C) 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 @@ -15,24 +15,31 @@ # along with this program. If not, see . +import cliapp import os import sys import summainlib -def files(root): - if os.path.isdir(root): - for dirname, dirnames, filenames in os.walk(root): - yield dirname - for filename in sorted(filenames): - yield os.path.join(dirname, filename) - else: - yield root - -normalizer = summainlib.NumberNormalizer() -for root in sys.argv[1:]: - for filename in files(root): - o = summainlib.FilesystemObject(filename, normalizer) - sys.stdout.write(o.format()) - sys.stdout.write('\n') +class Summain(cliapp.Application): + + def files(self, root): + if os.path.isdir(root): + for dirname, dirnames, filenames in os.walk(root): + yield dirname + for filename in sorted(filenames): + yield os.path.join(dirname, filename) + else: + yield root + + def process_args(self, args): + normalizer = summainlib.NumberNormalizer() + for root in args: + for filename in self.files(root): + o = summainlib.FilesystemObject(filename, normalizer) + sys.stdout.write(o.format()) + sys.stdout.write('\n') + + +Summain().run() -- cgit v1.2.1