예제 #1
0
파일: mock.py 프로젝트: moreandres/behaving
def main(args=sys.argv[1:]):
    """Main function called by `mailmock` command.
    """
    parser = argparse.ArgumentParser(description='Mail mock server')

    parser.add_argument('-p', '--port', default='8025', help='The port to use')

    parser.add_argument('-o',
                        '--output_dir',
                        default=None,
                        required=True,
                        help='Directory where to dump the mail.')
    parser.add_argument('-n',
                        '--no-stdout',
                        dest="log_to_stdout",
                        default=True,
                        action="store_false",
                        required=False,
                        help="Don't log received mail to stdout")
    options = parser.parse_args(args=args)

    if not os.path.exists(options.output_dir):
        try:
            os.mkdir(options.output_dir)
        except OSError:
            logging.error('Output directory could not be created')
    global output_dir
    output_dir = options.output_dir

    smtpd = DebuggingServer(('0.0.0.0', int(options.port)), None,
                            options.log_to_stdout)
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        smtpd.close()
예제 #2
0
def main(args=sys.argv[1:]):
    """Main function called by `mailmock` command.
    """
    parser = argparse.ArgumentParser(description='Mail mock server')

    parser.add_argument('-p', '--port',
                        default='8025',
                        help='The port to use')

    parser.add_argument('-o', '--output_dir',
                        default=None,
                        required=True,
                        help='Directory where to dump the mail.')
    parser.add_argument('-n', '--no-stdout',
                        dest="log_to_stdout",
                        default=True,
                        action="store_false",
                        required=False,
                        help="Don't log received mail to stdout")
    options = parser.parse_args(args=args)

    if not os.path.exists(options.output_dir):
        try:
            os.mkdir(options.output_dir)
        except OSError:
            logging.error('Output directory could not be created')
    global output_dir
    output_dir = options.output_dir

    smtpd = DebuggingServer(('localhost', int(options.port)), None, options.log_to_stdout)
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        smtpd.close()