Exemplo n.º 1
0
 def test_walk_empty(self):
     """Test walk_silva_tree on an empty tree.
     """
     self.assertEqual(
         list(walk_silva_tree(self.root)),
         [self.root])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContainer)),
         [self.root])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContent)),
         [])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContent, version=True)),
         [])
Exemplo n.º 2
0
 def get_selected_contents(self, key='content', recursive=False):
     for content in self.get_contents(self.request.form.get(key)):
         if recursive and IContainer.providedBy(content):
             for content in walk_silva_tree(content):
                 yield content
         else:
             yield content
Exemplo n.º 3
0
    def run(self, root, options):
        if options.keep < 1:
            fail("You need to keep at least one version")
        logger.info('Removing old versions ...')
        removed = 0
        count = 0
        for count, content in enumerate(walk_silva_tree(root)):
            if not IVersionedContent.providedBy(content):
                continue
            versions = content._previous_versions
            if not versions:
                continue
            if count and count % 500 == 0:
                # Commit now and when
                transaction.commit()

            removable_versions = versions[:-options.keep]
            content._previous_versions = versions[-options.keep:]

            contained_ids = content.objectIds()
            removable_version_ids = set([
                str(version[0]) for version in removable_versions
                if version[0] in contained_ids])
            removed += len(removable_version_ids)

            content.manage_delObjects(list(removable_version_ids))

            if removed and removed % 500 == 0:
                logger.info('Removed %d versions, continuing ...' % removed)
        if removed:
            logger.info('Removed %d versions in total' % removed)
            transaction.commit()
        else:
            logger.info('Nothing removed')
Exemplo n.º 4
0
 def build(self, root=None):
     self.cleanup()
     root = root or self.get_root()
     intids = getUtility(IIntIds)
     count = 0
     for (index, ob,) in enumerate(walk_silva_tree(root)):
         if self.index_object(ob, intids): count += 1
     return count
Exemplo n.º 5
0
 def update_silva_contents(self, mapping, updaters, do_version=False):
     if not updaters:
         return []
     changes = [0] * len(updaters)
     for content in walk_silva_tree(self.context.get_root(), version=do_version):
         for index, updater in enumerate(updaters):
             changes[index] += updater(mapping, content)
     return changes
Exemplo n.º 6
0
def index_content(parent, reindex=False):
    """Recursively index or index Silva Content.
    """
    count = 0
    for count, content in enumerate(walk_silva_tree(parent)):
        if count and count % 500 == 0:
            transaction.commit()
            logger.info('indexing: %d objects indexed' % count)
        if reindex:
            ICataloging(content).reindex()
        else:
            ICataloging(content).index()
    logger.info('catalog indexing: %d objects indexed' % count)
Exemplo n.º 7
0
def index_content(parent, reindex=False):
    """Recursively index or index Silva Content.
    """
    count = 0
    for count, content in enumerate(walk_silva_tree(parent)):
        if count and count % 500 == 0:
            transaction.commit()
            logger.info('indexing: %d objects indexed' % count)
        if reindex:
            ICataloging(content).reindex()
        else:
            ICataloging(content).index()
    logger.info('catalog indexing: %d objects indexed' % count)
Exemplo n.º 8
0
 def test_walk(self):
     """Test walk_silva_tree with some interfaces.
     """
     self.assertEqual(
         list(walk_silva_tree(self.root)),
         [self.root,
          self.root.folder,
          self.root.publication,
          self.root.publication.toc,
          self.root.publication.folder,
          self.root.publication.contact,
          self.root.publication.location,
          self.root.information])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContainer)),
         [self.root,
          self.root.folder,
          self.root.publication,
          self.root.publication.folder])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContent)),
         [self.root.publication.toc,
          self.root.publication.contact,
          self.root.publication.location,
          self.root.information])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IContent, version=True)),
         [self.root.publication.toc,
          self.root.publication.contact,
          self.root.publication.contact.get_editable(),
          self.root.publication.location,
          self.root.publication.location.get_editable(),
          self.root.information,
          self.root.information.get_editable()])
     self.assertEqual(
         list(walk_silva_tree(self.root, requires=IVersion, version=True)),
         [self.root.publication.contact.get_editable(),
          self.root.publication.location.get_editable(),
          self.root.information.get_editable()])
