#!/bin/bash
set -euo pipefail
set -x

if [ ! -S ~/.ssh/ssh_auth_sock ]; then
    eval `sh-agent`
    ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
ssh-add -l > /dev/null || ssh-add

git pull

bazel query 'let targets = //... in deps($targets)' | egrep '^//.*\.py$' | fgrep -v //build/zrte:gen_usr/lib/ | fgrep -v //build/zrte:usr/lib/ > /tmp/list_pyall.out
bazel query 'let targets = //... in deps(attr(default_python_version, PY2, $targets) union attr(python_version, PY2, $targets))' | egrep '^//.*\.py$' > /tmp/list_py2.out
bazel query 'let targets = //... in deps(attr(default_python_version, PY3, $targets) union attr(python_version, PY3, $targets))' | egrep '^//.*\.py$' > /tmp/list_py3.out

~/v/py3_tpm_metrics/bin/python3.6 -m experimental.estevens.py3_tpm_metrics.compute_metrics --do_new_sheet
