Ejemplo n.º 1
0
    def getPossibleConverters(self):
        """Get a Dictionary ot available Converters."""
        try:
            diagramTypes = Registry.getKind(self.graphname()).registration()
        except RuntimeError:
            diagramTypes = []
        ret = [{
            'name':
            ' ',
            'sources': [{
                'name': ' ',
                'converters': [{
                    'name': _useDefaultConverter
                }]
            }]
        }]

        for dt in diagramTypes:
            sources = []
            for source in ICRegistry.getSources(dt.name):
                converters = [{
                    'name': conv
                } for conv in ICRegistry.getConverters(dt.name, source)]
                sources.append({'name': source, 'converters': converters})
            ret.append({'name': dt.name, 'sources': sources})
        return ret
Ejemplo n.º 2
0
def registerConverters(module):
    """Registers all input converters found in the given module."""
    for attrib in dir(module):
        try:
            potentialCoverter = getattr(module, attrib)
            if IInputConverter.isImplementedByInstancesOf(potentialCoverter):
                ICRegistry.register(potentialCoverter)
        except TypeError:
            pass
Ejemplo n.º 3
0
    def having_errors(self, whichTests='all'):
        """Test if we have errors.

        e.g. conflicts between diagramKind and converter
        """
        if whichTests == 'all':
            if self.current_version < self.version:
                return "Diagram is older than SVGrafZ-Product. \
                Please update the diagram as described in doc/update.txt"

            if self.current_version > self.version:
                return "Diagram is newer than SVGrafZ-Product. \
                Please update your SVGrafZ-Product to the latest version."

        diagramTypesOfConverter = ICRegistry.getConverter(
            self.convertername()).registration().keys()

        try:
            for diagramType in Registry.getKind(
                    self.graphname()).registration():
                if diagramType in diagramTypesOfConverter:
                    return False
        except RuntimeError:
            return "DiagramKind does not exist any more.\
            Please choose another."

        return "DiagramKind and Converter are incompatible. \
Ejemplo n.º 4
0
    def test_2register_get_Type(self):
        """Test _registerType(type) and getTypes()."""
        n = NoDiagramType
        a = DiagramType1
        b = DiagramType1
        c = DiagramType2

        ICRegistry._clear()  # remove filling of __init__.py
        self.assertRaises(RuntimeError, ICRegistry._registerType, n)
        self.failUnless(ICRegistry._registerType(a), 'register type1')
        self.failIf(ICRegistry._registerType(a), 'register type1 second time')
        self.failIf(ICRegistry._registerType(b), 'register type1 third time')

        self.assertEqual([a.name], ICRegistry.getTypes())
        self.failUnless(ICRegistry._registerType(c), 'register type2')
        self.assertEqual([a.name, c.name], ICRegistry.getTypes())
Ejemplo n.º 5
0
    def test_3_clear(self):
        """Test of _clear()."""
        a = DiagramType1

        self.failIf(ICRegistry._clear(), '1st clear')
        self.assertEqual([], ICRegistry.getTypes(), '1st get')
        self.failUnless(ICRegistry._registerType(a), 'register type1')
        self.assertEqual([a.name], ICRegistry.getTypes(), '2nd get')
        self.failIf(ICRegistry._clear(), '2nd clear')
        self.assertEqual([], ICRegistry.getTypes(), '3rd get')
Ejemplo n.º 6
0
    def test_8getDefaultConverterName(self):
        """Test getDefaultConverterName()."""

        c1 = Converter1  # empty converter
        c4 = Converter4  # default converter
        c5 = Converter5
        c6 = Converter6  # second default
        c7 = Converter7

        ICRegistry._clear()

        self.assertNone(ICRegistry.getDefaultConverterName(), 'empty reg')
        self.failUnless(ICRegistry.register(c1))
        self.assertNone(ICRegistry.getDefaultConverterName(), 'empty reg 2nd')
        self.failUnless(ICRegistry.register(c5))
        self.assertNone(ICRegistry.getDefaultConverterName(), 'no default')
        self.failUnless(ICRegistry.register(c4))
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default')
        self.assertRaises(RuntimeError, ICRegistry.register,
                          c6)  #second default
        self.assertNone(ICRegistry.getConverter(c6.name), 'get 2nd default')
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default 2')
        self.failUnless(ICRegistry.register(c7))
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default 3')
Ejemplo n.º 7
0
    def test_7getConverter(self):
        """Test getConverter(converterName)."""
        c1 = Converter1
        c4 = Converter4

        ICRegistry._clear()
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 1st')
        self.assertNone(ICRegistry.getConverter(c4.name), 'get c4 1st')
        self.failUnless(ICRegistry.register(c1))
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 2nd')
        self.assertNone(ICRegistry.getConverter(c4.name), 'get c4 2nd')
        self.failUnless(ICRegistry.register(c4))
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 3rd')
        self.assertEqual(
            c4().__class__,
            ICRegistry.getConverter(c4.name).__class__,
            'get c4 3rd (%s != %s)' %
            (c4().__class__, ICRegistry.getConverter(c4.name).__class__))
