예제 #1
0
파일: main.py 프로젝트: sergejx/oxalis
 def convert_site(self, path):
     """Convert site to new format and load it."""
     message = "Convert selected site to Oxalis 0.3 format?"
     secondary_message = (
         "From version 0.3 Oxalis uses new format of sites. Selected site " +
         "has older format and needs to be converted before opening. " +
         "The conversion preserves all site contents.\n" +
         "Note, however, that after conversion it would not be possible " +
         "to open the site in Oxalis 0.1.")
     dlg = Gtk.MessageDialog(parent=self,
                             type=Gtk.MessageType.QUESTION,
                             message_format=message)
     dlg.format_secondary_text(secondary_message)
     dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                     "Convert", Gtk.ResponseType.YES)
     dlg.set_default_response(Gtk.ResponseType.YES)
     response = dlg.run()
     if response == Gtk.ResponseType.YES:
         convert_01_to_03(path)
         self.window.controller.load_site(path)
     dlg.destroy()
예제 #2
0
    def test_conversion(self):
        with TemporaryDirectory() as tempdir:
            converted_site = join(tempdir, 'site')
            shutil.copytree(self.SITE_01, converted_site)
            convert_01_to_03(converted_site)

            # Compare files that should be same after conversion
            common = [join('_oxalis', 'config'), join('_oxalis', 'upload'),
                      'index.md', join('subdir', 'index.md')]
            match, __, __ = filecmp.cmpfiles(converted_site, self.SITE_03,
                                             common, False)
            self.assertListEqual(common, match)

            # Compare if templates are in place and contain proper tags
            default_tpl = join(converted_site, '_templates', 'default.html')
            self.assertTrue(os.path.exists(default_tpl))
            with open(default_tpl, 'r') as file:
                text = file.read()
                self.assertGreater(text.find('{{ content }}'), 0)
                self.assertGreater(text.find('{{ title }}'), 0)

            self.assertTrue(os.path.exists(
                join(converted_site, '_templates', 'second.html')))