#NEWLINE# @ cli . command ( 'deploy' , short_help = 'Deploy the website.' ) #NEWLINE# @ click . argument ( 'server' , required = False ) #NEWLINE# @ click . option ( '-O' , '--output-path' , type = click . Path ( ) , default = None , help = 'The output path.' ) #NEWLINE# @ click . option ( '--username' , envvar = 'LEKTOR_DEPLOY_USERNAME' , help = 'An optional username to override the URL.' ) #NEWLINE# @ click . option ( '--password' , envvar = 'LEKTOR_DEPLOY_PASSWORD' , help = 'An optional password to override the URL or the default prompt.' ) #NEWLINE# @ pass_context #NEWLINE# def deploy_cmd( ctx , server , output_path , **credentials ) : #NEWLINE# #INDENT# "This command deploys the entire contents of the build folder\n    (`--output-path`) onto a configured remote server.  The name of the\n    server must fit the name from a target in the project configuration.\n    If no server is supplied then the default server from the config is\n    used.\n\n    The deployment credentials are typically contained in the project config\n    file but it's also possible to supply them here explicitly.  In this\n    case the `--username` and `--password` parameters (as well as the\n    `LEKTOR_DEPLOY_USERNAME` and `LEKTOR_DEPLOY_PASSWORD` environment\n    variables) can override what's in the URL.\n\n    For more information see the deployment chapter in the documentation.\n    " #NEWLINE# from lektor.publisher import publish , PublishError #NEWLINE# if ( output_path is None ) : #NEWLINE# #INDENT# output_path = ctx . get_default_output_path ( ) #NEWLINE# #UNINDENT# ctx . load_plugins ( ) #NEWLINE# env = ctx . get_env ( ) #NEWLINE# config = env . load_config ( ) #NEWLINE# if ( server is None ) : #NEWLINE# #INDENT# server_info = config . get_default_server ( ) #NEWLINE# if ( server_info is None ) : #NEWLINE# #INDENT# raise click . BadParameter ( 'No default server configured.' , param_hint = 'server' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# server_info = config . get_server ( server ) #NEWLINE# if ( server_info is None ) : #NEWLINE# #INDENT# raise click . BadParameter ( ( 'Server "%s" does not exist.' % server ) , param_hint = 'server' ) #NEWLINE# #UNINDENT# #UNINDENT# event_iter = publish ( env , server_info . target , output_path , credentials = credentials ) #NEWLINE# if ( event_iter is None ) : #NEWLINE# #INDENT# raise click . UsageError ( ( 'Server "%s" is not configured for a valid publishing method.' % server ) ) #NEWLINE# #UNINDENT# click . echo ( ( 'Deploying to %s' % server_info . name ) ) #NEWLINE# click . echo ( ( '  Build cache: %s' % output_path ) ) #NEWLINE# click . echo ( ( '  Target: %s' % secure_url ( server_info . target ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# for line in event_iter : #NEWLINE# #INDENT# click . echo ( ( '  %s' % click . style ( line , fg = 'cyan' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# except PublishError as e : #NEWLINE# #INDENT# click . secho ( ( 'Error: %s' % e ) , fg = 'red' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# click . echo ( 'Done!' )