utils 1.71 KB
Newer Older
Kenneth Reitz's avatar
test  
Kenneth Reitz committed
1 2
shopt -s extglob

Kenneth Reitz's avatar
Kenneth Reitz committed
3 4
[ $(uname) == "Darwin" ] && SED_FLAG='-l' || SED_FLAG='-u'

Kenneth Reitz's avatar
Kenneth Reitz committed
5 6 7
# Syntax sugar.
indent() {
  RE="s/^/       /"
Kenneth Reitz's avatar
Kenneth Reitz committed
8
  sed $SED_FLAG "$RE"
Kenneth Reitz's avatar
Kenneth Reitz committed
9 10 11 12
}

# Clean up pip output
cleanup() {
Kenneth Reitz's avatar
Kenneth Reitz committed
13
  sed $SED_FLAG -e 's/\.\.\.\+/.../g' | sed $SED_FLAG '/already satisfied/Id' | sed $SED_FLAG -e '/Overwriting/Id' |  sed $SED_FLAG -e '/python executable/Id' | sed $SED_FLAG -e '/no previously-included files/Id'
Kenneth Reitz's avatar
Kenneth Reitz committed
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
}

# Virtualenv wrapper.
function virtualenv (){
  python "$ROOT_DIR/vendor/virtualenv-1.8.4/virtualenv.py" "$@"
}

# Buildpack Steps.
function puts-step (){
  echo "-----> $@"
}

# Buildpack Warnings.
function puts-warn (){
  echo " !     $@"
}

# Usage: $ set-env key value
function set-env (){
  echo "export $1=$2" >> $PROFILE_PATH
}

# Usage: $ set-default-env key value
function set-default-env (){
  echo "export $1=\${$1:-$2}" >> $PROFILE_PATH
}
Kenneth Reitz's avatar
Kenneth Reitz committed
40

Kenneth Reitz's avatar
Kenneth Reitz committed
41 42 43 44 45
# Usage: $ set-default-env key value
function un-set-env (){
  echo "unset $1" >> $PROFILE_PATH
}

Kenneth Reitz's avatar
Kenneth Reitz committed
46 47 48
# Does some serious copying.
function deep-cp (){
  find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec cp -a '{}' $2 \;
Kenneth Reitz's avatar
test  
Kenneth Reitz committed
49
  cp -r $1/!(tmp) $2
Kenneth Reitz's avatar
Kenneth Reitz committed
50
  # echo copying $1 to $2
Kenneth Reitz's avatar
Kenneth Reitz committed
51 52 53 54 55 56
}

# Does some serious moving.
function deep-mv (){
  deep-cp $1 $2

Kenneth Reitz's avatar
test  
Kenneth Reitz committed
57
  rm -fr $1/!(tmp)
Kenneth Reitz's avatar
Kenneth Reitz committed
58
  find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
}

# Recursively finds requirements.txt files
function list-req (){
  echo $@
  for req in $(grep -Fie "-r " $@ | sed 's/-r //g')
    do
      path="$(dirname $@)/$req"
      list-req $path
    done
}

# Find pattern in requirements files recursively
# Usage: $ in-req pattern file
function in-req (){
  for file in $(list-req $2)
    do
      if (grep -Fiqe "$1" "$file") then
        return 0
      fi
    done
  return 1
}