Ejemplo n.º 1
0
 def setUp(self):
     self.project = Project.from_path(
         os.path.join(os.path.dirname(__file__), 'demo-project'))
     self.env = Environment(self.project)
     self.pad = Database(self.env).new_pad()
     self.out = tempfile.mkdtemp()
     self.builder = Builder(self.pad, self.out)
Ejemplo n.º 2
0
 def _build():
     builder = Builder(env.new_pad(), str(self._dst),
                       buildstate_path=self._buildstate,
                       extra_flags=self._buildflags if not tiny else [])
     failures = builder.build_all()
     builder.prune()
     return failures == 0
Ejemplo n.º 3
0
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 4
0
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 5
0
    def clean(self):
        from lektor.builder import Builder
        from lektor.reporter import CliReporter

        # self._ctx.load_plugins()
        env = self._ctx.get_env()

        reporter = CliReporter(env)  # (env, verbosity=self._verbosity)
        with reporter:
            builder = Builder(env.new_pad(), self._dst)
            builder.prune(all=True)
Ejemplo n.º 6
0
Archivo: cli.py Proyecto: jab/lektor
def clean_cmd(ctx, output_path, verbosity):
    """Cleans the entire build folder."""
    from lektor.builder import Builder
    from lektor.reporter import CliReporter

    if output_path is None:
        output_path = ctx.get_default_output_path()

    env = ctx.get_env()

    reporter = CliReporter(env, verbosity=verbosity)
    with reporter:
        builder = Builder(ctx.new_pad(), output_path)
        builder.prune(all=True)
def build(ctx):
    lektor_cli_ctx = Context()
    lektor_cli_ctx.load_plugins()

    env = lektor_cli_ctx.get_env()
    pad = env.new_pad()

    # This is essentially `lektor build --output-path build`.
    with CliReporter(env, verbosity=0):
        builder = Builder(pad, OUTPUT_DIR)
        failures = builder.build_all()

    if failures:
        raise invoke.Exit('Builder failed.')
Ejemplo n.º 8
0
Archivo: cli.py Proyecto: jab/lektor
def clean_cmd(ctx, output_path, verbosity):
    """Cleans the entire build folder."""
    from lektor.builder import Builder
    from lektor.reporter import CliReporter

    if output_path is None:
        output_path = ctx.get_default_output_path()

    env = ctx.get_env()

    reporter = CliReporter(env, verbosity=verbosity)
    with reporter:
        builder = Builder(ctx.new_pad(), output_path)
        builder.prune(all=True)
Ejemplo n.º 9
0
def child_sources_test_project_builder(tmpdir):
    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), "child-sources-test-project"))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 10
0
def get_unicode_builder(tmpdir):
    proj = Project.from_path(
        os.path.join(os.path.dirname(__file__), u"ünicöde-project"))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 11
0
def test_prev_next_dependencies(request, pntest_env, pntest_reporter):
    env, reporter = pntest_env, pntest_reporter
    builder = make_builder(request, env.new_pad())
    builder.build_all()

    # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other,
    # posts 2 and 3 depend on each other, but posts 1 and 3 are independent.
    assert 'content/post2/contents.lr' in reporter.deps['post1']
    assert 'content/post3/contents.lr' not in reporter.deps['post1']
    assert '/post1@siblings' in reporter.deps['post1']

    assert 'content/post1/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' in reporter.deps['post2']
    assert '/post2@siblings' in reporter.deps['post2']

    assert 'content/post1/contents.lr' not in reporter.deps['post4']
    assert 'content/post2/contents.lr' in reporter.deps['post4']
    assert '/post4@siblings' in reporter.deps['post4']

    # Create post3, check that post2 and post4's dependencies are updated.
    post3_dir = os.path.join(env.project.tree, 'content', 'post3')

    def cleanup():
        try:
            shutil.rmtree(post3_dir)
        except (OSError, IOError):
            pass

    request.addfinalizer(cleanup)
    os.makedirs(post3_dir)
    open(os.path.join(post3_dir, 'contents.lr'), 'w+').close()

    reporter.clear()
    builder = Builder(env.new_pad(), builder.destination_path)
    builder.build_all()

    # post2, post3, and post4 had to be rebuilt, but not post1.
    assert set(['post2', 'post3', 'post4']) == set(reporter.artifact_ids)

    # post2 depends on post3 now, not post4.
    assert 'content/post3/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' not in reporter.deps['post2']

    # post4 depends on post3 now, not post2.
    assert 'content/post3/contents.lr' in reporter.deps['post4']
    assert 'content/post2/contents.lr' not in reporter.deps['post4']
