示例#1
0
def addWikiFromFs(self, new_id, title='', wiki_type='zwikidotorg',
                      REQUEST=None):
    """
    Create a new zwiki web from the specified template on the filesystem.
    """
    parent = self.Destination()
    # Go with a BTreeFolder from the start to avoid hassle with large
    # wikis on low-memory hosted servers ?
    #parent.manage_addProduct['BTreeFolder2'].manage_addBTreeFolder(
    #str(new_id),str(title))
    # No - the standard folder's UI is more useful for small wikis,
    # and more importantly BTreeFolder2 isn't standard until 2.8.0b2
    f = Folder()
    f.id, f.title = str(new_id), str(title)
    new_id = parent._setObject(f.id, f)
    f = parent[new_id]
    # add objects from wiki template
    # cataloging really slows this down!
    dir = os.path.join(package_home(globals()),'wikis',wiki_type)
    filenames = os.listdir(dir)
    for filename in filenames:
        if re.match(r'(?:\..*|CVS|_darcs)', filename): continue
        m = re.search(r'(.+)\.(.+)',filename)
        id, type = filename, ''
        if m: id, type = m.groups()
        text = open(dir + os.sep + filename, 'r').read()
        if type == 'dtml':
            addDTMLMethod(f, filename[:-5], title='', file=text)
        elif re.match(r'(?:(?:stx|html|latex)(?:dtml)?|txt)', type):
            addZWikiPage(f,id,title='',page_type=type,file=text)
        elif type == 'pt':
            f._setObject(id, ZopePageTemplate(id, text, 'text/html'))
        elif type == 'py':
            f._setObject(id, PythonScript(id))
            f._getOb(id).write(text)
        elif type == 'zexp' or type == 'xml':
            connection = self.getPhysicalRoot()._p_jar
            f._setObject(id, connection.importFile(dir + os.sep + filename, 
                customImporters=customImporters))
            #self._getOb(id).manage_changeOwnershipType(explicit=0)
        elif re.match(r'(?:jpe?g|gif|png)', type):
            f._setObject(filename, Image(filename, '', text))
        else:
            id = f._setObject(filename, File(filename, '', text))
            if type == 'css': f[filename].content_type = 'text/css'
    f.objectValues(spec='ZWiki Page')[0].updatecontents()