def main(): parser = OptionParser() parser.add_option( "-i", "--ini-file", dest="ini_file", help="read configuration from FILE (default: %default)", metavar="FILE", default="expense.ini", ) parser.add_option( "-v", "--verbose", action="count", dest="verbose", help="print status messages to stdout more verbose", default=1, ) parser.add_option( "-c", "--create-default-config", dest="create_default_config", action="store_true", help="create a default config file", default=False, ) parser.add_option( "-y", "--yes", dest="require_confirm", action="store_false", help="don't ask questions", default=True ) parser.add_option( "--include-without-attachment", dest="attachment_only", action="store_false", help="include mails without attachments during forwarding", default=True, ) (options, args) = parser.parse_args() if options.verbose > 1: _checked_load_logging_config("~/.python/logging_debug.conf") elif options.verbose: _checked_load_logging_config("~/.python/logging.conf") else: logging.basicConfig(stream=sys.stdout, level=logging.WARN) config_parser = ExpenseConfigParser(ConfigParser(), options.ini_file) if options.create_default_config: config_parser.store() else: config_provider = config_parser.load() config_provider.attachment_only = options.attachment_only ExpenseHelper( config_provider=config_provider, confirmation_provider=options.require_confirm and ConfirmationProvier.from_commandline or ConfirmationProvier.yes, ).run()
def test_store_and_load_config(self): from tempfile import NamedTemporaryFile f = NamedTemporaryFile(delete = True) e = ExpenseConfigParser(ConfigParser(), f.name) e.store() e.load()