forked from jdswinbank/tkp-lofar-build
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.sh
More file actions
146 lines (134 loc) · 4.32 KB
/
utils.sh
File metadata and controls
146 lines (134 loc) · 4.32 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
##Check that the most recent command returned a zero exit code. If not, print error and exit
check_result() {
COMPONENT=${1} #General name for current task
STEP=${2} #Name of specific task in current task
RESULT=${3}
if [ $RESULT -ne 0 ]
then
message="$STEP failed: returned value $RESULT"
echo
echo "**** ERROR: $COMPONENT: $message ****"
exit 1
fi
}
update_svn_repo() {
SOURCEDIR=${1} #path to svn repo
REVISION=${2} #revision to check out (optional, defaults to HEAD)
cd $SOURCEDIR
echo
echo
echo "*** Updating sources at $SOURCEDIR. ***"
git_update_startdir=$(pwd)
cd $SOURCEDIR
git clean -df
check_result "$SOURCEDIR update" "clean" $?
git checkout -f master
git svn rebase
check_result "$SOURCEDIR update" "svn rebase" $?
if [ $REVISION ]; then
echo "*** Checking out $REVISION. *** "
GIT_HASH=`git svn find-rev r$REVISION`
if [[ -z $GIT_HASH ]]; then
echo
echo
echo "**** ERROR: rev $REVISION not found at $SOURCEDIR$ ****"
exit
fi
git checkout $GIT_HASH
check_result "$SOURCEDIR update" "rev change" $?
unset GIT_HASH
fi
cd "$git_update_startdir"
unset git_update_startdir
}
update_authenticated_svn_repo() {
SOURCEDIR=${1} #path to svn repo
SVN_LOGIN=${2} #login username
REVISION=${3} #revision to check out (optional, defaults to HEAD)
cd $SOURCEDIR
echo
echo
echo "*** Updating sources at $SOURCEDIR. ***"
git_update_startdir=$(pwd)
cd $SOURCEDIR
git clean -df
check_result "$SOURCEDIR update" "clean" $?
git checkout -f master
git svn rebase --username $SVN_LOGIN
check_result "$SOURCEDIR update" "svn rebase" $?
if [ $REVISION ]; then
echo "*** Checking out r$REVISION. *** "
GIT_HASH=`git svn find-rev r$REVISION`
if [[ -z $GIT_HASH ]]; then
echo
echo
echo "**** ERROR: rev $REVISION not found at $SOURCEDIR$ ****"
exit
fi
git checkout $GIT_HASH
check_result "$SOURCEDIR update" "rev change" $?
unset GIT_HASH
fi
cd "$git_update_startdir"
unset git_update_startdir
}
update_git_repo() {
SOURCEDIR=${1} #path to git repo
BRANCH=${2} #branch to check out
cd $SOURCEDIR
echo
echo
echo "*** Updating repo at $SOURCEDIR. ***"
git_update_startdir=$(pwd)
cd $SOURCEDIR
git clean -df
check_result "$SOURCEDIR update" "clean" $?
if [ $BRANCH ]; then
git checkout -f $BRANCH
else
git checkout -f master
fi
check_result "$SOURCEDIR update" "checkout $BRANCH" $?
git pull
check_result "$SOURCEDIR update" "pull" $?
cd "$git_update_startdir"
unset git_update_startdir
}
#Get svn revision number for git-svn repository in current working directory
get_git_svnrev(){
echo `git svn find-rev HEAD`
}
#Get short version of SHA1 hash for git repository in current working directory
get_git_short_hash(){
echo `git log --pretty=format:'%h' -n 1`
}
#Some python packages want to be installed via a .pth file.
#This is a pain for continuous deployment, since you can't simply add the .pth to the PYTHONPATH environment variable.
#But, we can unpack the .pth contents to a destination of our choosing, and then use the results:
unpack_pth_file() {
pth_file=${1} #path to .pth file.
target_dir=${2} #e.g. /some/versioned/build/lib/python2.7/site-packages
mkdir -p "$target_dir"
#.pth file paths can be absolute, or relative to the .pth file.
#To deal with both cases, we cd to the same directory as the .pth file
#Carefully ensuring that our path parameters updated accordingly.
#Make target dir an absolute path:
target_dir=$(cd ${target_dir} && pwd -P)
unpack_pth_file_startdir="$(pwd)"
cd $(dirname ${pth_file})
pth_file=$(basename ${pth_file})
# echo "PWD: $(pwd)"
for word in $(<$pth_file); do
if [[ ${word: -4} == ".egg" && -d ${word} ]]; then
# echo "${word} is a valid egg dir"
eggdir=${word}
for pkgdir in $(find -L $eggdir/* -mindepth 0 -maxdepth 0 -type d); do
if [[ $(basename $pkgdir) != EGG-INFO ]] ; then
# echo "Found '$(basename $pkgdir)' in $pkgdir"
cp -r "$pkgdir" "$target_dir"
fi
done
fi
done
cd "${unpack_pth_file_startdir}"
}