forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils
More file actions
executable file
·108 lines (85 loc) · 1.95 KB
/
utils
File metadata and controls
executable file
·108 lines (85 loc) · 1.95 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
shopt -s extglob
if [ $(uname) == Darwin ]; then
sed() { command sed -l "$@"; }
else
sed() { command sed -u "$@"; }
fi
# Syntax sugar.
indent() {
sed "s/^/ /"
}
# Clean up pip output
cleanup() {
sed -e 's/\.\.\.\+/.../g' | sed -e '/already satisfied/Id' | sed -e '/No files were found to uninstall/Id' | sed -e '/Overwriting/Id' | sed -e '/python executable/Id' | sed -e '/no previously-included files/Id'
}
# Buildpack Indented line.
puts-line() {
echo " $@"
}
# Buildpack Steps.
puts-step() {
echo "-----> $@"
}
# Buildpack Warnings.
puts-warn() {
echo " ! $@"
}
# Buildpack Commands.
puts-cmd() {
echo " $ $@"
}
# Usage: $ set-env key value
set-env() {
echo "export $1=$2" >> $PROFILE_PATH
}
# Usage: $ set-default-env key value
set-default-env() {
echo "export $1=\${$1:-$2}" >> $PROFILE_PATH
}
# Usage: $ un-set-env key
un-set-env() {
echo "unset $1" >> $PROFILE_PATH
}
# Does some serious copying.
deep-cp() {
declare source="$1" target="$2"
mkdir -p "$target"
# cp doesn't like being called without source params,
# so make sure they expand to something first.
# subshell to avoid surprising caller with shopts.
(
shopt -s nullglob dotglob
set -- "$source"/!(tmp|.|..)
[[ $# == 0 ]] || cp -a "$@" "$target"
)
}
# Does some serious moving.
deep-mv() {
deep-cp "$1" "$2"
deep-rm "$1"
}
# Does some serious deleting.
deep-rm() {
# subshell to avoid surprising caller with shopts.
(
shopt -s dotglob
rm -rf "$1"/!(.curlrc|.netrc|tmp|.|..)
)
}
sub-env() {
WHITELIST=${2:-''}
BLACKLIST=${3:-'^(GIT_DIR|PYTHONHOME|LD_LIBRARY_PATH|LIBRARY_PATH|PATH)$'}
# Python-specific variables.
export PYHONHOME=$BUILD_DIR/.heroku/python
export PYTHONPATH=$BUILD_DIR/
(
if [ -d "$ENV_DIR" ]; then
for e in $(ls $ENV_DIR); do
echo "$e" | grep -E "$WHITELIST" | grep -qvE "$BLACKLIST" &&
export "$e=$(cat $ENV_DIR/$e)"
:
done
fi
$1
)
}