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()
def _initPAS(self, plugin_type_info=(), plugins={}): from OFS.Folder import Folder from Products.PluggableAuthService.PluggableAuthService import addPluggableAuthService app = Folder() app.getPhysicalPath = lambda: () app.getPhysicalRoot = lambda: app addPluggableAuthService(app) pas = app._getOb("acl_users") return app, pas
def _initPAS(self, plugin_type_info=(), plugins={}): from OFS.Folder import Folder from Products.PluggableAuthService.PluggableAuthService \ import addPluggableAuthService app = Folder() app.getPhysicalPath = lambda: () app.getPhysicalRoot = lambda: app addPluggableAuthService(app) pas = app._getOb('acl_users') return app, pas
def _initRegistry(self, plugin_type_info=(), plugins={}): from OFS.Folder import Folder from OFS.SimpleItem import SimpleItem from Products.PluginRegistry.PluginRegistry import PluginRegistry app = Folder() app.getPhysicalPath = lambda: () app.getPhysicalRoot = lambda: app app._setObject('foo_plugin_1', SimpleItem()) app._setObject('foo_plugin_2', SimpleItem()) registry = PluginRegistry(plugin_type_info) registry._plugins = {} # it is usually lazy for plugin_type, registered in plugins.items(): for obj_id in registered: obj = app._getOb(obj_id) directlyProvides(obj, plugin_type) registry._plugins[plugin_type] = registered app._setObject('plugin_registry', registry) registry = app._getOb('plugin_registry') return app, registry