コード例 #1
0
 def _clear_export_files(self):
     login(self.layer['app'], SITE_OWNER_NAME)
     exporters = [factory() for name, factory in
                  getFactoriesFor(IRecensioExporter)]
     for exporter in exporters:
         old_export_file = self.portal.get(exporter.export_filename)
         if old_export_file:
             api.content.delete(old_export_file)
     login(self.portal, TEST_USER_NAME)
コード例 #2
0
ファイル: export.py プロジェクト: syslabcom/recensio.policy
    def __call__(self):
        log.info('Starting export')
        annotations = IAnnotations(self.context)
        if self.request.get('force', False):
            del annotations[EXPORT_TIMESTAMP_KEY]
        timestamp = annotations.get(EXPORT_TIMESTAMP_KEY, 0)
        if time() - timestamp < 2 * 60 * 60:  # 2 hours
            log.info('export already running, abort')
            return 'An export is already running, aborting'

        annotations[EXPORT_TIMESTAMP_KEY] = time()
        transaction.commit()

        try:
            exporters = [(name, factory()) for name, factory in
                        getFactoriesFor(IRecensioExporter)]
            exporters_to_run = [(name, e) for name, e in exporters
                                if e.needs_to_run()]
        except Exception as e:
            log.exception(e)
            del annotations[EXPORT_TIMESTAMP_KEY]
            msg = 'Error, aborting export: ' + str(e)
            log.error(msg)
            return msg

        if not exporters_to_run:
            del annotations[EXPORT_TIMESTAMP_KEY]
            log.info('export finished, nothing to do')
            return 'Nothing to do, no exporter requested an export run.'

        for issue_or_volume in self.issues_and_volumes():
            for review in self.reviews(issue_or_volume):
                for name, exporter in exporters_to_run:
                    try:
                        exporter.add_review(review)
                    except Exception as e:
                        log.error('Error in {0} - {1}: {2}'.format(
                            review.getId(), e.__class__.__name__, e))
            # Free memory after every issue and volume
            transaction.commit()
        statuses = []
        for name, exporter in exporters_to_run:
            try:
                status = exporter.export()
                statuses.append((name, status))
            except Exception as e:
                log.error('Error in {0} - {1}: {2}'.format(
                    name, e.__class__.__name__, e))

        del annotations[EXPORT_TIMESTAMP_KEY]
        transaction.commit()
        log.info('export finished')

        return '<br />\n'.join(
            [name + ': ' + str(status) for name, status in statuses])
コード例 #3
0
 def getDefaultContent(self):
     for name, factory in component.getFactoriesFor(self.group_obj.schema):
         if name == 'highlightdata':
             return factory()
コード例 #4
0
 def _callFUT(self, *args, **kw):
     from zope.component import getFactoriesFor
     return getFactoriesFor(*args, **kw)
コード例 #5
0
        print "%s is a jerk!" % (self.other)
    

# utilities
hello = Greeter()
goodbye = Greeter2()
        
component.provideUtility(hello, IGreeter, 'hello')
component.provideUtility(goodbye, IGreeter, 'goodbye')

utilities = component.getAllUtilitiesRegisteredFor(IGreeter)


# factories - this looks like the best way to proceed with registering
# renderers.
factory = Factory(Greeter, 'Greeter', 'Greeter Class, says hello')
factory2 = Factory(Greeter2, 'Greeter2', 'Greeter Class, says goodbye')

component.provideUtility(factory, IFactory, 'hello1')
component.provideUtility(factory2, IFactory, 'hello2')

factories = component.getFactoriesFor(IGreeter)

# adapters - no love
component.provideAdapter(
    factory=RudeGreeter,
    adapts=[IRudeGreeter],
    provides=IGreeter)


コード例 #6
0
ファイル: vocabulary.py プロジェクト: ilshad/tackle
def content_factories(context):
    terms = []
    for name, factory in getFactoriesFor(IContent):
        terms.append(SimpleTerm(name, title=factory.title))
    return SimpleVocabulary(terms)