Ejemplo n.º 1
0
    def execute(cls, options):
        options = cls.handle_options(options)

        try:
            if options.extract:
                MySQLExtractor(options).extract()
            if options.load:
                MediawikiLoader(options).load()
        finally:
            if not options.keep_dumps:
                shutil.rmtree(options.dump_dir)
Ejemplo n.º 2
0
    def setUp(self):
        setup_basic_test()
        self.options = mock.Mock()
        self.options.dump_dir = os.path.join(g.tmpdir, 'w2m_test')

        # monkey-patch MySQLExtractor for test
        def pages(self):
            yield {'page_id': 1, 'title': 'Test title'}
            yield {'page_id': 2, 'title': 'Main_Page'}
            yield {'page_id': 3, 'title': 'Test'}

        def history(self, page_id):
            data = {
                1: [{
                    'timestamp': 1,
                    'text': "Test",
                    'username': '******'
                }, {
                    'timestamp': 2,
                    'text': "Test Text",
                    'username': '******'
                }],
                2: [{
                    'timestamp': 1,
                    'text': "Main_Page",
                    'username': '******'
                }, {
                    'timestamp': 2,
                    'text': "Main_Page text",
                    'username': '******'
                }],
                3: [{
                    'timestamp': 1,
                    'text': "Some test text",
                    'username': ''
                }, {
                    'timestamp': 2,
                    'text': "",
                    'username': ''
                }]
            }
            revisions = data[page_id]
            for rev in revisions:
                yield rev

        def talk(self, page_title):
            return {
                'text': 'Talk for page %s.' % page_title,
                'timestamp': 1,
                'username': '******'
            }

        def attachments(self, *args, **kwargs):
            # make 'empty' iterator
            if False:
                yield

        MySQLExtractor._pages = pages
        MySQLExtractor._history = history
        MySQLExtractor._talk = talk
        MySQLExtractor._attachments = attachments
        self.extractor = MySQLExtractor(self.options)