Exemple #1
0
def update_portal_for_z210(portal):
    """The way that the component registry and other things changed when going
    from Zope 2.9 to 2.10.  This function will migrate all aspects that it
    can migrate.
    """

    portal = aq_base(portal)
    if 'utilities' in portal.objectIds():
        for id, u in portal.utilities.objectItems():
            pieces = id.split('-')
            ifacename = pieces[0]
            name = u''
            if len(pieces) > 1:
                name = pieces[1]
            iface = None
            for checkiface in interface.providedBy(u).flattened():
                if checkiface.getName() == ifacename:
                    iface = checkiface
                    break
            if iface is not None:
                update_utility(portal, id, u, iface, name)

        if len(portal.utilities.objectIds()) == 0:
            # using ObjectManager since it doesn't do as intensive
            # security checks as PloneSite.manage_delObjects
            ObjectManager.manage_delObjects(portal, ['utilities'])
Exemple #2
0
    def importDesignFromZip(self, zip_file, replace=False):
        """Import the design from a zip file
        """
        logger.info("Start design import")
        self.setStatus(_("Importing design"))
        self.getIndex().no_refresh = True
        txn = transaction.get()
        count = 0
        total = 0
        if replace:
            logger.info("Replace mode: removing current design")
            designelements = (
                [o.id for o in self.getForms()] +
                [o.id for o in self.getViews()] +
                [o.id for o in self.getAgents()])
            ObjectManager.manage_delObjects(self, designelements)
            ObjectManager.manage_delObjects(
                self.resources,
                list(self.resources.objectIds()))
            logger.info("Current design removed")
        total_elements = None
        file_names = zip_file.namelist()
        for file_name in file_names:
            json_string = zip_file.open(file_name).read()
            if not json_string:
                # E.g. if the zipfile contains entries for directories
                continue
            design = json.loads(json_string, object_pairs_hook=OrderedDict)["design"]
            elements = design.items()
            if not total_elements:
                total_elements = len(elements)
            for (name, element) in elements:
                if name == 'dbsettings':
                    logger.info("Import db settings")
                    self.importDbSettingsFromJSON(element)
                elif name == 'resources':
                    for (res_id, res) in design['resources'].items():
                        logger.info("Import resource" + res_id)
                        self.importResourceFromJSON(
                            self.resources, res_id, res)
                else:
                    logger.info("Import " + name)
                    self.importElementFromJSON(self, name, element)
                count = count + 1
                total = total + 1
                if count == 10:
                    self.setStatus(_("Importing design (%d%%)") % int(
                        100 * total / total_elements))
                    logger.info(
                        "(%d elements committed, still running...)" % total)
                    txn.savepoint(optimistic=True)
                    count = 0

        logger.info("(%d elements imported)" % total)
        self.setStatus(_("Ready"))
        txn.commit()
        self.getIndex().no_refresh = False
Exemple #3
0
    def importDesignFromZip(self, zip_file, replace=False):
        """Import the design from a zip file
        """
        logger.info("Start design import")
        self.setStatus(_("Importing design"))
        self.getIndex().no_refresh = True
        txn = transaction.get()
        count = 0
        total = 0
        if replace:
            logger.info("Replace mode: removing current design")
            designelements = ([o.id for o in self.getForms()] +
                              [o.id for o in self.getViews()] +
                              [o.id for o in self.getAgents()])
            ObjectManager.manage_delObjects(self, designelements)
            ObjectManager.manage_delObjects(self.resources,
                                            list(self.resources.objectIds()))
            logger.info("Current design removed")
        total_elements = None
        file_names = zip_file.namelist()
        for file_name in file_names:
            json_string = zip_file.open(file_name).read()
            if not json_string:
                # E.g. if the zipfile contains entries for directories
                continue
            design = json.loads(json_string,
                                object_pairs_hook=OrderedDict)["design"]
            elements = design.items()
            if not total_elements:
                total_elements = len(elements)
            for (name, element) in elements:
                if name == 'dbsettings':
                    logger.info("Import db settings")
                    self.importDbSettingsFromJSON(element)
                elif name == 'resources':
                    for (res_id, res) in design['resources'].items():
                        logger.info("Import resource" + res_id)
                        self.importResourceFromJSON(self.resources, res_id,
                                                    res)
                else:
                    logger.info("Import " + name)
                    self.importElementFromJSON(self, name, element)
                count = count + 1
                total = total + 1
                if count == 10:
                    self.setStatus(
                        _("Importing design (%d%%)") %
                        int(100 * total / total_elements))
                    logger.info("(%d elements committed, still running...)" %
                                total)
                    txn.savepoint(optimistic=True)
                    count = 0

        logger.info("(%d elements imported)" % total)
        self.setStatus(_("Ready"))
        txn.commit()
        self.getIndex().no_refresh = False
