summaryrefslogtreecommitdiff
path: root/pkg/tools/enable_ipdb.sh
blob: 42ea96a9fa8967681c573b92f0f5e94b6e97050e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh

# This script installs modules needed for using IPythin debug shell in a
# Bitmask bundle directory. It uses a python virtual environment in which it
# installs needed modules and then links them into the appropriate directory
# inside the bundle directory.

MODULES="ast.py runpy.py"
SITE_MODULES="ipdb IPython simplegeneric.py decorator.py pexpect"

if [ $# != 1 ]; then
  echo "Usage: $0 bundle_path"
  exit 1
fi

BUNDLE_PATH=`echo $1 | sed -e "s/\/\$//"`
BUNDLE_LIB=${BUNDLE_PATH}/lib
BUNDLE_VENV=${BUNDLE_PATH}/.venv

function check_bundle_dirs() {
  if [ ! -d ${BUNDLE_PATH} ]; then
    echo "Argument ${BUNDLE_PATH} is not a directory."
    exit 2
  fi

  if [ ! -d ${BUNDLE_LIB} ]; then
    echo "Expected library directory ${BUNDLE_LIB} is not a directory."
    exit 2
  fi

  if [ ! -w ${BUNDLE_LIB} ]; then
    echo "Directory ${BUNDLE_LIB} is not writable."
    exit 2
  fi
}

function confirm_installation() {
  echo -n "Are you sure you want to enable IPython debugger in ${BUNDLE_PATH} (y/N)? "
  read confirm
  if [[ "${confirm}" != "y" && "${confirm}" != "Y" ]]; then
    echo "Bailing out..."
    exit 0
  fi
}

function setup_virtualenv() {
  if [ ! -d ${BUNDLE_VENV} ]; then
    virtualenv ${BUNDLE_VENV}
  fi
  source ${BUNDLE_VENV}/bin/activate
  pip install ipdb
}

function link_modules() {
  for package in ${MODULES}; do
    package_path=${BUNDLE_LIB}/${package}
    if [[ ! -f ${package_path} && ! -d ${package_path} ]]; then
      ln -sf /usr/lib/python2.7/${package} ${BUNDLE_LIB}
    fi
  done
  for package in ${SITE_MODULES}; do
    package_path=${BUNDLE_LIB}/${package}
    if [[ ! -f ${package_path} && ! -d ${package_path} ]]; then
      ln -sf ${BUNDLE_VENV}/lib/python2.7/site-packages/${package} ${BUNDLE_LIB}
    fi
  done
}

function main() {
  check_bundle_dirs
  confirm_installation
  setup_virtualenv
  link_modules
  echo "All done."
  exit 0
}

main