Example #1
0
def build(target_dir, test_dir, other_locale):
    """
    Build the site.

    Set the TRANSLATIONS_PATTERN to the old v6 default.
    """
    init_command = nikola.plugins.command.init.CommandInit()
    init_command.create_empty_site(target_dir)
    init_command.create_configuration(target_dir)

    src = os.path.join(test_dir, "..", "data", "translated_titles")
    for root, dirs, files in os.walk(src):
        for src_name in files:
            rel_dir = os.path.relpath(root, src)
            dst_file = os.path.join(target_dir, rel_dir, src_name)
            src_file = os.path.join(root, src_name)
            shutil.copy2(src_file, dst_file)

    os.rename(
        os.path.join(target_dir, "pages", "1.%s.txt" % other_locale),
        os.path.join(target_dir, "pages", "1.txt.%s" % other_locale),
    )

    patch_config(
        target_dir,
        (
            'TRANSLATIONS_PATTERN = "{path}.{lang}.{ext}"',
            'TRANSLATIONS_PATTERN = "{path}.{ext}.{lang}"',
        ),
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #2
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    redirects_dir = os.path.join(target_dir, "files", "redirects")
    nikola.utils.makedirs(redirects_dir)

    # Source file for absolute redirect
    target_path = os.path.join(redirects_dir, "absolute_source.html")
    with io.open(target_path, "w+", encoding="utf8") as outf:
        outf.write("absolute")

    # Source file for relative redirect
    target_path = os.path.join(redirects_dir, "rel_src.html")
    with io.open(target_path, "w+", encoding="utf8") as outf:
        outf.write("relative")

    # Configure usage of specific redirects
    append_config(
        target_dir,
        """
REDIRECTIONS = [
    ("posts/absolute.html", "/redirects/absolute_source.html"),
    ("external.html", "http://www.example.com/"),
    ("relative.html", "redirects/rel_src.html"),
]
""",
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #3
0
 def test_check_links_fail(self):
     with cd(self.target_dir):
         os.unlink(os.path.join("output", "archive.html"))
         try:
             __main__.main(['check', '-l'])
         except SystemExit as e:
             self.assertNotEqual(e.code, 0)
Example #4
0
 def test_check_links_fail(self):
     with cd(self.target_dir):
         os.unlink(os.path.join("output", "archive.html"))
         try:
             __main__.main(['check', '-l'])
         except SystemExit as e:
             self.assertNotEqual(e.code, 0)
Example #5
0
    def test_future_post(self):
        """ Ensure that the future post is not present in the index and sitemap."""
        index_path = os.path.join(self.target_dir, "output", "index.html")
        sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml")
        foo_path = os.path.join(self.target_dir, "output", "posts", "foo", "index.html")
        bar_path = os.path.join(self.target_dir, "output", "posts", "bar", "index.html")
        self.assertTrue(os.path.isfile(index_path))
        self.assertTrue(os.path.isfile(foo_path))
        self.assertTrue(os.path.isfile(bar_path))
        with io.open(index_path, "r", encoding="utf8") as inf:
            index_data = inf.read()
        with io.open(sitemap_path, "r", encoding="utf8") as inf:
            sitemap_data = inf.read()
        self.assertTrue('foo/' in index_data)
        self.assertFalse('bar/' in index_data)
        self.assertTrue('foo/' in sitemap_data)
        self.assertFalse('bar/' in sitemap_data)

        # Run deploy command to see if future post is deleted
        with cd(self.target_dir):
            __main__.main(["deploy"])

        self.assertTrue(os.path.isfile(index_path))
        self.assertTrue(os.path.isfile(foo_path))
        self.assertFalse(os.path.isfile(bar_path))
Example #6
0
def build(target_dir):
    """Build the site."""
    init_command = nikola.plugins.command.init.CommandInit()
    init_command.create_empty_site(target_dir)
    init_command.create_configuration(target_dir)

    # Change COMMENT_SYSTEM_ID to not wait for 5 seconds
    append_config(target_dir, '\nCOMMENT_SYSTEM_ID = "nikolatest"\n')

    def format_datetime(datetime):
        return datetime.strftime("%Y-%m-%d %H:%M:%S")

    past_datetime = format_datetime(current_time() + timedelta(days=-1))
    with io.open(os.path.join(target_dir, "posts", "empty1.txt"),
                 "w+",
                 encoding="utf8") as past_post:
        past_post.write("""\
.. title: foo
.. slug: foo
.. date: %s
""" % past_datetime)

    future_datetime = format_datetime(current_time() + timedelta(days=1))
    with io.open(os.path.join(target_dir, "posts", "empty2.txt"),
                 "w+",
                 encoding="utf8") as future_post:
        future_post.write("""\
.. title: bar
.. slug: bar
.. date: %s
""" % future_datetime)

    with cd(target_dir):
        __main__.main(["build"])
Example #7
0
 def test_check_files_fail(self):
     with cd(self.target_dir):
         with io.open(os.path.join("output", "foobar"), "w+", encoding="utf8") as outf:
             outf.write("foo")
         try:
             __main__.main(['check', '-f'])
         except SystemExit as e:
             self.assertNotEqual(e.code, 0)
Example #8
0
 def test_check_files_fail(self):
     with cd(self.target_dir):
         with io.open(os.path.join("output", "foobar"), "w+", encoding="utf8") as outf:
             outf.write("foo")
         try:
             __main__.main(["check", "-f"])
         except SystemExit as e:
             self.assertNotEqual(e.code, 0)
Example #9
0
def build(target_dir):
    """Build the site."""
    init_command = nikola.plugins.command.init.CommandInit()
    init_command.create_empty_site(target_dir)
    init_command.create_configuration(target_dir)

    with cd(target_dir):
        __main__.main(["build"])
Example #10
0
 def test_check_files_fail(self):
     with cd(self.target_dir):
         with codecs.open(os.path.join("output", "foobar"), "wb+", "utf8") as outf:
             outf.write("foo")
         try:
             __main__.main(['check', '-f'])
         except SystemExit as e:
             self.assertNotEqual(e.code, 0)
Example #11
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    build_dir = os.path.join(target_dir, "posts")

    with cd(build_dir):
        __main__.main(["build"])
Example #12
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    patch_config(
        target_dir,
        ("# CREATE_FULL_ARCHIVES = False", "CREATE_FULL_ARCHIVES = True"))

    with cd(target_dir):
        __main__.main(["build"])
def build(target_dir, import_file):
    __main__.main([
        "import_wordpress",
        "--no-downloads",
        "--output-folder",
        target_dir,
        import_file,
    ])

    with cd(target_dir):
        result = __main__.main(["build"])
        assert not result
Example #14
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    patch_config(
        target_dir,
        ('SITE_URL = "https://example.com/"',
         'SITE_URL = "https://example.com/foo/"'),
        ("# URL_TYPE = 'rel_path'", "URL_TYPE = 'full_path'"),
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #15
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    append_config(
        target_dir,
        """
POSTS = (("posts/*.txt", "posts", "post.tmpl"),
         ("posts/*.txt", "posts", "post.tmpl"))
""",
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #16
0
 def build(self):
     """Build the site."""
     try:
         self.oldlocale = locale.getlocale()
         locale.setlocale(locale.LC_ALL, ("en_US", "utf8"))
     except:
         pytest.skip('no en_US locale!')
     else:
         with cd(self.target_dir):
             __main__.main(["build", "--invariant"])
     finally:
         try:
             locale.setlocale(locale.LC_ALL, self.oldlocale)
         except:
             pass
Example #17
0
 def build(self):
     """Build the site."""
     try:
         self.oldlocale = locale.getlocale()
         locale.setlocale(locale.LC_ALL, ("en_US", "utf8"))
     except:
         pytest.skip('no en_US locale!')
     else:
         with cd(self.target_dir):
             __main__.main(["build", "--invariant"])
     finally:
         try:
             locale.setlocale(locale.LC_ALL, self.oldlocale)
         except:
             pass
Example #18
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    # Set the SITE_URL to have a path with subfolder
    patch_config(
        target_dir,
        (
            'SITE_URL = "https://example.com/"',
            'SITE_URL = "https://example.com/foo/bar/"',
        ),
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #19
0
    def _execute(self, command, args):

        self.logger = get_logger(CommandGitHubDeploy.name,
                                 self.site.loghandlers)
        self._source_branch = self.site.config.get('GITHUB_SOURCE_BRANCH',
                                                   'master')
        self._deploy_branch = self.site.config.get('GITHUB_DEPLOY_BRANCH',
                                                   'gh-pages')
        self._remote_name = self.site.config.get('GITHUB_REMOTE_NAME',
                                                 'origin')

        self._ensure_git_repo()

        if not self._prompt_continue():
            return

        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            sys.exit(build)

        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        self._checkout_deploy_branch()

        self._copy_output()

        self._commit_and_push()

        return
Example #20
0
def build(target_dir, test_dir):
    """Build the site."""
    init_command = nikola.plugins.command.init.CommandInit()
    init_command.create_empty_site(target_dir)
    init_command.create_configuration(target_dir)

    src = os.path.join(test_dir, "..", "data", "translated_titles")
    for root, dirs, files in os.walk(src):
        for src_name in files:
            rel_dir = os.path.relpath(root, src)
            dst_file = os.path.join(target_dir, rel_dir, src_name)
            src_file = os.path.join(root, src_name)
            shutil.copy2(src_file, dst_file)

    with cd(target_dir):
        __main__.main(["build"])
Example #21
0
    def _execute(self, command, args):

        self.logger = get_logger(
            CommandGitHubDeploy.name, self.site.loghandlers
        )

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            sys.exit(build)

        # Clean non-target files
        l = self._doitargs['cmds'].get_plugin('list')(config=self.config, **self._doitargs)
        only_on_output, _ = real_scan_files(l, self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push()

        return
Example #22
0
    def _execute(self, options, args):
        """Run the deployment."""
        self.logger = get_logger(CommandGitHubDeploy.name)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Remove drafts and future posts if requested (Issue #2406)
        undeployed_posts = clean_before_deployment(self.site)
        if undeployed_posts:
            self.logger.notice(
                "Deleted {0} posts due to DEPLOY_* settings".format(
                    len(undeployed_posts)))

        # Commit and push
        self._commit_and_push(options['commit_message'])

        return
Example #23
0
    def _execute(self, options, args):
        """Run the deployment."""
        self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Remove drafts and future posts if requested (Issue #2406)
        undeployed_posts = clean_before_deployment(self.site)
        if undeployed_posts:
            self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts)))

        # Commit and push
        self._commit_and_push(options['commit_message'])

        return
Example #24
0
def test_check_files_fail(build, output_dir, target_dir):
    manually_added_file = os.path.join(output_dir, "foobar")
    with io.open(manually_added_file, "w+", encoding="utf8") as outf:
        outf.write("foo")

    with cd(target_dir):
        result = __main__.main(["check", "-f"])
        assert result != 0
Example #25
0
def test_future_post_deployment(build, output_dir, target_dir):
    """ Ensure that the future post is deleted upon deploying. """
    index_path = os.path.join(output_dir, "index.html")
    post_in_past = os.path.join(output_dir, "posts", "foo", "index.html")
    post_in_future = os.path.join(output_dir, "posts", "bar", "index.html")

    assert os.path.isfile(index_path)
    assert os.path.isfile(post_in_past)
    assert os.path.isfile(post_in_future)

    # Run deploy command to see if future post is deleted
    with cd(target_dir):
        __main__.main(["deploy"])

    assert os.path.isfile(index_path)
    assert os.path.isfile(post_in_past)
    assert not os.path.isfile(post_in_future)
Example #26
0
def build(target_dir):
    """Build the site."""
    init_command = nikola.plugins.command.init.CommandInit()
    init_command.create_empty_site(target_dir)
    init_command.create_configuration(target_dir)

    create_pages(target_dir)

    append_config(
        target_dir,
        """
PAGE_INDEX = True
PRETTY_URLS = False
PAGES = PAGES + (('pages/*.php', 'pages', 'page.tmpl'),)
""",
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #27
0
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    # Configure our pages to reside in the root
    patch_config(
        target_dir,
        ('("pages/*.txt", "pages", "page.tmpl"),',
         '("pages/*.txt", "", "page.tmpl"),'),
        ('("pages/*.rst", "pages", "page.tmpl"),',
         '("pages/*.rst", "", "page.tmpl"),'),
        ('# INDEX_PATH = ""', 'INDEX_PATH = "blog"'),
    )
    append_config(
        target_dir,
        """
PRETTY_URLS = False
STRIP_INDEXES = False
""",
    )

    with cd(target_dir):
        __main__.main(["build"])
Example #28
0
 def setUpClass(self):
     self.metadata_option = "ADDITIONAL_METADATA"
     script_root = os.path.dirname(__file__)
     test_dir = os.path.join(script_root, "data", "test_config")
     nikola.main(["--conf=" + os.path.join(test_dir, "conf.py")])
     self.simple_config = nikola.config
     nikola.main(["--conf=" + os.path.join(test_dir, "prod.py")])
     self.complex_config = nikola.config
     nikola.main(["--conf=" + os.path.join(test_dir, "config.with+illegal(module)name.characters.py")])
     self.complex_filename_config = nikola.config
     self.check_base_equality(self.complex_filename_config)
Example #29
0
 def setUpClass(self):
     self.metadata_option = "ADDITIONAL_METADATA"
     script_root = os.path.dirname(__file__)
     test_dir = os.path.join(script_root, "data", "test_config")
     nikola.main(["--conf=" + os.path.join(test_dir, "conf.py")])
     self.simple_config = nikola.config
     nikola.main(["--conf=" + os.path.join(test_dir, "prod.py")])
     self.complex_config = nikola.config
     nikola.main([
         "--conf=" + os.path.join(
             test_dir, "config.with+illegal(module)name.characters.py")
     ])
     self.complex_filename_config = nikola.config
     self.check_base_equality(self.complex_filename_config)
Example #30
0
    def _execute(self, command, args):

        self.logger = get_logger(
            CommandGitHubDeploy.name, self.site.loghandlers
        )
        self._source_branch = self.site.config.get(
            'GITHUB_SOURCE_BRANCH', 'master'
        )
        self._deploy_branch = self.site.config.get(
            'GITHUB_DEPLOY_BRANCH', 'gh-pages'
        )
        self._remote_name = self.site.config.get(
            'GITHUB_REMOTE_NAME', 'origin'
        )
        self._pull_before_commit = self.site.config.get(
            'GITHUB_PULL_BEFORE_COMMIT', False
        )

        self._ensure_git_repo()

        self._exit_if_output_committed()

        if not self._prompt_continue():
            return

        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            sys.exit(build)

        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        self._checkout_deploy_branch()

        self._copy_output()

        self._commit_and_push()

        return
Example #31
0
 def render(self):
     from nikola.__main__ import main
     from nikola import nikola
     with self.current_site_directory():
         # Make it raise exceptions instead of swallowing
         # them.
         old_debug = nikola.DEBUG
         nikola.DEBUG = True
         try:
             x = main([
                 'build',
                 '--quiet',  # TODO: Conditional on env variable
                 '--strict',
                 '--no-continue',
                 '-v2'
             ])
             if x:
                 raise AssertionError("Build error", x)
         finally:
             nikola.DEBUG = old_debug
     self._rendered = True
Example #32
0
    def _execute(self, command, args):
        """Run the deployment."""
        self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push()

        return
Example #33
0
    def _execute(self, command, args):

        self.logger = get_logger(CommandGitHubDeploy.name, self.site.loghandlers)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(["build"])
        if build != 0:
            self.logger.error("Build failed, not deploying to GitHub")
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push()

        return
Example #34
0
    def _execute(self, options, args):
        """Run the deployment."""
        self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push(options['commit_message'])

        return
Example #35
0
    def _execute(self, command, args):

        self.logger = get_logger(
            CommandGitHubDeploy.name, self.site.loghandlers
        )

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            sys.exit(build)

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push()

        return
Example #36
0
 def _run_command(self, args=[]):
     from nikola.__main__ import main
     with self._captured_output() as out:
         main(['plugin', '-u', PLUGIN_URL] + args)
         out.seek(0)
         return out.read()
Example #37
0
 def test_check_files(self):
     with cd(self.target_dir):
         try:
             __main__.main(['check', '-f'])
         except SystemExit as e:
             self.assertEqual(e.code, 0)
Example #38
0
 def build(self):
     """Build the site."""
     with cd(self.target_dir):
         __main__.main(["build"])
Example #39
0
    def test_subdir_run(self):
        """Check whether build works from posts/"""

        with cd(os.path.join(self.target_dir, 'posts')):
            result = __main__.main(['build'])
            self.assertEquals(result, 0)
Example #40
0
 def test_check_files(self):
     with cd(self.target_dir):
         self.assertIsNone(__main__.main(['check', '-f']))
Example #41
0
 def _run_command(self, args=[]):
     from nikola.__main__ import main
     return main(args)
Example #42
0
 def test_check_files(self):
     with cd(self.target_dir):
         try:
             __main__.main(['check', '-f'])
         except SystemExit as e:
             self.assertEqual(e.code, 0)
Example #43
0
 def _run_command(self, args=[]):
     from nikola.__main__ import main
     return main(args)
 def setUpClass():
     from nikola.__main__ import main
     main(['install_plugin', 'microdata'])
     LOGGER.notice('--- TESTS FOR ItemScope')
     LOGGER.level = logbook.WARNING
Example #45
0
    def test_subdir_run(self):
        """Check whether build works from posts/"""

        with cd(os.path.join(self.target_dir, 'posts')):
            result = __main__.main(['build'])
            self.assertEquals(result, 0)
Example #46
0
 def test_check_files(self):
     with cd(self.target_dir):
         self.assertIsNone(__main__.main(['check', '-f']))
Example #47
0
 def build(self):
     """Build the site."""
     with cd(self.target_dir):
         __main__.main(["build"])
Example #48
0
 def test_check_files(self):
     with cd(self.target_dir):
         self.assertIsNone(__main__.main(["check", "-f"]))