Exemple #4
0
    def deleteDocuments(self, ids=None, massive=True):
        """ Batch delete documents from database.
        If ``massive`` is True, the ``onDelete`` formula and index
        updating are not performed (use ``refreshDB`` to update).
        """
        if ids is None:
            ids = [doc.id for doc in self.getAllDocuments()]

        if massive:
            ObjectManager.manage_delObjects(self.documents, ids)
        else:
            for id in ids:
                self.deleteDocument(self.getDocument(id))
Exemple #5
0
    def deleteDocuments(self, ids=None, massive=True):
        """ Batch delete documents from database.
        If ``massive`` is True, the ``onDelete`` formula and index
        updating are not performed (use ``refreshDB`` to update).
        """
        if ids is None:
            ids = [doc.id for doc in self.getAllDocuments()]

        if massive:
            ObjectManager.manage_delObjects(self.documents, ids)
        else:
            for id in ids:
                self.deleteDocument(self.getDocument(id))
Exemple #6
0
    def manage_delObjects(self, ids=None, uids=None, REQUEST=None):
        """Delete a subordinate object

      The objects specified in 'ids' get deleted.
      """
        if ids is None: ids = []
        if uids is None: uids = []
        if len(ids) > 0:
            # Use default method
            return ObjectManager.manage_delObjects(self, ids, REQUEST)
        if not uids:
            return MessageDialog(
                title='No items specified',
                message='No items were specified!',
                action='./manage_main',
            )
        while uids:
            uid = uids.pop()
            ob = self.getPortalObject().portal_catalog.getObject(uid)
            container = ob.aq_inner.aq_parent
            id = ob.id
            v = container._getOb(id, self)
            if v is self:
                raise BadRequest('%s does not exist' % id)
            container._delObject(id)
        if REQUEST is not None:
            return self.manage_main(self, REQUEST, update_menu=1)
Exemple #7
0
  def manage_delObjects(self, ids=None, uids=None, REQUEST=None):
      """Delete a subordinate object

      The objects specified in 'ids' get deleted.
      """
      if ids is None: ids = []
      if uids is None: uids = []
      if len(ids) > 0:
        # Use default method
        return ObjectManager.manage_delObjects(self, ids, REQUEST)
      if not uids:
          return MessageDialog(title='No items specified',
                 message='No items were specified!',
                 action ='./manage_main',)
      while uids:
          uid = uids.pop()
          ob=self.getPortalObject().portal_catalog.getObject(uid)
          container = ob.aq_inner.aq_parent
          id = ob.id
          v=container._getOb(id, self)
          if v is self:
              raise BadRequest('%s does not exist' % id)
          container._delObject(id)
      if REQUEST is not None:
              return self.manage_main(self, REQUEST, update_menu=1)
Exemple #8
0
    def deleteDocuments(self,ids=None, massive=True):
        """delete documents from database
        if massive, onDelete formula and index updating are not performed (use refreshDB to update)
        """
        if ids is None:
            ids=[doc.id for doc in self.getAllDocuments()]

        if massive:
            ObjectManager.manage_delObjects(self.documents, ids)
        else:
            for id in ids:
                try:
                    self.deleteDocument(self.getDocument(id))
                except:
                    # if insufficient access rights, we continue
                    pass
    def deleteDocuments(self, ids=None, massive=True):
        """ Batch delete documents from database.
        If ``massive`` is True, the ``onDelete`` formula and index
        updating are not performed (use ``refreshDB`` to update).
        """
        if ids is None:
            ids = [doc.id for doc in self.getAllDocuments()]

        if massive:
            ObjectManager.manage_delObjects(self.documents, ids)
        else:
            for id in ids:
                try:
                    self.deleteDocument(self.getDocument(id))
                except Exception, e:
                    # TODO: if insufficient access rights or absolutely anything else. Fix the bare except.
                    warnings.warn("Error during deletion: %s" % e)