Ejemplo n.º 12
0
def test_prev_next_dependencies(request, pntest_env, pntest_reporter):
    env, reporter = pntest_env, pntest_reporter
    builder = make_builder(request, env.new_pad())
    builder.build_all()

    # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other,
    # posts 2 and 3 depend on each other, but posts 1 and 3 are independent.
    assert 'content/post2/contents.lr' in reporter.deps['post1']
    assert 'content/post3/contents.lr' not in reporter.deps['post1']
    assert '/post1@siblings' in reporter.deps['post1']

    assert 'content/post1/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' in reporter.deps['post2']
    assert '/post2@siblings' in reporter.deps['post2']

    assert 'content/post1/contents.lr' not in reporter.deps['post4']
    assert 'content/post2/contents.lr' in reporter.deps['post4']
    assert '/post4@siblings' in reporter.deps['post4']

    # Create post3, check that post2 and post4's dependencies are updated.
    post3_dir = os.path.join(env.project.tree, 'content', 'post3')

    def cleanup():
        try:
            shutil.rmtree(post3_dir)
        except (OSError, IOError):
            pass

    request.addfinalizer(cleanup)
    os.makedirs(post3_dir)
    open(os.path.join(post3_dir, 'contents.lr'), 'w+').close()

    reporter.clear()
    builder = Builder(env.new_pad(), builder.destination_path)
    builder.build_all()

    # post2, post3, and post4 had to be rebuilt, but not post1.
    assert set(['post2', 'post3', 'post4']) == set(reporter.artifact_ids)

    # post2 depends on post3 now, not post4.
    assert 'content/post3/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' not in reporter.deps['post2']

    # post4 depends on post3 now, not post2.
    assert 'content/post3/contents.lr' in reporter.deps['post4']
    assert 'content/post2/contents.lr' not in reporter.deps['post4']
Ejemplo n.º 13
0
def clean_cmd(ctx, output_path, verbosity):
    """Cleans the entire build folder.

    If not build folder is provided, the default build folder of the project
    in the Lektor cache is used.
    """
    from lektor.builder import Builder
    from lektor.reporter import CliReporter

    if output_path is None:
        output_path = ctx.get_default_output_path()

    env = ctx.get_env()

    reporter = CliReporter(env, verbosity=verbosity)
    with reporter:
        builder = Builder(env.new_pad(), output_path)
        builder.prune(all=True)
Ejemplo n.º 14
0
def clean_cmd(ctx, output_path, verbosity):
    """Cleans the entire build folder.

    If not build folder is provided, the default build folder of the project
    in the Lektor cache is used.
    """
    from lektor.builder import Builder
    from lektor.reporter import CliReporter

    if output_path is None:
        output_path = ctx.get_default_output_path()

    env = ctx.get_env()

    reporter = CliReporter(env, verbosity=verbosity)
    with reporter:
        builder = Builder(env.new_pad(), output_path)
        builder.prune(all=True)
Ejemplo n.º 15
0
def build(ctx, bust=False):
    lektor_cli_ctx = Context()

    if bust:
        project = lektor_cli_ctx.get_project()
        shutil.rmtree(project.get_package_cache_path(), ignore_errors=True)
        shutil.rmtree(project.get_output_path(), ignore_errors=True)

    lektor_cli_ctx.load_plugins()
    env = lektor_cli_ctx.get_env()
    pad = env.new_pad()

    # This is essentially `lektor build --output-path build`.
    with CliReporter(env, verbosity=0):
        builder = Builder(pad, OUTPUT_DIR)
        failures = builder.build_all()

    if failures:
        raise invoke.Exit('Builder failed.')

    # Generate redirect file.
    redirect_filename = os.path.join(OUTPUT_DIR, '_redirects')
    with io.open(redirect_filename, mode='w', encoding='utf8') as f:
        static_redirect = get_static_redirect()
        f.write(static_redirect)
        if not static_redirect.endswith('\n'):
            f.write('\n')

        f.write('\n')
        f.write('# Blog posts.\n')
        f.write('\n'.join(generate_blog_post_redirects(pad)))
        f.write('\n')

        f.write('\n')
        f.write('# Download redirects.\n')
        f.write('\n'.join(generate_download_redirects(pad)))
        f.write('\n')

        latest_redirect = get_latest_download_redirect(pad)
        if latest_redirect is not None:
            f.write('\n')
            f.write('# Latests version download links.\n')
            f.write(latest_redirect)
            f.write('\n')
