def load_pages(self): """Load pages with edit history from json to Allura wiki tool""" allura_base.log.info('Loading pages into allura...') for page_dir in self._pages(): for page in self._history(page_dir): p = WM.Page.upsert(page['title']) p.viewable_by = ['all'] p.text = mediawiki_internal_links2markdown( mediawiki2markdown(page['text']), page['title']) timestamp = datetime.datetime.strptime(page['timestamp'], self.TIMESTAMP_FMT) p.mod_date = timestamp c.user = (M.User.query.get(username=page['username'].lower()) or M.User.anonymous()) ss = p.commit() ss.mod_date = ss.timestamp = timestamp # set home to main page if page['title'] == 'Main_Page': gl = WM.Globals.query.get(app_config_id=self.wiki.config._id) if gl is not None: gl.root = page['title'] allura_base.log.info('Loaded history of page %s (%s)' % (page['page_id'], page['title'])) self.load_talk(page_dir, page['title']) self.load_attachments(page_dir, page['title'])
def load_pages(self): """Load pages with edit history from json to Allura wiki tool""" log.info('Loading pages into allura...') for page_dir in self._pages(): for page in self._history(page_dir): p = WM.Page.upsert(page['title']) p.viewable_by = ['all'] p.text = mediawiki_internal_links2markdown( mediawiki2markdown(page['text']), page['title']) timestamp = datetime.datetime.strptime(page['timestamp'], self.TIMESTAMP_FMT) p.mod_date = timestamp c.user = (M.User.query.get(username=page['username'].lower()) or M.User.anonymous()) ss = p.commit() ss.mod_date = ss.timestamp = timestamp # set home to main page if page['title'] == 'Main_Page': gl = WM.Globals.query.get(app_config_id=self.wiki.config._id) if gl is not None: gl.root = page['title'] log.info('Loaded history of page %s (%s)', page['page_id'], page['title']) self.load_talk(page_dir, page['title']) self.load_attachments(page_dir, page['title'])
def test_mediawiki_internal_links2markdown(): text = """Example page! Inline image: [[File:image.png]] Link to file: [[Media:attach.pdf|Att]] File: [[Media:attach.pdf]] Inline image in old format: [[Image:image.png]] Internal link1: [[Some Page]] Internal link2: [[SomePage|link text]] Internal link3: [[ircdb#ircdb.checkCapability()|ircdb.checkCapability()]] """ output = converters.mediawiki_internal_links2markdown(text, "Example page") assert "Example page!" in output assert "Inline image: [[img src=image.png]]" in output assert "Link to file: [Att](Example page/attachment/attach.pdf)" in output assert "File: [attach.pdf](Example page/attachment/attach.pdf)" in output assert "Inline image in old format: [[img src=image.png]]" in output assert "Internal link1: [Some_Page]" in output, output assert "Internal link2: [link text](SomePage)" in output, output assert ("Internal link3: [ircdb.checkCapability()]" "(Ircdb#ircdb.checkCapability())") in output, output
def test_mediawiki_internal_links2markdown(): text = """Example page! Inline image: [[File:image.png]] Link to file: [[Media:attach.pdf|Att]] File: [[Media:attach.pdf]] Inline image in old format: [[Image:image.png]] Internal link1: [[Some Page]] Internal link2: [[SomePage|link text]] Internal link3: [[ircdb#ircdb.checkCapability()|ircdb.checkCapability()]] """ output = converters.mediawiki_internal_links2markdown(text, 'Example page') assert 'Example page!' in output assert 'Inline image: [[img src=image.png]]' in output assert 'Link to file: [Att](Example page/attachment/attach.pdf)' in output assert 'File: [attach.pdf](Example page/attachment/attach.pdf)' in output assert 'Inline image in old format: [[img src=image.png]]' in output assert 'Internal link1: [Some_Page]' in output, output assert 'Internal link2: [link text](SomePage)' in output, output assert ('Internal link3: [ircdb.checkCapability()]' '(Ircdb#ircdb.checkCapability())') in output, output