示例#1
0
文件: mailin.py 项目: cguardia/karl
    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()
示例#2
0
def exercise(app):
    """
    Simulate the first request to the application in order to prime the ZODB
    cache.

    Performing this operation during start up, it is hoped to delay user
    requests being handed off to this worker by mod_wsgi until after the cache
    is already primed.  Otherwise the first, slow, cache priming request would
    fall to an unlucky user.
    """
    # Need to be logged in as somebody.  Use the first user we find that is a
    # member of some group.
    root, closer = get_root(app)
    for profile in root['profiles'].values():
        user = root.users.get_by_id(profile.__name__)
        if user['groups']:
            break

    request = webob.Request.blank('/')
    request.environ['repoze.who.identity'] = user
    user['repoze.who.userid'] = user['id']
    home, extra_path = get_user_home(root, request)
    path = model_path(home, *extra_path)
    request.path_info = path
    response = request.get_response(app)
    if response.status_int != 200:
        logger = get_logger()
        logger.warn('Status of %s when priming cache.  Response body:\n%s' %
                    (response.status, response.body))
示例#3
0
def main(argv=sys.argv):
    logging.basicConfig()
    parser = optparse.OptionParser(description=__doc__, usage="%prog [options]")
    parser.add_option(
        "-C",
        "--config",
        dest="config",
        help="Path to configuration file (defaults to $CWD/etc/karl.ini)",
        metavar="FILE",
    )
    parser.add_option(
        "-O",
        "--output",
        dest="output",
        default=".",
        help="Path to the directory where reports should be written.",
        metavar="DIR",
    )
    options, args = parser.parse_args(argv[1:])

    if args:
        parser.error("Too many arguments. " + str(args))

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

    root, closer = get_root(app)
    folder = os.path.abspath(options.output)
    generate_reports(root, folder)
示例#4
0
def main(argv=sys.argv):
    parser = optparse.OptionParser(
        description=__doc__,
        usage="%prog [options] [user1, user2, ...]",
        )
    parser.add_option('-C', '--config', dest='config',
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('-f', '--filter', dest='filter', action='store_true',
        help='Limit results to users specified by username in stdin.  Users'
             ' should be whitespace delimited.', default=False)
    options, args = parser.parse_args(argv[1:])

    ids = None
    if options.filter:
        ids = sys.stdin.read().split()

    if args:
        if ids is not None:
            ids.extend(args)
        else:
            ids = args

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

    root, closer = get_root(app)

    out_csv = csv.writer(sys.stdout)
    out_csv.writerow(['username', 'community', 'last_activity'])
    for row in stats.user_activity_report(root, ids):
        username, community, last_activity = row
        out_csv.writerow([username, community.__name__, last_activity.ctime()])
示例#5
0
def open_root(config, name='openhcd'):
    """Open the database root object, given a Paste Deploy config file name.

    Returns (root, closer).  Call the closer function to close the database
    connection.
    """
    config = os.path.abspath(os.path.normpath(config))
    app = loadapp('config:%s' % config, name=name)
    return get_root(app)
示例#6
0
def open_root(config, name="karl"):  # pragma NO COVERAGE
    """Open the database root object, given a Paste Deploy config file name.

    Returns (root, closer).  Call the closer function to close the database
    connection.
    """
    config = os.path.abspath(os.path.normpath(config))
    app = loadapp("config:%s" % config, name=name)
    return get_root(app)
示例#7
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()
示例#8
0
文件: mailin.py 项目: cguardia/karl
    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()
示例#9
0
文件: digest.py 项目: boothead/karl
 def run():
     set_subsystem('digest')
     root, closer = get_root(app)
     alerts.send_digests(root)
     closer()