Ejemplo n.º 16
0
 def _build():
     builder = Builder(ctx.new_pad(), output_path)
     if source_info_only:
         builder.update_all_source_infos()
     else:
         builder.build_all()
         if prune:
             builder.prune()
Ejemplo n.º 17
0
class TestLektorPythonMarkdown(unittest.TestCase):
    def setUp(self):
        self.project = Project.from_path(
            os.path.join(os.path.dirname(__file__), 'demo-project'))
        self.env = Environment(self.project)
        self.pad = Database(self.env).new_pad()
        self.out = tempfile.mkdtemp()
        self.builder = Builder(self.pad, self.out)

    def tearDown(self):
        try:
            shutil.rmtree(self.out)
        except (OSError, IOError):
            pass

    def test_basic(self):
        failures = self.builder.build_all()
        assert not failures
        page_path = os.path.join(self.builder.destination_path,
                                 'fr/index.html')
        html = open(page_path).read()
        print(html)
        assert '<h1 id="header-1">Header 1</h1>' in html
        assert '<h2 class="customclass" id="header-2">Header 2</h2>' in html
        # The output changes depending on the version of python-markdown uses.
        # assert '<pre class="codehilite"><code class="linenums">code here</code></pre>' in html
        # Check url & image substitution
        assert '<a href="/fr/sub-page/">Link to Sub Page</a>' in html
        assert '<a href="/fr/slug-url/">Link to Slug</a>' in html
        assert '<a href="/invalid-page">Link to Invalid Page</a>' in html
        assert '<img alt="alttxt" src="/fr/logo.png" />' in html
        # Check references
        assert '<a href="/fr/sub-page/" title="Sub Page">Sub Page</a>' in html
        assert '<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>' in html

    def test_basic_alt_en(self):
        failures = self.builder.build_all()
        assert not failures
        page_path = os.path.join(self.builder.destination_path,
                                 'en/index.html')
        html = open(page_path).read()
        print(html)
        assert '<img alt="alttxt" src="/fr/logo.png" />' in html
def make_builder(request, pad):
    from lektor.builder import Builder
    out = tempfile.mkdtemp()
    builder = Builder(pad, out)
    def cleanup():
        try:
            shutil.rmtree(out)
        except (OSError, IOError):
            pass
    request.addfinalizer(cleanup)
    return builder
Ejemplo n.º 19
0
def demo_output(site_path, my_plugin_id, my_plugin_cls, tmp_path_factory):
    """ Build the demo site.

    Return path to output directory.

    """
    project = Project.from_path(str(site_path))
    env = Environment(project, load_plugins=False)

    # Load our plugin
    env.plugin_controller.instanciate_plugin(my_plugin_id, my_plugin_cls)
    env.plugin_controller.emit('setup-env')

    pad = Database(env).new_pad()
    output_path = tmp_path_factory.mktemp('demo-site')
    builder = Builder(pad, str(output_path))
    with CliReporter(env):
        failures = builder.build_all()
        assert failures == 0
    return output_path
Ejemplo n.º 20
0
def child_sources_test_project_builder(tmpdir):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project
    from lektor.builder import Builder

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 21
0
def get_unicode_builder(tmpdir):
    from lektor.project import Project
    from lektor.environment import Environment
    from lektor.db import Database
    from lektor.builder import Builder

    proj = Project.from_path(os.path.join(os.path.dirname(__file__),
                                          u'ünicöde-project'))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir('output')))
Ejemplo n.º 22
0
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path,
                           build_flags=self.build_flags)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         if self.prune:
             builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 23
