diff --git a/configuration.py b/configuration.py index e77f560..32f0789 100644 --- a/configuration.py +++ b/configuration.py @@ -27,41 +27,40 @@ import sys if sys.version_info.major == 3: - import configparser + import configparser else: - import ConfigParser as configparser + import ConfigParser as configparser -from os.path import expanduser def get_account_data(print_errors = False, config_file = 'conf.cfg', config_section = 'ote'): - """ - boolean print_errors: Print errors to stdout instead of raising an exception. - string config_file: The name of the configuration file. - string config_section: The name of the section to read in the configuration file. - """ - config = open_config_file(print_errors, config_file) - try: - username = config.get(config_section, 'username') - password = config.get(config_section, 'password') - shared_secret = config.get(config_section, 'shared_secret') - except Exception as err: - message = 'Error: Please make sure your config file %s contains the section %s with the entries "username", "password" and "shared_secret".' % (config_file, config_section) - if print_errors: - print(message) - sys.exit(2) - else: - raise NameError(message) - return (username, password, shared_secret) + """ + boolean print_errors: Print errors to stdout instead of raising an exception. + string config_file: The name of the configuration file. + string config_section: The name of the section to read in the configuration file. + """ + config = open_config_file(print_errors, config_file) + try: + username = config.get(config_section, 'username') + password = config.get(config_section, 'password') + shared_secret = config.get(config_section, 'shared_secret') + except Exception: + message = 'Error: Please make sure your config file %s contains the section %s with the entries "username", "password" and "shared_secret".' % (config_file, config_section) + if print_errors: + print(message) + sys.exit(2) + else: + raise NameError(message) + return (username, password, shared_secret) def open_config_file(print_errors, config_file): - config = configparser.ConfigParser() - try: - if config.read(config_file) == []: raise Exception() - except: - message = "Error: Please make sure you adopted the config file: %s" % config_file - if print_errors: - print(message) - sys.exit(2) - else: - raise NameError(message) - return config + config = configparser.ConfigParser() + try: + if config.read(config_file) == []: raise Exception() + except: + message = "Error: Please make sure you adopted the config file: %s" % config_file + if print_errors: + print(message) + sys.exit(2) + else: + raise NameError(message) + return config