Beispiel #1
0
    def _deployImages(self, destination, dir, extensions=['.gif','.ico'], t={},
                      remove_oldstuff=0):
        """ do the actual deployment of images in a dir """
        # shortcuts
        osj = os.path.join

        for filestr in os.listdir(dir):
            if self._file_has_extensions(filestr, extensions):
                # take the image
                id, title = cookIdAndTitle(filestr)
                base= getattr(destination,'aq_base',destination)
                if hasattr(base, id) and remove_oldstuff:
                    destination.manage_delObjects([id])

                if not hasattr(base, id):
                    destination.manage_addImage(id, title=title, \
                          file=open(osj(dir, filestr),'rb').read())
                    t[id]="Image"
        return t
Beispiel #2
0
    def DeployMassStandards(self, remove_oldstuff=0, DestinationURL=None):
        """ copy images and other documents into the instance unless they
            are already there
        """
        t={}

        # create folders
        root = self.getRoot()
        rootbase = getattr(root, 'aq_base', root)

        osj = os.path.join
        standards_home = osj(package_home(globals()),'standards')
        t = self._deployImages(root, standards_home,
                               t=t, remove_oldstuff=remove_oldstuff)

        #www_home = osj(standards_home,'www')
        #t = self._deployImages(root.www, www_home,
                               #t=t, remove_oldstuff=remove_oldstuff)

        # shortcut
        addPG = root.manage_addProduct['PageTemplates'].manage_addPageTemplate
        AddParam2URL = Utils.AddParam2URL

        for filestr in os.listdir(standards_home):
            if filestr[-5:] == '.dtml':
                id, title = cookIdAndTitle(filestr.replace('.dtml',''))
                if hasattr(rootbase, id) and remove_oldstuff:
                    root.manage_delObjects([id])

                if not hasattr(rootbase, id):
                    file = DTMLFile('standards/%s'%filestr.replace('.dtml',''), globals()).read()
                    root.manage_addDTMLDocument(id, title, file=file)
                    t[id] ="DTML Document"
            elif filestr[-4:] == '.zpt':
                id, title = cookIdAndTitle(filestr.replace('.zpt',''))
                if hasattr(rootbase, id) and remove_oldstuff:
                    root.manage_delObjects([id])

                if not hasattr(rootbase, id):
                    file = open(osj(standards_home,filestr)).read()
                    addPG(id, title=title, text=file)
                    t[id]="Page Template"
            elif filestr[-3:] == '.py':
                id, title = cookIdAndTitle(filestr.replace('.py',''))
                if hasattr(rootbase, id) and remove_oldstuff:
                    root.manage_delObjects([id])

                if not hasattr(rootbase, id):
                    file = open(osj(standards_home, filestr)).read()
                    id = root._setObject(id, PythonScript(id))
                    root._getOb(id).write(file)
                    t[id]="Script (Python)"

        if DestinationURL:
            msg = ''
            for k,v in t.items():
                msg = "%s (%s)\n%s"%(k,v,msg)

            url = AddParam2URL(DestinationURL,{'manage_tabs_message':\
                                "Standard objects deployed\n\n%s"%msg})
            self.REQUEST.RESPONSE.redirect(url)
        else:
            return "Standard objects deployed\n%s"%t