Exemplo n.º 9
0
def purge_old_versions(parent):
    count = 0
    for count, content in enumerate(walk_silva_tree(parent)):
        if not interfaces.IVersionedContent.providedBy(content):
            continue
        versions = content._previous_versions
        if not versions:
            continue
        if count and count % 500 == 0:
            # Commit now and when
            transaction.commit()

        removable_versions = versions[:-1]
        content._previous_versions = versions[-1:]

        contained_ids = content.objectIds()
        removable_version_ids = set([
            str(version[0]) for version in removable_versions
            if version[0] in contained_ids])

        content.manage_delObjects(list(removable_version_ids))
    def export(self):
        values, errors = self.extractData()
        if errors:
            return silvaforms.FAILURE
        exported = []
        extension_name = values['extension_name']
        if ':' in extension_name:
            extension_name, entry_name = extension_name.split(':', 1)
        extension = pkg_resources.working_set.by_key[extension_name]
        directory = os.path.dirname(extension.load_entry_point(
            'Products.SilvaExternalSources.sources', entry_name).__file__)

        if values['recursive']:
            sources = walk_silva_tree(self.context, requires=ICodeSource)
        else:
            sources = self.context.objectValues('Silva Code Source')

        for source in sources:
            if source.meta_type != 'Silva Code Source':
                continue
            identifier = source.getId()
            target = os.path.join(directory, identifier)
            location = (
                extension.project_name + ':' +
                target[len(extension.location):])

            if source.get_fs_location() not in (None, location):
                continue
            if not os.path.exists(target):
                os.makedirs(target)
            source._fs_location = location
            installable = CodeSourceInstallable(location, target)
            installable.export(source)
            exported.append(location)
        if exported:
            self.status = 'Exported: {0}.'.format(', '.join(exported))
        else:
            self.status = 'Nothing exported.'
        return silvaforms.SUCCESS
Exemplo n.º 11
0
def purge_old_versions(parent):
    count = 0
    for count, content in enumerate(walk_silva_tree(parent)):
        if not interfaces.IVersionedContent.providedBy(content):
            continue
        versions = content._previous_versions
        if not versions:
            continue
        if count and count % 500 == 0:
            # Commit now and when
            transaction.commit()

        removable_versions = versions[:-1]
        content._previous_versions = versions[-1:]

        contained_ids = content.objectIds()
        removable_version_ids = set([
            str(version[0]) for version in removable_versions
            if version[0] in contained_ids
        ])

        content.manage_delObjects(list(removable_version_ids))
Exemplo n.º 12
0
    def export(self):
        values, errors = self.extractData()
        if errors:
            return silvaforms.FAILURE
        exported = []
        extension_name = values['extension_name']
        if ':' in extension_name:
            extension_name, entry_name = extension_name.split(':', 1)
        extension = pkg_resources.working_set.by_key[extension_name]
        directory = os.path.dirname(
            extension.load_entry_point('Products.SilvaExternalSources.sources',
                                       entry_name).__file__)

        if values['recursive']:
            sources = walk_silva_tree(self.context, requires=ICodeSource)
        else:
            sources = self.context.objectValues('Silva Code Source')

        for source in sources:
            if source.meta_type != 'Silva Code Source':
                continue
            identifier = source.getId()
            target = os.path.join(directory, identifier)
            location = (extension.project_name + ':' +
                        target[len(extension.location):])

            if source.get_fs_location() not in (None, location):
                continue
            if not os.path.exists(target):
                os.makedirs(target)
            source._fs_location = location
            installable = CodeSourceInstallable(location, target)
            installable.export(source)
            exported.append(location)
        if exported:
            self.status = 'Exported: {0}.'.format(', '.join(exported))
        else:
            self.status = 'Nothing exported.'
        return silvaforms.SUCCESS
Exemplo n.º 13
0
 def get_contents(self):
     return walk_silva_tree(self.root, requires=IPublishable)
Exemplo n.º 14
0
 def build(self):
     self._excluded_contents = TupleMap()
     for container in walk_silva_tree(self.get_root(), requires=IContainer):
         self.index_content_access(container)
Exemplo n.º 15
0
 def references(self):
     service = getUtility(IReferenceService)
     producer = service.get_references_from
     for content in walk_silva_tree(self.context, version=True):
         for reference in producer(content):
             yield reference
Exemplo n.º 16
0
 def find_installed_sources(self):
     logger.info('search for code sources')
     self.clear_installed_sources()
     service = getUtility(IIntIds)
     for source in walk_silva_tree(self.get_root(), requires=ICodeSource):
         self._installed_sources.append(service.register(source))
 def find_installed_sources(self):
     logger.info('search for code sources')
     self.clear_installed_sources()
     service = getUtility(IIntIds)
     for source in walk_silva_tree(self.get_root(), requires=ICodeSource):
         self._installed_sources.append(service.register(source))