source: main/waeup.kofa/trunk/src/waeup/kofa/maintenance.py @ 8986

Last change on this file since 8986 was 8719, checked in by uli, 13 years ago

pyflakes.

File size: 1.7 KB
Line 
1"""Helpers for maintainers of kofa sites.
2
3XXX: This stuff might go into a separate package, but right
4     now it is too less for a complete package.
5"""
6import sys
7from ZODB.scripts.analyze import report, analyze
8from zope.component.hooks import setSite
9from zope.component import getUtility
10from zope.catalog.interfaces import ICatalog
11from zope.intid.interfaces import IIntIds
12
13def db_analyze(args=None):
14    """Run the analyze tool from ZODB package.
15    """
16    if args is None:
17        args = sys.argv[1:]
18
19    path = None
20    if len(args) > 0:
21        path = args[0]
22    else:
23        print
24        print "Analyze a ZODB file and print statistics"
25        print "about contained objects, sizes, etc."
26        print
27        print "Usage: %s <path-to-Data.fs>" % sys.argv[0]
28        print
29        sys.exit(0)
30
31    report(analyze(path))
32
33def update_catalog(site, cat_name, objects=[], func=None):
34    """Update a catalog.
35
36    Put `objects` or objects delivered by `func()` into the catalog
37    registered under `cat_name` in `site`.
38
39    Objects to be catalogued must be 'located', i.e. they must have a
40    __name__ and __parent__ (because they are adapted to
41    IKeyReference).
42
43    You can pass in objects as some iterable or as a function that is
44    called to deliver the set of objects to be catalogued.
45
46    A function takes precedence over object lists.
47    """
48    setSite(site)
49    cat = getUtility(ICatalog, name=cat_name)
50    intids = getUtility(IIntIds, context=cat)
51    if func is not None:
52        objects = func()
53    for ob in objects:
54        doc_id = intids.queryId(ob, None)
55        if doc_id is None:
56            doc_id = intids.register(ob)
57        cat.index_doc(doc_id, ob)
58    return cat
Note: See TracBrowser for help on using the repository browser.