@mod.route('/action/backup-container', methods=['GET', 'POST'])
@if_logged_in()
def backup_container():
    """
    Verify the form to backup a container
    """
    if request.method == 'POST':
        container = request.form['orig']
        sr_type = request.form['dest']
        if 'push' in request.form:
            push = request.form['push']
        else:
            push = False
        sr_path = None
        for sr in storage_repos:
            if sr_type in sr:
                sr_path = sr[1]
                break

        backup_failed = True

        try:
            backup_file = lxc.backup(container=container, sr_type=sr_type, destination=sr_path)
            bucket_token = get_bucket_token(container)
            if push and bucket_token and USE_BUCKET:
                    os.system('curl http://{}:{}/{} -F file=@{}'.format(BUCKET_HOST, BUCKET_PORT, bucket_token, backup_file))
            backup_failed = False
        except lxc.ContainerDoesntExists:
            flash(container % u'The Container %s does not exist !', 'error')
        except lxc.DirectoryDoesntExists:
            flash(u'Local backup directory "%s" does not exist !' % sr_path, 'error')
        except lxc.NFSDirectoryNotMounted:
            flash(u'NFS repository "%s" not mounted !' % sr_path, 'error')
        except subprocess.CalledProcessError:
            flash(u'Error during transfert !', 'error')
        except:
            flash(u'Error during transfert !', 'error')

        if backup_failed is not True:
            flash(u'Container %s backed up successfully' % container, 'success')
        else:
            flash(u'Failed to backup %s container' % container, 'error')

    return redirect(url_for('main.home'))
dataset/ETHPy150Open claudyus/LXC-Web-Panel/lwp/views/main.py/backup_container/swapped operands of `%`