Exemple #10
0
    def deleteDocuments(self, ids=None, massive=True):
        """ Batch delete documents from database.
        If ``massive`` is True, the ``onDelete`` formula and index
        updating are not performed (use ``refreshDB`` to update).
        """
        if ids is None:
            ids = [doc.id for doc in self.getAllDocuments()]

        if massive:
            ObjectManager.manage_delObjects(self.documents, ids)
        else:
            for id in ids:
                try:
                    self.deleteDocument(self.getDocument(id))
                except Exception, e:
                    # TODO: if insufficient access rights or absolutely anything else. Fix the bare except.
                    warnings.warn("Error during deletion: %s" % e)
Exemple #11
0
    def importDesignFromJSON(self,
                             jsonstring=None,
                             REQUEST=None,
                             from_folder=None,
                             replace=False):
        """
        """
        logger.info("Start design import")
        self.setStatus(_("Importing design"))
        self.getIndex().no_refresh = True
        txn = transaction.get()
        json_strings = []
        count = 0
        total = 0
        if from_folder:
            if not os.path.isdir(from_folder):
                raise PlominoDesignException('%s does not exist' % from_folder)
            json_files = (
                glob.glob(os.path.join(from_folder, '*.json')) +
                glob.glob(os.path.join(from_folder, 'resources/*.json')))
            total_elements = len(json_files)
            for p in json_files:
                fileobj = codecs.open(p, 'r', 'utf-8')
                json_strings.append(fileobj.read())
        else:
            if REQUEST:
                filename = REQUEST.get('filename')
                f = REQUEST.get(filename)
                cte = f.headers.get('content-transfer-encoding')
                if cte == 'base64':
                    filecontent = base64.decodestring(f.read())
                else:
                    filecontent = f.read()
                json_strings.append(asUnicode(filecontent))
            else:
                json_strings.append(asUnicode(jsonstring))
            total_elements = None

        if replace:
            logger.info("Replace mode: removing current design")
            designelements = [
                o.id
                for o in self.getForms() + self.getViews() + self.getAgents()
            ]
            ObjectManager.manage_delObjects(self, designelements)
            ObjectManager.manage_delObjects(
                self.resources,
                # Un-lazify BTree
                list(self.resources.objectIds()))
            logger.info("Current design removed")

        for jsonstring in json_strings:
            design = json.loads(jsonstring.encode('utf-8'),
                                object_pairs_hook=OrderedDict)["design"]
            elements = design.items()

            if not total_elements:
                total_elements = len(elements)

            for (name, element) in design.items():
                if name == 'dbsettings':
                    logger.info("Import db settings")
                    self.importDbSettingsFromJSON(element)
                elif name == 'resources':
                    for (res_id, res) in design['resources'].items():
                        logger.info("Import resource" + res_id)
                        self.importResourceFromJSON(self.resources, res_id,
                                                    res)
                else:
                    logger.info("Import " + name)
                    self.importElementFromJSON(self, name, element)
                count = count + 1
                total = total + 1
                if count == 10:
                    self.setStatus(
                        _("Importing design (%d%%)") %
                        int(100 * total / total_elements))
                    logger.info("(%d elements committed, still running...)" %
                                total)
                    txn.savepoint(optimistic=True)
                    count = 0

        logger.info("(%d elements imported)" % total)
        self.setStatus(_("Ready"))
        txn.commit()
        self.getIndex().no_refresh = False