0
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
def demo_output(tmp_path_factory):
    """ Build the demo site.

    Return path to output director.

    """
    site_dir = os.path.join(os.path.dirname(__file__), 'test-site')

    project = Project.from_path(site_dir)

    env = project.make_env(load_plugins=False)
    # Load our plugin
    env.plugin_controller.instanciate_plugin('polymorphic-type',
                                             PolymorphicTypePlugin)
    env.plugin_controller.emit('setup-env')

    output_path = tmp_path_factory.mktemp('output')
    builder = Builder(env.new_pad(), str(output_path))
    with CliReporter(env):
        failures = builder.build_all()
        assert failures == 0

    return output_path
Ejemplo n.º 25
0
def test_prev_next_dependencies(request, tmpdir, pntest_env, pntest_reporter):
    env, reporter = pntest_env, pntest_reporter
    builder = Builder(env.new_pad(), str(tmpdir.mkdir("output")))
    builder.build_all()

    # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other,
    # posts 2 and 3 depend on each other, but posts 1 and 3 are independent.
    assert "content/post2/contents.lr" in reporter.deps["post1"]
    assert "content/post3/contents.lr" not in reporter.deps["post1"]
    assert "/post1@siblings" in reporter.deps["post1"]

    assert "content/post1/contents.lr" in reporter.deps["post2"]
    assert "content/post4/contents.lr" in reporter.deps["post2"]
    assert "/post2@siblings" in reporter.deps["post2"]

    assert "content/post1/contents.lr" not in reporter.deps["post4"]
    assert "content/post2/contents.lr" in reporter.deps["post4"]
    assert "/post4@siblings" in reporter.deps["post4"]

    # Create post3, check that post2 and post4's dependencies are updated.
    post3_dir = os.path.join(env.project.tree, "content", "post3")

    def cleanup():
        try:
            shutil.rmtree(post3_dir)
        except (OSError, IOError):
            pass

    request.addfinalizer(cleanup)
    os.makedirs(post3_dir)
    with open(os.path.join(post3_dir, "contents.lr"), "w+", encoding="utf-8"):
        pass

    reporter.clear()
    builder = Builder(env.new_pad(), builder.destination_path)
    builder.build_all()

    # post2, post3, and post4 had to be rebuilt, but not post1.
    assert set(["post2", "post3", "post4"]) == set(reporter.artifact_ids)

    # post2 depends on post3 now, not post4.
    assert "content/post3/contents.lr" in reporter.deps["post2"]
    assert "content/post4/contents.lr" not in reporter.deps["post2"]

    # post4 depends on post3 now, not post2.
    assert "content/post3/contents.lr" in reporter.deps["post4"]
    assert "content/post2/contents.lr" not in reporter.deps["post4"]
Ejemplo n.º 26
0
 def _build():
     builder = Builder(env.new_pad(), output_path,
                       build_flags=build_flags)
     if source_info_only:
         builder.update_all_source_infos()
     else:
         if profile:
             from .utils import profile_func
             profile_func(builder.build_all)
         else:
             builder.build_all()
         if prune:
             builder.prune()
Ejemplo n.º 27
0
    def _build():
        builder = Builder(env.new_pad(), output_path, build_flags=build_flags)
        if source_info_only:
            builder.update_all_source_infos()
            return True

        if profile:
            from .utils import profile_func
            failures = profile_func(builder.build_all)
        else:
            failures = builder.build_all()
        if prune:
            builder.prune()
        return failures == 0
