@@ -0,0 +1,3094 @@
+import argparse%0Aimport os%0Aimport sys%0Afrom ConfigParser import (%0A        SafeConfigParser,%0A        NoOptionError,%0A        )%0A%0Afrom oauth2client import file%0Afrom oauth2client import client%0Afrom oauth2client import tools%0A%0A# Parser for command-line arguments.%0Aparser = argparse.ArgumentParser(%0A        description=__doc__,%0A        formatter_class=argparse.RawDescriptionHelpFormatter,%0A        parents=%5Btools.argparser%5D%0A        )%0Aparser.add_argument('--section', nargs='?', help='The section to read from the configuration file.', default='DEFAULT')%0Aparser.add_argument('config', help='Configuration file.')%0A%0Adef str2bool(truthy):%0A    return truthy%5B0%5D.lower() in ('y', 't')%0A%0Aclass Configuration(object):%0A    def __init__(self):%0A        # Parse the command-line flags.%0A        flags = parser.parse_args()%0A%0A        config_defaults = %7B%7D%0A        config_defaults%5B'here'%5D = os.path.dirname(os.path.abspath(flags.config))%0A        config = SafeConfigParser(config_defaults)%0A        config.readfp(open(flags.config))%0A%0A        if flags.section != 'DEFAULT' and not config.has_section(flags.section):%0A            parser.error('Specified section doesn%5C't exist in configuration.')%0A%0A        try:%0A            # CLIENT_SECRETS is name of a file containing the OAuth 2.0 information for this%0A            # application, including client_id and client_secret. You can see the Client ID%0A            # and Client secret on the APIs page in the Cloud Console:%0A            # %3Chttps://cloud.google.com/console%3E%0A            self.CLIENT_SECRETS = config.get(flags.section, 'secrets')%0A            self.CLIENT_CREDENTIALS = config.get(flags.section, 'credentials')%0A            self.INTERVAL = int(config.get(flags.section, 'interval'))%0A            self.WITH_GEOIP = str2bool(config.get(flags.section, 'geoip.enabled'))%0A            self.email = %7B%7D%0A        except NoOptionError as e:%0A            parser.error('Unable to get required parameter from config: %7B%7D'.format(e))%0A%0A        # Set up a Flow object to be used for authentication.%0A        # Add one or more of the following scopes. PLEASE ONLY ADD THE SCOPES YOU%0A        # NEED. For more information on using scopes please see%0A        # %3Chttps://developers.google.com/+/best-practices%3E.%0A        self.FLOW = client.flow_from_clientsecrets(self.CLIENT_SECRETS,%0A                scope=%5B%0A                    'https://www.googleapis.com/auth/admin.reports.audit.readonly',%0A                    'https://www.googleapis.com/auth/admin.reports.usage.readonly',%0A                    %5D,%0A                message=tools.message_if_missing(self.CLIENT_SECRETS)%0A                )%0A%0A        # If the credentials don't exist or are invalid run through the native client%0A        # flow. The Storage object will ensure that if successful the good%0A        # credentials will get written back to the file.%0A        storage = file.Storage(self.CLIENT_CREDENTIALS)%0A        self.credentials = storage.get()%0A        if self.credentials is None or self.credentials.invalid:%0A            self.credentials = tools.run_flow(FLOW, storage, flags) %0A%0A    def get_credentials(self):%0A        return self.credentials%0A

Split the arg/config parsing out into seperate part