From 68d0520d5a1d4a76ac5a35ef14fdd2843d5ea3d8 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 15 Dec 2007 04:07:55 -0800 Subject: Make app.py pass pylint. --- gitosis/app.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/gitosis/app.py b/gitosis/app.py index fa9772b..ff44fed 100644 --- a/gitosis/app.py +++ b/gitosis/app.py @@ -1,3 +1,4 @@ +"""Common code for all callable Gitosis programs.""" import os import sys import logging @@ -5,6 +6,8 @@ import optparse import errno import ConfigParser +# C0103 - 'log' is a special name +# pylint: disable-msg=C0103 log = logging.getLogger('gitosis.app') class CannotReadConfigError(Exception): @@ -17,30 +20,41 @@ class ConfigFileDoesNotExistError(CannotReadConfigError): """Configuration does not exist""" class App(object): + """Common Gitosis Application runner.""" + # R0201 - the many of the methods in this class are intended to be + # overridden, hence they are not suited to be functions. + # W0613 - They also might ignore arguments here, where the descendant + # methods won't. + # pylint: disable-msg=R0201,W0613 + name = None - def run(class_): - app = class_() + def run(cls): + """Launch the app.""" + app = cls() return app.main() run = classmethod(run) def main(self): + """Main program routine.""" self.setup_basic_logging() parser = self.create_parser() (options, args) = parser.parse_args() cfg = self.create_config(options) try: self.read_config(options, cfg) - except CannotReadConfigError, e: - log.error(str(e)) + except CannotReadConfigError, ex: + log.error(str(ex)) sys.exit(1) self.setup_logging(cfg) self.handle_args(parser, cfg, options, args) def setup_basic_logging(self): + """Set up the initial logging.""" logging.basicConfig() def create_parser(self): + """Handle commandline option parsing.""" parser = optparse.OptionParser() parser.set_defaults( config=os.path.expanduser('~/.gitosis.conf'), @@ -53,25 +67,28 @@ class App(object): return parser def create_config(self, options): + """Handle config file parsing.""" cfg = ConfigParser.RawConfigParser() return cfg def read_config(self, options, cfg): + """Read the configuration file into the config parser.""" try: conffile = file(options.config) - except (IOError, OSError), e: - if e.errno == errno.ENOENT: + except (IOError, OSError), ex: + if ex.errno == errno.ENOENT: # special case this because gitosis-init wants to # ignore this particular error case - raise ConfigFileDoesNotExistError(str(e)) + raise ConfigFileDoesNotExistError(str(ex)) else: - raise CannotReadConfigError(str(e)) + raise CannotReadConfigError(str(ex)) try: cfg.readfp(conffile) finally: conffile.close() def setup_logging(self, cfg): + """Set up the full logging, using the configuration.""" try: loglevel = cfg.get('gitosis', 'loglevel') except (ConfigParser.NoSectionError, @@ -79,6 +96,8 @@ class App(object): pass else: try: + # logging really should declare the symbolics + # pylint: disable-msg=W0212 symbolic = logging._levelNames[loglevel] except KeyError: log.warning( @@ -89,5 +108,6 @@ class App(object): logging.root.setLevel(symbolic) def handle_args(self, parser, cfg, options, args): + """Abstract method for the non-option argument handling.""" if args: parser.error('not expecting arguments') -- cgit v1.2.3