You are here: Home / Documentation / How To's / Script to locate intranet folders

Script to locate intranet folders

by nguyen — published Apr 08, 2009 03:47 PM, last modified Aug 16, 2016 10:50 AM

ZMI

Add Script (Python) called ".findIntranets" containing

plone_site_search_depth = 3 # depth it will search, from the zope root, for plone sites

def find_intranets(plone):
    """
    Steps:
    1. look at Plone content types
    2. look in root folder of each site
    """

    pc = plone.portal_catalog
    brains = pc.searchResults({'portal_type' : ('Folder', ) })
    brains = list(brains)
    #brains.filter(lambda x : "MB" not in x.getObjSize)
    #brains.sort(lambda x, y : x.getObjSize > y.getObjSize)

    for b in brains:
        id = b.getId
        if id == 'intranet' or id == 'Intranet':
            url = b.getURL()
            print "<a href='%s'>%s</a><br>" % (url, url)

    return printed

def get_plone_sites():

    def find_it(current_context, depth):
        if depth == 0:
            return []
        else:
            sites = []
            for obj in current_context.objectIds():
                site = current_context[obj]
                if hasattr(site, 'portal_type') and site.portal_type == 'Plone Site':
                    sites.append(site)
                elif hasattr(site, 'objectIds'):
                    sites.extend(find_it(site, depth - 1))
            return sites
    return find_it(context, plone_site_search_depth)

sites = get_plone_sites()

for site in sites:
    print "Plone Site: %s<br/>" % site.title
    print find_intranets(site)

return printed
Navigation