Ejemplo n.º 28
0
def shell_cmd(ctx, extra_flags):
    """Starts a Python shell in the context of a Lektor project.

    This is particularly useful for debugging plugins and to explore the
    API.  To quit the shell just use `quit()`.  Within the shell various
    utilities are available right from the get-go for you.

    \b
    - `project`: the loaded project as object.
    - `env`: an environment for the loaded project.
    - `pad`: a database pad initialized for the project and environment
      that is ready to use.
    """
    ctx.load_plugins(extra_flags=extra_flags)
    import code
    from lektor.db import F, Tree
    from lektor.builder import Builder

    banner = "Python %s on %s\nLektor Project: %s" % (
        sys.version,
        sys.platform,
        ctx.get_env().root_path,
    )
    ns = {}
    startup = os.environ.get("PYTHONSTARTUP")
    if startup and os.path.isfile(startup):
        with open(startup, "r", encoding="utf-8") as f:
            eval(compile(f.read(), startup, "exec"), ns)  # pylint: disable=eval-used
    pad = ctx.get_env().new_pad()
    ns.update(
        project=ctx.get_project(),
        env=ctx.get_env(),
        pad=pad,
        tree=Tree(pad),
        config=ctx.get_env().load_config(),
        make_builder=lambda: Builder(ctx.get_env().new_pad(),
                                     ctx.get_default_output_path()),
        F=F,
    )
    try:
        c = Config()
        c.TerminalInteractiveShell.banner2 = banner
        embed(config=c, user_ns=ns)
    except NameError:  # No IPython
        code.interact(banner=banner, local=ns)
Ejemplo n.º 29
0
    def _build():
        builder = Builder(
            env.new_pad(),
            output_path,
            buildstate_path=buildstate_path,
            extra_flags=extra_flags,
        )
        if source_info_only:
            builder.update_all_source_infos()
            return True

        if profile:
            failures = profile_func(builder.build_all)
        else:
            failures = builder.build_all()
        if prune:
            builder.prune()
        return failures == 0
Ejemplo n.º 30
0
    def _build():
        builder = Builder(env.new_pad(), output_path,
                          buildstate_path=buildstate_path,
                          build_flags=build_flags)
        if source_info_only:
            builder.update_all_source_infos()
            return True

        if profile:
            from .utils import profile_func
            failures = profile_func(builder.build_all)
        else:
            failures = builder.build_all()
        if prune:
            builder.prune()
        return failures == 0
Ejemplo n.º 31
0
def shell_cmd(ctx):
    """Starts a Python shell in the context of a Lektor project.

    This is particularly useful for debugging plugins and to explore the
    API.  To quit the shell just use `quit()`.  Within the shell various
    utilities are available right from the get-go for you.

    \b
    - `project`: the loaded project as object.
    - `env`: an environment for the loaded project.
    - `pad`: a database pad initialized for the project and environment
      that is ready to use.
    """
    ctx.load_plugins()
    import code
    from lektor.db import F, Tree
    from lektor.builder import Builder
    banner = 'Python %s on %s\nLektor Project: %s' % (
        sys.version,
        sys.platform,
        ctx.get_env().root_path,
    )
    ns = {}
    startup = os.environ.get('PYTHONSTARTUP')
    if startup and os.path.isfile(startup):
        with open(startup, 'r') as f:
            eval(compile(f.read(), startup, 'exec'), ns)
    pad = ctx.get_env().new_pad()
    ns.update(project=ctx.get_project(),
              env=ctx.get_env(),
              pad=pad,
              tree=Tree(pad),
              config=ctx.get_env().load_config(),
              make_builder=lambda: Builder(ctx.get_env().new_pad(),
                                           ctx.get_default_output_path()),
              F=F)
    code.interact(banner=banner, local=ns)
Ejemplo n.º 32
0
def scratch_builder(tmpdir, scratch_pad):
    from lektor.builder import Builder
    return Builder(scratch_pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 33
0
Archivo: cli.py Proyecto: jab/lektor
 def _build():
     builder = Builder(ctx.new_pad(), output_path)
     builder.build_all()
     if prune:
         builder.prune()
Ejemplo n.º 34
0
def lektor_builder(lektor_pad, tmp_path):
    return Builder(lektor_pad, str(tmp_path))
Ejemplo n.º 35
0
def builder(tmpdir, pad):
    from lektor.builder import Builder
    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 36
0
 def get_builder(self, pad=None):
     if pad is None:
         pad = self.get_pad()
     return Builder(pad, self.output_path, build_flags=self.build_flags)
Ejemplo n.º 37
0
def scratch_builder(tmpdir, scratch_pad):
    return Builder(scratch_pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 38
0
def theme_builder(theme_pad, tmpdir):
    from lektor.builder import Builder

    return Builder(theme_pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 39
0
 def get_builder(self, pad):
     return Builder(pad, self.output_path)