Beispiel #1
0
    def update(self):
        parser = AtomisatorConfig(CONFIG)
        # getting parameters for the rss output
        file_, link, title, description = self._get_values(parser)

        # TODO make atomisator cfg file read/writeable by text
        # to avoid all this crappy parsing
        _get = request.GET.get
        title = _get('title', title)
        link = _get('link', link)
        description = _get('description', description)
        self._set_values(parser, file_, link, title, description)

        parser.database = _get('database', parser.database)

        current = [
            '%s %s'.strip() % (p[0], ' '.join(p[1])) for p in parser.filters
        ]

        filters = _get('filters', '\n'.join(current))
        filters = [
            f for f in [s.strip() for s in filters.split('\n')] if f != ''
        ]
        filters = [(u[0], tuple(u[1:])) for u in [f.split() for f in filters]]
        if filters != parser.filters:
            parser.filters = filters

        current = [
            '%s %s'.strip() % (p[0], ' '.join(p[1])) for p in parser.enhancers
        ]

        enhancers = _get('enhancers', '\n'.join(current))
        enhancers = [
            f for f in [s.strip() for s in enhancers.split('\n')] if f != ''
        ]
        enhancers = [(u[0], tuple(u[1:]))
                     for u in [f.split() for f in enhancers]]

        if enhancers != parser.enhancers:
            parser.enhancers = enhancers

        current = [
            '%s %s'.strip() % (p[0], ' '.join(p[1])) for p in parser.sources
        ]
        sources = _get('sources', '\n'.join(current))
        sources = [
            f for f in [s.strip() for s in sources.split('\n')] if f != ''
        ]
        sources = [(u[0], tuple(u[1:])) for u in [f.split() for f in sources]]

        parser.sources = sources
        parser.write()
        redirect_to(action='index')
Beispiel #2
0
def test_config():
    parser = AtomisatorConfig(cfg)
    s = parser.sources
    waited = [('rss', ('gdigg.xml', )), ('rss', ('gtarek.xml', )),
              ('rss', ('gpp.xml', )), ('rss', ('gdigg.xml', )),
              ('rss', ('gtarek.xml', )), ('rss', ('gpp.xml', ))]

    assert_equals(s, waited)
    parser.sources = (('rss', ('ok.xml', )), )
    assert_equals(parser.sources, [('rss', (u'ok.xml', ))])

    assert_equals(parser.database, 'sqlite:///gatomisator.db')
    parser.database = 'sqlite://here'
    assert_equals(parser.database, 'sqlite://here')

    assert_equals(parser.timeout, 5.0)
    parser.timeout = 7.0
    assert_equals(parser.timeout, 7.0)

    assert_equals(parser.store_entries, True)
    parser.store_entries = False
    assert_equals(parser.store_entries, False)

    assert_equals(parser.max_age, 30)
    parser.max_age = 35
    assert_equals(parser.max_age, 35)

    old = open(cfg).read()
    parser.write()
    new = open(cfg).read()
    assert new != old

    open(cfg, 'w').write(old)

    assert_equals(parser.processes, PROCESSES)
    parser.processes = 1
    assert_equals(parser.processes, 1)