diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-02-12 23:33:50 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-02-12 23:33:50 +0000 |
commit | 5993da289ea43e60231135c0410318bbb10eafaf (patch) | |
tree | cfb82392165be6c973782f3442b0da2498bc9148 /summain | |
parent | 64b79c2f1104e6c6e7dd1d435001777ea4252f5c (diff) | |
download | summain-5993da289ea43e60231135c0410318bbb10eafaf.tar.gz |
Use cliapp for main program.
Diffstat (limited to 'summain')
-rwxr-xr-x | summain | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -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 <http://www.gnu.org/licenses/>. +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() |