def install_protocol_database_task(bootstrap_path=None,
                                   bootstrap_branch=None,
                                   release=None,
                                   map_area=None,
                                   skip_backup=None):
    """Overwrites the client DB.

    For example:

        fab -P -R lentsweletau deploy.install_protocol_database_task:bootstrap_path=/Users/erikvw/source/bcpp/fabfile/conf/,release=,map_area=

    """
    bootstrap_env(path=bootstrap_path,
                  filename='bootstrap_client.conf',
                  bootstrap_branch=bootstrap_branch)
    if not release:
        abort('release not specified')
    if not map_area:
        abort('map_area not specified')

    update_fabric_env()

    install_protocol_database(skip_backup=skip_backup,
                              release=release,
                              map_area=map_area)
def load_containers_task(bootstrap_path=None,
                         bootstrap_branch=None,
                         map_area=None,
                         file_path=None):
    """Loads containers into the database.

    For example:

        fab -P -R lentsweletau utils.load_containers_task:bootstrap_path=/Users/imosweu/source/bcpp/fabfile/conf/,file_path=,map_area=

    """

    bootstrap_env(path=bootstrap_path,
                  filename='bootstrap_client.conf',
                  bootstrap_branch=bootstrap_branch)
    if not map_area:
        abort('map_area not specified')

    update_fabric_env()

    with cd(env.project_repo_root):
        run(f'source {activate_venv()} &&  python manage.py'
            f' load_containers {file_path}{map_area}container.json edc_map.container'
            )
        run(f'source {activate_venv()} &&  python manage.py'
            f' load_containers {file_path}{map_area}inner_container.json'
            ' edc_map.innercontainer')
def ssh_copy_id(bootstrap_path=None,
                use_local_fabric_conf=None,
                bootstrap_branch=None):
    """
    Example:
        fab -R testhosts -P deploy.ssh_copy_id:config_path=/Users/erikvw/source/bcpp/fabfile/,bootstrap_branch=develop,local_fabric_conf=True --user=django
    """

    bootstrap_env(path=os.path.expanduser(bootstrap_path),
                  bootstrap_branch=bootstrap_branch)
    update_fabric_env(use_local_fabric_conf=use_local_fabric_conf)
    pub_key = local('cat ~/.ssh/id_rsa.pub', capture=True)
    with cd('~/.ssh'):
        run('touch authorized_keys')
        result = run('cat authorized_keys', quiet=True)
        if pub_key not in result:
            run('cp authorized_keys authorized_keys.bak')
            run(f'echo {pub_key} >> authorized_keys')
def change_map_area_task(map_area=None,
                         bootstrap_path=None,
                         bootstrap_branch=None):
    """Change a remote host's map area and restart web.

    For example:

        fab -H bcpp057 utils.change_map_area_task:bootstrap_path=/Users/erikvw/source/bcpp/fabfile/conf/,bootstrap_branch=develop,map_area=mmankgodi --user=django

    """
    bootstrap_env(path=bootstrap_path,
                  filename='bootstrap_client.conf',
                  bootstrap_branch=bootstrap_branch)

    update_fabric_env()

    update_bcpp_conf(map_area=map_area)

    launch_webserver()
def restore_media_folder(bootstrap_path=None,
                         bootstrap_branch=None,
                         use_local_fabric_conf=True):
    """Restores media/edc_map from the external backup

    For example:

        fab -P -R mmankgodi utils.restore_media_folder:bootstrap_path=/Users/django/source/bcpp/fabfile/conf/,bootstrap_branch=develop,use_local_fabric_conf=True --user=django
    """
    bootstrap_env(path=bootstrap_path,
                  filename='bootstrap_client.conf',
                  bootstrap_branch=bootstrap_branch)

    update_fabric_env(use_local_fabric_conf=use_local_fabric_conf)

    local_dir = '/Volumes/BONTSI/Village\ Maps/mmankgodi\ maps/media/edc_map'

    remote_dir = os.path.join('~/media/edc_map')

    if exists(remote_dir):
        run(f'rm -rf {remote_dir}', warn_only=True)
    run(f'mkdir -p {remote_dir}', warn_only=True)

    rsync_project(local_dir=local_dir, remote_dir=remote_dir)