示例#1
0
def deploy():
    '''
    Pantalla de deploy
    '''
    page = request.args.get("page", 0, int)
    mode = request.args.get("show", "deploy", str)
    if not mode in ("deploy","script","publish","recover"): mode = "deploy"
    form = DeployForm(request.form)
    dls = None

    force_busy = False

    if mode == "deploy":
        form.mode.choices = [(i,i) for i in fabfile.get_modes()]
        form.mode.choices.sort()
    elif mode == "publish":
        form.publish_mode.choices = deploy_backups_datetimes()
    elif mode == "script":
        dls = deploy_list_scripts()
        if dls:
            form.script_mode.choices = [(i,i) for i in dls]
            form.script_mode.choices.sort()
            form.script_hosts.choices = [(i,i) for i in set(
                k for j in dls.itervalues() for k in j)]
            form.script_hosts.choices.sort()
            form.script_available_hosts.data = json.dumps(dls)
        else:
            form.script_mode.choices = ()
            form.script_hosts.choices = ()

    if request.method == "POST":
        if form.script_clean_cache.data:
            # Botón de borrar caché de scripts
            cache.set(scriptTaskRefresh, time.time())
            cache.delete(deploy_list_scripts.make_cache_key())
        elif form.remove_lock.data:
            for i in (scriptTask, deployTask):
                try:
                    i.release_lock()
                except BaseException as e:
                    flash(e, "error")
        elif form.clean_log.data:
            # Botón de borrar caché de stdout y stderr de deploy
            deployTask.clean_stdout_data()
            deployTask.clean_stderr_data()
        elif not deployTask.busy:
            config = None
            do_task = True
            task = (
                "deploy" if form.deploy.data else
                "deploy-rollback" if form.deploy_rollback.data else
                "clean-local" if form.clean_local.data else
                "clean-remote" if form.clean_remote.data else
                "restart" if form.restart.data else
                "package" if form.package.data else
                "package-rollback" if form.rollback.data else
                "prepare-deploy" if form.prepare.data else
                "commit-deploy" if form.commit.data else
                "publish" if form.publish.data else
                "script" if form.script.data else None
                )
            if task == "publish":
                path = form.publish_mode.data
                message = form.publish_message.data.strip()
                version = form.publish_version.data.strip()
                for i in (path, message, version):
                    if not i:
                        flash("admin_deploy_publish_empty", "error")
                        do_task = False
                        break
                else:
                    if " " in version or any(not i.isdigit() for i in version.split("-")[0].split(".")):
                        flash("admin_deploy_publish_bad_version", "error")
                        do_task = False
                    else:
                        config = {
                            "path":path,
                            "message":message,
                            "version":version
                            }
            elif task == "script":
                if dls is None: dls = deploy_list_scripts()
                available_hosts = dls[form.script_mode.data]
                config = {
                    "hosts":tuple(
                        i for i in form.script_hosts.data
                        if i in available_hosts
                        ),
                    "script":form.script_mode.data
                    }
                if not config["hosts"]:
                    flash("admin_deploy_no_hosts","error")
                    do_task = False

            if task and do_task:
                flash("admin_deploy_in_progress", "message in_progress_message")
                force_busy = True
                deployTask.run(
                    task,
                    None if task in ("publish","script") else form.mode.data,
                    config)
            elif task is None:
                abort(502)

    return render_template('admin/deploy.html',
        page_title=_('admin_deploy'),
        title=admin_title('admin_deploy'),
        backups=deploy_backups(),
        show=mode,
        form=form,
        page=page,
        deploy_available=not (force_busy or deployTask.busy),
        stdout=deployTask.get_stdout_data(),
        stderr=deployTask.get_stderr_data()
        )
示例#2
0
def deploy():
    """
    Pantalla de deploy
    """
    page = request.args.get("page", 0, int)
    mode = request.args.get("show", "old", str)
    size = request.args.get("size", 15, int)
    form = DeployForm(request.form)
    form.mode.choices = [(i, i) for i in fabfile.get_modes()]
    form.publish_mode.choices = deploy_backups_datetimes()

    if request.method == "POST" and not deployTask.busy:
        flash("admin_deploy_in_progress", "message in_progress_message")
        mode = form.mode.data
        config = None
        task = (
            "deploy"
            if form.deploy.data
            else "deploy-rollback"
            if form.deploy_rollback.data
            else "clean-local"
            if form.clean_local.data
            else "clean-remote"
            if form.clean_remote.data
            else "restart"
            if form.restart.data
            else "package"
            if form.package.data
            else "package-rollback"
            if form.rollback.data
            else "prepare-deploy"
            if form.prepare.data
            else "commit-deploy"
            if form.commit.data
            else "publish"
            if form.publish.data
            else None
        )
        if task.startswith("deploy") and fabfile.is_self_target(mode, task):
            task += "-safely"
            flash("admin_deploy_manual_restart", "message")
        elif task == "publish":
            path = form.publish_mode.data
            message = form.publish_message.data.strip()
            version = form.publish_version.data.strip()
            for i in (path, message, version):
                if not i:
                    flash("admin_deploy_publish_empty", "error")
                    break
            else:
                if " " in version or any(not i.isdigit() for i in version.split("-")[0].split(".")):
                    flash("admin_deploy_publish_bad_version", "error")
                else:
                    config = {"path": path, "message": message, "version": version}
        if task:
            deployTask.run(mode, task, config)
        else:
            abort(502)

    stdout = deployTask.stdout.get_data()
    stderr = deployTask.stderr.get_data()

    return render_template(
        "admin/deploy.html",
        page_title=_("admin_deploy"),
        title=admin_title("admin_deploy"),
        backups=deploy_backups(),
        form=form,
        page=page,
        list_mode=mode,
        deploy_available=not deployTask.busy,
        stdout=stdout,
        stderr=stderr,
        page_size=size,
    )