Ejemplo n.º 8
0
    def test_6register(self):
        """Test register(converter)."""
        d1 = DiagramType1.name
        d2 = DiagramType2.name
        s1 = DataSource1.name
        s2 = DataSource2.name
        n = NoConverter
        c1 = Converter1
        c2 = Converter2
        c3 = Converter3
        c4 = Converter4
        c42 = Converter4
        c5 = Converter5

        ICRegistry._clear()
        self.assertRaises(RuntimeError, ICRegistry.register, n)
        self.failUnless(ICRegistry.register(c1), 'reg c1')
        self.assertEqual([], ICRegistry.getTypes(), 'get c1')
        self.assertRaises(RuntimeError, ICRegistry.register, c2)
        self.assertRaises(RuntimeError, ICRegistry.register, c3)
        self.failUnless(ICRegistry.register(c4), 'reg c4')
        self.assertEqual([d1], ICRegistry.getTypes(), 'get c4 typ')
        self.assertEqual([s1], ICRegistry.getSources(d1), 'get c4 src')
        self.assertEqual([c4.name], ICRegistry.getConverters(d1, s1),
                         'get c4 conv')
        self.assertRaises(RuntimeError, ICRegistry.register, c4)
        self.assertRaises(RuntimeError, ICRegistry.register, c42)
        self.assertEqual([d1], ICRegistry.getTypes(), 'get c4 typ 3rd')
        self.assertEqual([s1], ICRegistry.getSources(d1), 'get c4 src 3rd')
        self.assertEqual([c4.name], ICRegistry.getConverters(d1, s1),
                         'get c4 conv 3rd')
        self.failUnless(ICRegistry.register(c5), 'reg c5')
        self.assertEqual([d1, d2], ICRegistry.getTypes(), 'get c5 typ')
        res = ICRegistry.getSources(d1)
        res.sort()
        self.assertEqual([s1, s2], res, 'get c5 d1 src')
        self.assertEqual([s2], ICRegistry.getSources(d2), 'get c5 d2 src')
        self.assertEqual([c4.name, c5.name], ICRegistry.getConverters(d1, s1),
                         'get c5 d1s1 conv')
        self.assertEqual([c5.name], ICRegistry.getConverters(d1, s2),
                         'get c5 d1s2 conv')
Ejemplo n.º 9
0
    def test_5_registerConverter(self):
        """Test _registerConverter(...) and getConverters(...)."""
        d1 = DiagramType1
        d2 = DiagramType2
        s1 = DataSource1
        s2 = DataSource2
        n = NoConverter
        a = Converter1
        b = Converter1
        c = Converter2

        ICRegistry._clear()
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty reg')
        self.failUnless(ICRegistry._registerType(d1))
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty type')
        self.failUnless(ICRegistry._registerSource(d1, s1))
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty src')
        self.assertRaises(RuntimeError, ICRegistry._registerConverter, d2, s1,
                          n)
        self.failUnless(ICRegistry._registerConverter(d2, s1, a), 'reg 21a')
        self.failIf(ICRegistry._registerConverter(d2, s1, a), 'reg 21a 2nd')
        self.failIf(ICRegistry._registerConverter(d2, s1, b), 'reg 21a 3rd')
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty src2')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 2nd')
        self.failUnless(ICRegistry._registerConverter(d2, s2, a), 'reg 22a')
        self.failIf(ICRegistry._registerConverter(d2, s2, a), 'reg 22a 2nd')
        self.failUnless(ICRegistry._registerConverter(d1, s2, a), 'reg 12a')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 3rd')
        self.failUnless(ICRegistry._registerConverter(d2, s1, c), 'reg 21c')
        self.assertEqual([a.name, c.name],
                         ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 4th')
        self.assertEqual([a.name], ICRegistry.getConverters(d1.name, s2.name),
                         'get 12')
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get 11')
Ejemplo n.º 10
0
    def test_4_registerSource(self):
        """Test of _registerSource(...) and getSource(...)"""
        d = DiagramType1
        e = DiagramType2
        n = NoDataSource
        a = DataSource1
        b = DataSource1
        c = DataSource2

        ICRegistry._clear()

        self.assertEqual([], ICRegistry.getSources(d.name),
                         'get from empty Registry')
        self.failUnless(ICRegistry._registerType(d))
        self.assertEqual([], ICRegistry.getSources(d.name),
                         'get from empty Type')
        self.assertEqual([], ICRegistry.getSources(e.name),
                         'get from not registered Type')
        self.assertRaises(RuntimeError, ICRegistry._registerSource, d, n)
        self.failUnless(ICRegistry._registerSource(d, a), 'reg one')
        self.failIf(ICRegistry._registerSource(d, a), 'reg one 2nd time')
        self.failIf(ICRegistry._registerSource(d, b), 'reg one 3rd time')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one2')
        self.assertEqual([], ICRegistry.getSources(e.name),
                         'get not registered Type 2')
        self.failUnless(ICRegistry._registerSource(e, a), 'reg two two')
        self.failIf(ICRegistry._registerSource(e, a), 'reg two two 2nd')
        self.failIf(ICRegistry._registerSource(e, b), 'reg two two 3rd')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two2')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one3')
        self.failUnless(ICRegistry._registerSource(d, c), 'reg tri')
        self.failIf(ICRegistry._registerSource(d, c), 'reg tri 2nd')
        res1 = ICRegistry.getSources(d.name)
        res1.sort()
        self.assertEqual([a.name, c.name], res1, 'get tri %s' % res1)
        res2 = ICRegistry.getSources(d.name)
        res2.sort()
        self.assertEqual([a.name, c.name], res2, 'get tri2')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two3')