Exemple #12
0
    def importDesignFromJSON(self, jsonstring=None, REQUEST=None,
            from_folder=None, replace=False):
        """
        """
        logger.info("Start design import")
        self.setStatus(_("Importing design"))
        self.getIndex().no_refresh = True
        txn = transaction.get()
        json_strings = []
        count = 0
        total = 0
        if from_folder:
            if not os.path.isdir(from_folder):
                raise PlominoDesignException('%s does not exist' % from_folder)
            json_files = (glob.glob(os.path.join(from_folder, '*.json')) +
                glob.glob(os.path.join(from_folder, 'resources/*.json')))
            total_elements = len(json_files)
            for p in json_files:
                fileobj = codecs.open(p, 'r', 'utf-8')
                json_strings.append(fileobj.read())
        else:
            if REQUEST:
                filename = REQUEST.get('filename')
                f = REQUEST.get(filename)
                cte = f.headers.get('content-transfer-encoding')
                if cte == 'base64':
                    filecontent = base64.decodestring(f.read())
                else:
                    filecontent = f.read()
                json_strings.append(asUnicode(filecontent))
            else:
                json_strings.append(asUnicode(jsonstring))
            total_elements = None

        if replace:
            logger.info("Replace mode: removing current design")
            designelements = [o.id for o in
                    self.getForms() +
                    self.getViews() +
                    self.getAgents()]
            ObjectManager.manage_delObjects(self, designelements)
            ObjectManager.manage_delObjects(
                self.resources,
                # Un-lazify BTree
                list(self.resources.objectIds()))
            logger.info("Current design removed")

        for jsonstring in json_strings:
            design = json.loads(jsonstring.encode('utf-8'), object_pairs_hook=OrderedDict)["design"]
            elements = design.items()

            if not total_elements:
                total_elements = len(elements)

            for (name, element) in design.items():
                if name == 'dbsettings':
                    logger.info("Import db settings")
                    self.importDbSettingsFromJSON(element)
                elif name == 'resources':
                    for (res_id, res) in design['resources'].items():
                        logger.info("Import resource" + res_id)
                        self.importResourceFromJSON(
                            self.resources, res_id, res)
                else:
                    logger.info("Import " + name)
                    self.importElementFromJSON(self, name, element)
                count = count + 1
                total = total + 1
                if count == 10:
                    self.setStatus(
                        _("Importing design (%d%%)") % int(
                            100 * total / total_elements))
                    logger.info(
                        "(%d elements committed, still running...)" % total)
                    txn.savepoint(optimistic=True)
                    count = 0

        logger.info("(%d elements imported)" % total)
        self.setStatus(_("Ready"))
        txn.commit()
        self.getIndex().no_refresh = False
    def importDesignFromXML(self,
                            xmlstring=None,
                            REQUEST=None,
                            from_folder=None,
                            replace=False):
        """
        """
        logger.info("Start design import")
        self.setStatus("Importing design")
        self.getIndex().no_refresh = True
        txn = transaction.get()
        xml_strings = []
        count = 0
        total = 0
        if from_folder:
            if not os.path.isdir(from_folder):
                raise PlominoDesignException, '%s does not exist' % path
            xml_files = (
                glob.glob(os.path.join(from_folder, '*.xml')) +
                glob.glob(os.path.join(from_folder, 'resources/*.xml')))
            total_elements = len(xml_files)
            for p in xml_files:
                fileobj = codecs.open(p, 'r', 'utf-8')
                xml_strings.append(fileobj.read())
        else:
            if REQUEST:
                f = REQUEST.get("file")
                xml_strings.append(asUnicode(f.read()))
            else:
                xml_strings.append(asUnicode(xmlstring))
            total_elements = None

        if replace:
            logger.info("Replace mode: removing current design")
            designelements = [o.id for o in self.getForms()] \
                                 + [o.id for o in self.getViews()] \
                                 + [o.id for o in self.getAgents()]
            ObjectManager.manage_delObjects(self, designelements)
            ObjectManager.manage_delObjects(self.resources,
                                            self.resources.objectIds())
            logger.info("Current design removed")

        for xmlstring in xml_strings:
            xmlstring = xmlstring.replace(">\n<", "><")
            xmldoc = parseString(xmlstring.encode('utf-8'))
            design = xmldoc.getElementsByTagName("design")[0]
            elements = [
                e for e in design.childNodes
                if e.nodeName in ('resource', 'element', 'dbsettings')
            ]

            if not total_elements:
                total_elements = len(elements)

            e = design.firstChild
            while e is not None:
                name = str(e.nodeName)
                if name in ('resource', 'element', 'dbsettings'):
                    if name == 'dbsettings':
                        logger.info("Import db settings")
                        self.importDbSettingsFromXML(e)
                    if name == 'element':
                        logger.info("Import " + e.getAttribute('id'))
                        self.importElementFromXML(self, e)
                    if name == 'resource':
                        logger.info("Import resource " + e.getAttribute('id'))
                        self.importResourceFromXML(self.resources, e)
                    count = count + 1
                    total = total + 1
                if count == 10:
                    self.setStatus("Importing design (%d%%)" %
                                   int(100 * total / total_elements))
                    logger.info("(%d elements committed, still running...)" %
                                total)
                    txn.savepoint(optimistic=True)
                    count = 0
                e = e.nextSibling

        logger.info("(%d elements imported)" % total)
        self.setStatus("Ready")
        txn.commit()
        self.getIndex().no_refresh = False