Exemplo n.º 1
0
    def plain(self):
        """Plain Python shell."""
        from nikola import Nikola
        try:
            import conf
            SITE = Nikola(**conf.__dict__)
            SITE.scan_posts()
            gl = {'conf': conf, 'SITE': SITE, 'Nikola': Nikola}
        except ImportError:
            LOGGER.error("No configuration found, cannot run the console.")
        else:
            import code
            try:
                import readline
            except ImportError:
                pass
            else:
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(gl).complete)
                readline.parse_and_bind("tab:complete")

            pythonrc = os.environ.get("PYTHONSTARTUP")
            if pythonrc and os.path.isfile(pythonrc):
                try:
                    execfile(pythonrc)  # NOQA
                except NameError:
                    pass

            code.interact(local=gl, banner=self.header.format('Python'))
Exemplo n.º 2
0
    def plain(self):
        """Plain Python shell."""
        from nikola import Nikola
        try:
            import conf
            SITE = Nikola(**conf.__dict__)
            SITE.scan_posts()
            gl = {'conf': conf, 'SITE': SITE, 'Nikola': Nikola}
        except ImportError:
            LOGGER.error("No configuration found, cannot run the console.")
        else:
            import code
            try:
                import readline
            except ImportError:
                pass
            else:
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(gl).complete)
                readline.parse_and_bind("tab:complete")

            pythonrc = os.environ.get("PYTHONSTARTUP")
            if pythonrc and os.path.isfile(pythonrc):
                try:
                    execfile(pythonrc)  # NOQA
                except NameError:
                    pass

            code.interact(local=gl, banner=self.header.format('Python'))
Exemplo n.º 3
0
    def _execute(self, options, args):
        """Start the console."""
        from nikola import Nikola
        try:
            import conf
            SITE = Nikola(**conf.__dict__)
            SITE.scan_posts()
            print("You can now access your configuration as conf and your "
                  "site engine as SITE.")
        except ImportError:
            print("No configuration found.")
        import code
        try:
            import readline
        except ImportError:
            pass
        else:
            import rlcompleter
            readline.set_completer(rlcompleter.Completer(globals()).complete)
            readline.parse_and_bind("tab:complete")

        pythonrc = os.environ.get("PYTHONSTARTUP")
        if pythonrc and os.path.isfile(pythonrc):
            try:
                execfile(pythonrc)  # NOQA
            except NameError:
                pass
        code.interact(local=globals())
Exemplo n.º 4
0
 def ipython(self):
     """IPython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         LOGGER.error("No configuration found, cannot run the console.")
     else:
         import IPython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         IPython.embed(header=self.header.format('IPython'))
Exemplo n.º 5
0
 def ipython(self):
     """IPython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         LOGGER.error("No configuration found, cannot run the console.")
     else:
         import IPython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         IPython.embed(header=self.header.format('IPython'))
Exemplo n.º 6
0
 def bpython(self):
     """bpython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         LOGGER.error("No configuration found, cannot run the console.")
     else:
         import bpython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         gl = {'conf': conf, 'SITE': SITE, 'Nikola': Nikola}
         bpython.embed(banner=self.header.format('bpython'), locals_=gl)
Exemplo n.º 7
0
 def bpython(self):
     """bpython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         print("No configuration found, cannot run the console.")
     else:
         import bpython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         gl = {'conf': conf, 'SITE': SITE, 'Nikola': Nikola}
         bpython.embed(banner=self.header.format('bpython'), locals_=gl)
Exemplo n.º 8
0
 def bpython(self):
     """bpython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         print("No configuration found, cannot run the console.")
     else:
         import bpython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         bpython.embed(banner='Nikola Console (conf = configuration, SITE '
                       '= site engine)')
Exemplo n.º 9
0
 def ipython(self):
     """IPython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         print("No configuration found, cannot run the console.")
     else:
         import IPython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         IPython.embed(header='Nikola Console (conf = configuration, SITE '
                       '= site engine)')
Exemplo n.º 10
0
 def bpython(self):
     """bpython shell."""
     from nikola import Nikola
     try:
         import conf
     except ImportError:
         print("No configuration found, cannot run the console.")
     else:
         import bpython
         SITE = Nikola(**conf.__dict__)
         SITE.scan_posts()
         gl = {'conf': conf, 'SITE': SITE, 'Nikola': Nikola}
         bpython.embed(banner='Nikola Console (conf = configuration, SITE '
                       '= site engine)', locals_=gl)
Exemplo n.º 11
0
    def f(ext: str,
          data: str,
          extra_plugins_dirs: List[Path] = None,
          metadata: str = None,
          extra_config: Dict = None) -> CompileResult:
        data = dedent(data)
        (tmp_site_path / 'pages' / 'test').with_suffix(ext).write_text(
            data, encoding='utf8')

        metadata = metadata or '.. title: test'
        (tmp_site_path / 'pages' / 'test').with_suffix('.meta').write_text(
            metadata, encoding='utf8')

        config = {
            'EXTRA_PLUGINS_DIRS': map(str, extra_plugins_dirs or []),
            'PAGES': (('pages/*' + ext, 'pages', 'page.tmpl'), ),
        }
        if extra_config:
            config.update(extra_config)

        site = Nikola(**config)
        site.init_plugins()
        site.scan_posts()

        post = site.timeline[0]
        post.compile('en')
        return CompileResult(request, post)
Exemplo n.º 12
0
from __future__ import print_function, unicode_literals

from nikola import Nikola
import conf
SITE = Nikola(**conf.__dict__)
SITE.scan_posts()
print("You can now access your configuration as conf and your site engine as SITE")
Exemplo n.º 13
0
def fixture(taxonomy, path):
    scheme, _, path = path.partition(':')
    append_index = scheme == 'base'
    if isinstance(taxonomy, ClassifyAuthors) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, AUTHOR_PATH=path)
    elif isinstance(taxonomy, ClassifyAuthors) and not append_index:
        pytest.skip("There is no AUTHORS_INDEX_PATH setting")
    elif isinstance(taxonomy, ClassifyCategories) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, CATEGORY_PATH=path)
    elif isinstance(taxonomy, ClassifyCategories) and not append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, CATEGORIES_INDEX_PATH=path)
    elif isinstance(taxonomy, ClassifyTags) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, TAG_PATH=path)
    elif isinstance(taxonomy, ClassifyTags) and not append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, TAGS_INDEX_PATH=path)
    else:
        raise TypeError("Unknown taxonomy %r" % type(taxonomy))

    site._template_system = mock.MagicMock()
    site._template_system.template_deps.return_value = []
    site._template_system.name = "dummy"
    site.hierarchy_per_classification = {
        taxonomy.classification_name: {
            "en": []
        }
    }
    site.posts_per_classification = {taxonomy.classification_name: {"en": {}}}
    site.taxonomy_plugins = {taxonomy.classification_name: taxonomy}

    taxonomy.set_site(site)

    classifier = TaxonomiesClassifier()
    classifier.set_site(site)

    expected = path.strip("/")
    if append_index:
        expected += "/"
    if not expected.startswith("/"):
        expected = "/" + expected

    return site, classifier, taxonomy, append_index, expected