Ejemplo n.º 11
0
 def viewInputConverterDesription(self):
     return self._list2dictlist(
         ICRegistry.getConverter(self.convertername()).description())
Ejemplo n.º 12
0
    def __call__(self, client=None, REQUEST={}):
        """Render the diagram."""
        graphClass = Registry.getKind(self.graphname())
        current = self.getPropertyValues()
        outputConverter, dummy = self._getOutputConverter()
        inputConverter = ICRegistry.getConverter(current['convertername'])
        errortext = legend = colnames = stylesheet = data = title = None

        if current['data'].getExpression() is None:
            errortext = "You did not enter a DataSource, so can't display anything."
        else:
            try:
                data = self.getValue(current['data'])
                try:
                    data = inputConverter.convert(data, current['fixcolumn'])
                except RuntimeError:
                    errortext = str(exc_info()[1])
                except (AttributeError, KeyError, CompilerError):
                    errortext = 'DataSource "%s" is not existing.' % (
                        current['data'])
            except RuntimeError:
                errortext = str(exc_info()[1])
        try:
            legend = self.getValue(current['legend'])
        except (AttributeError, KeyError, CompilerError):
            errortext = 'Legend "%s" is not existing.' % (current['legend'])

        if legend == 'converter':
            if IInputConverterWithLegend.isImplementedBy(inputConverter):
                legend = inputConverter.legend(
                )  # cause convert is already done
            else:
                errortext = "DataConverter '%s' can't be used with '%s'." % (
                    current['convertername'], 'string:converter')
        try:
            colnames = self.getValue(current['colnames'])
        except (AttributeError, KeyError, CompilerError):
            errortext = 'ColumnNames "%s" do not exist.' % (
                current['colnames'])

        if current['stylesheet']:
            try:
                stylesheet = getattr(self, current['stylesheet'])
                stylesheet = outputConverter.getStyleSheetURL(stylesheet)
            except AttributeError:
                errortext = 'Stylesheet "%s" is not existing.' % (
                    current['stylesheet'])
        try:
            title = self.getValue(current['taltitle'])
        except (AttributeError, KeyError, CompilerError, RuntimeError):
            errortext = '"Title with TALES" has Errors.'
        if title is None:
            title = current['title'] or ''

        otherParams = {
            'gridlines': current['gridlines'],
            'height': current['height'],
            'width': current['width'],
            'intcaption': current['intcaption'],
            'fillgaps': current['fillgaps'],
        }
        graph = graphClass(data=data,
                           legend=legend,
                           colnames=colnames,
                           title=title,
                           stylesheet=stylesheet,
                           otherParams=otherParams,
                           errortext=errortext)
        graph.setSpecialAttrib(current['specialattrib'])
        if REQUEST.RESPONSE:
            outputConverter.setHTTPHeaders(
                REQUEST.RESPONSE,
                title.replace(' ', '_') or 'unnamed')
        outputConverter.setSourceData(graph.compute().encode('UTF-8'))
        if not outputConverter.convert():
            return outputConverter.getErrorResult()
        else:
            return outputConverter.getResultData()
Ejemplo n.º 13
0
 def convertername(self, default=None):
     "get convertername."
     return self.getAttribute('convertername',
                              ICRegistry.getDefaultConverterName(), default)