示例#1
0
def deploy_cmd(ctx, server, output_path, extra_flags, **credentials):
    """This command deploys the entire contents of the build folder
    (`--output-path`) onto a configured remote server.  The name of the
    server must fit the name from a target in the project configuration.
    If no server is supplied then the default server from the config is
    used.

    The deployment credentials are typically contained in the project config
    file but it's also possible to supply them here explicitly.  In this
    case the `--username` and `--password` parameters (as well as the
    `LEKTOR_DEPLOY_USERNAME` and `LEKTOR_DEPLOY_PASSWORD` environment
    variables) can override what's in the URL.

    For more information see the deployment chapter in the documentation.
    """
    from lektor.publisher import publish, PublishError

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

    ctx.load_plugins(extra_flags=extra_flags)
    env = ctx.get_env()
    config = env.load_config()

    if server is None:
        server_info = config.get_default_server()
        if server_info is None:
            raise click.BadParameter("No default server configured.",
                                     param_hint="server")
    else:
        server_info = config.get_server(server)
        if server_info is None:
            raise click.BadParameter('Server "%s" does not exist.' % server,
                                     param_hint="server")

    try:
        event_iter = publish(
            env,
            server_info.target,
            output_path,
            credentials=credentials,
            server_info=server_info,
            extra_flags=extra_flags,
        )
    except PublishError as e:
        raise click.UsageError('Server "%s" is not configured for a valid '
                               "publishing method: %s" % (server, e))

    click.echo("Deploying to %s" % server_info.name)
    click.echo("  Build cache: %s" % output_path)
    click.echo("  Target: %s" % secure_url(server_info.target))
    try:
        for line in event_iter:
            click.echo("  %s" % click.style(line, fg="cyan"))
    except PublishError as e:
        click.secho("Error: %s" % e, fg="red")
    else:
        click.echo("Done!")
示例#2
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(id=name,
                       name_i18n=get_i18n_block(info, 'name'),
                       target=target,
                       enabled=bool_from_string(info.get('enabled'), True),
                       default=bool_from_string(info.get('default'), False))
示例#3
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name'),
         target=target,
         enabled=info.get('enabled', 'true').lower() in ('true', 'yes', '1'),
     )
示例#4
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None or 'target' not in info:
         return None
     info = info.copy()
     target = info.pop('target')
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name', pop=True),
         target=target,
         enabled=bool_from_string(info.pop('enabled', None), True),
         default=bool_from_string(info.pop('default', None), False),
         extra=info
     )
示例#5
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None or 'target' not in info:
         return None
     info = info.copy()
     target = info.pop('target')
     if public:
         target = secure_url(target)
     return ServerInfo(id=name,
                       name_i18n=get_i18n_block(info, 'name', pop=True),
                       target=target,
                       enabled=bool_from_string(info.pop('enabled', None),
                                                True),
                       default=bool_from_string(info.pop('default', None),
                                                False),
                       extra=info)
示例#6
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values["SERVERS"].get(name)
     if info is None or "target" not in info:
         return None
     info = info.copy()
     target = info.pop("target")
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, "name", pop=True),
         target=target,
         enabled=bool_from_string(info.pop("enabled", None), True),
         default=bool_from_string(info.pop("default", None), False),
         extra=info,
     )
示例#7
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values['SERVERS'].get(name)
     if info is None:
         return None
     target = info.get('target')
     if target is None:
         return None
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, 'name'),
         target=target,
         enabled=bool_from_string(info.get('enabled'), True),
         default=bool_from_string(info.get('default'), False)
     )
示例#8
0
 def get_server(self, name, public=False):
     """Looks up a server info by name."""
     info = self.values["SERVERS"].get(name)
     if info is None or "target" not in info:
         return None
     info = info.copy()
     target = info.pop("target")
     if public:
         target = secure_url(target)
     return ServerInfo(
         id=name,
         name_i18n=get_i18n_block(info, "name", pop=True),
         target=target,
         enabled=bool_from_string(info.pop("enabled", None), True),
         default=bool_from_string(info.pop("default", None), False),
         extra=info,
     )