Example #1
0
def main():
    parser = optparse.OptionParser(description=__doc__, usage="%prog [options] queue_path")
    parser.add_option(
        "-C",
        "--config",
        dest="config",
        default=None,
        help="Path to configuration file (defaults to $CWD/etc/karl.ini)",
        metavar="FILE",
    )
    parser.add_option("--daemon", "-D", dest="daemon", action="store_true", default=False, help="Run in daemon mode.")
    parser.add_option(
        "--interval",
        "-i",
        dest="interval",
        type="int",
        default=6 * 3600,
        help="Interval, in seconds, between executions when in " "daemon mode.",
    )
    parser.add_option(
        "--server", "-s", dest="hostname", default="localhost", help="SMTP server host name", metavar="HOST"
    )
    parser.add_option("--port", "-P", dest="port", type="int", default=25, help="Port of SMTP server", metavar="PORT")
    parser.add_option("--username", "-u", dest="username", default=None, help="Username, if authentication is required")
    parser.add_option("--password", "-p", dest="password", default=None, help="Password, if authentication is required")
    parser.add_option(
        "--force-tls", "-f", dest="force_tls", action="store_true", default=False, help="Require that TLS be used."
    )
    parser.add_option(
        "--no-tls", "-n", dest="no_tls", action="store_true", default=False, help="Require that TLS not be used."
    )

    options, args = parser.parse_args()

    if not args:
        parser.error("Please specify queue path.")
    elif len(args) > 1:
        parser.error("Too many arguments.")
    queue_path = args[0]

    config = options.config
    if config is None:
        config = get_default_config()
    app = loadapp("config:%s" % config, "karl")
    set_subsystem("mailout")

    mailer = SMTPMailer(
        hostname=options.hostname,
        port=options.port,
        username=options.username,
        password=options.password,
        no_tls=options.no_tls,
        force_tls=options.force_tls,
    )
    qp = QueueProcessor(mailer, queue_path)

    if options.daemon:
        run_daemon("digest", qp.send_messages, options.interval)
    else:
        qp.send_messages()
Example #2
0
    def run():
        root, closer = get_root(app)
        set_subsystem('mailin')

        zodb_uri = get_setting(root, 'postoffice.zodb_uri')
        zodb_path = get_setting(root, 'postoffice.zodb_path', '/postoffice')
        queue = get_setting(root, 'postoffice.queue')

        if zodb_uri is None:
            parser.error("postoffice.zodb_uri must be set in config file")

        if queue is None:
            parser.error("postoffice.queue must be set in config file")

        runner = MailinRunner2(root, zodb_uri, zodb_path, queue)
        try:
            runner()

            if options.dry_run:
                transaction.abort()
            else:
                transaction.commit()

            p_jar = getattr(root, '_p_jar', None)
            if p_jar is not None:
                # Attempt to fix memory leak
                p_jar.db().cacheMinimize()

        except:
            transaction.abort()
            raise

        finally:
            closer()
            runner.close()
Example #3
0
def main():
    parser = optparse.OptionParser(
        description=__doc__,
        usage="%prog [options] queue_path",
    )
    parser.add_option('-C', '--config', dest='config',
        default=None,
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('--daemon', '-D', dest='daemon',
                      action='store_true', default=False,
                      help='Run in daemon mode.')
    parser.add_option('--interval', '-i', dest='interval', type='int',
                      default=6*3600,
                      help='Interval, in seconds, between executions when in '
                           'daemon mode.')
    parser.add_option('--server', '-s', dest='hostname', default="localhost",
                      help='SMTP server host name', metavar='HOST')
    parser.add_option('--port', '-P', dest='port', type='int', default=25,
                      help='Port of SMTP server', metavar='PORT')
    parser.add_option('--username', '-u', dest='username', default=None,
                      help='Username, if authentication is required')
    parser.add_option('--password', '-p', dest='password', default=None,
                      help='Password, if authentication is required')
    parser.add_option('--force-tls', '-f', dest='force_tls',
                      action='store_true', default=False,
                      help='Require that TLS be used.')
    parser.add_option('--no-tls', '-n', dest='no_tls',
                      action='store_true', default=False,
                      help='Require that TLS not be used.')

    options, args = parser.parse_args()

    if not args:
        parser.error('Please specify queue path.')
    elif len(args) > 1:
        parser.error('Too many arguments.')
    queue_path = args[0]

    config = options.config
    if config is None:
        config = get_default_config()
    app = loadapp('config:%s' % config, 'karl')
    set_subsystem('mailout')

    mailer = SMTPMailer(
        hostname=options.hostname,
        port=options.port,
        username=options.username,
        password=options.password,
        no_tls=options.no_tls,
        force_tls=options.force_tls
    )
    qp = QueueProcessor(mailer, queue_path)

    if options.daemon:
        run_daemon('digest', qp.send_messages, options.interval)
    else:
        qp.send_messages()
Example #4
0
 def run(root=root):
     closer = lambda: None  # unit test
     try:
         if root is None:
             root, closer = get_root(app)
         #else: unit test
         set_subsystem('update_feeds')
         update_func(root, config, force=options.force)
     except:
         tx.abort()
         closer()
         raise
     else:
         if options.dryrun:
             tx.abort()
         else:
             tx.commit()
         closer()
Example #5
0
def make_app(global_config, **kw):
    config = global_config.copy()
    config.update(kw)

    # paster app config callback
    zodb_uri = config.get('zodb_uri')
    if zodb_uri is None:
        raise ValueError('zodb_uri must not be None')
    get_root = PersistentApplicationFinder(zodb_uri, appmaker)

    # Coerce a value out of the [app:karl] section in the INI file
    jquery_dev_mode = config.get('jquery_dev_mode', False)
    config['jquery_dev_mode'] = asbool(jquery_dev_mode)

    # Set up logging
    configure_log(**config)
    set_subsystem('karl')

    # Set up logging admin view (coerce instances to list)
    if 'logs_view' in config:
        config['logs_view'] = map(os.path.abspath, config['logs_view'].split())

    for key in ('syslog_view_instances', 'error_monitor_subsystems'):
        if key in config:
            config[key] = config[key].split()

    # Make BFG app
    pkg_name = config.get('package', None)
    if pkg_name is not None:
        __import__(pkg_name)
        package = sys.modules[pkg_name]
        app = bfg_make_app(get_root, package, options=config)
    else:
        filename = 'karl.includes:standalone.zcml'
        app = bfg_make_app(get_root, filename=filename, options=config)

    #exercise(app) # experimental
    return app
Example #6
0
    def run(root=root):
        closer = lambda: None # unit test
        if options.run_draino:
            draino_args = ['draino', '-vvv', '-p', '%s/Maildir' % maildir_root,
                           maildir_root]
            if options.dry_run:
                draino_args.insert(1, '--dry-run')
            draino = Draino(draino_args)

        if root is None:
            root, closer = get_root(app)
        #else: unit test

        set_subsystem('mailin')
        if options.run_draino:
            draino.run()
        runner = factory(root, maildir_root, options)
        runner()
        p_jar = getattr(root, '_p_jar', None)
        if p_jar is not None:
            # Attempt to fix memory leak
            p_jar.db().cacheMinimize()
        closer()
Example #7
0
 def run():
     set_subsystem('digest')
     root, closer = get_root(app)
     alerts.send_digests(root)
     closer()