Exemple #1
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)
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)
Exemple #3
0
 def tree(self):
     return Tree(self.pad)
Exemple #4
0
def scratch_tree(scratch_pad):
    from lektor.db import Tree
    return Tree(scratch_pad)
Exemple #5
0
def tree(pad, no_alt_pad, disable_alternatives):
    if disable_alternatives:
        pad = no_alt_pad
    return Tree(pad)
Exemple #6
0
def scratch_tree(scratch_pad):
    return Tree(scratch_pad)
Exemple #7
0
def tree(pad):
    return Tree(pad)