-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateSlicerExtensions.script
More file actions
executable file
·238 lines (232 loc) · 8.16 KB
/
UpdateSlicerExtensions.script
File metadata and controls
executable file
·238 lines (232 loc) · 8.16 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
createNewBranch ()
{
tool=$1
mainBranch="$2"
localMainBranch="$3"
#Create new branch for update
branchName=update-${tool}${localMainBranch}
if [ `git branch | grep -c $branchName` -ne 0 ]
then
echo "Removing existing local branch: $branchName"
git branch -D $branchName
fi
git checkout -B $branchName ${mainBranch}
}
updateDescriptionFile ()
{
descriptionFile=$1
descriptRevision=$2
currentRevision=$3
#Replace hash in s4ext description file
if [ "$OSTYPE" == "linux" ]; then
sed -i "s/$descriptRevision/$currentRevision/g" $descriptionFile
else
sed -i '' "s/$descriptRevision/$currentRevision/g" $descriptionFile
fi
}
updateExtensions ()
{
tool=$1
if [ "$2" == "push" ]
then
localMainBranch="$3"
branchName=update-${tool}${localMainBranch}
if [ `git branch | grep -c "origin/$branchName"` -ne 0 ]
then
echo "Removing existing remote branch: $branchName"
git push origin :$branchName
fi
git push origin $branchName --force
fi
}
ExtensionGit()
{
sourceDir="$1"
tool="$2"
mainBranch="$3"
descriptionFile="$4"
descriptRevision="$5"
currentrevision="$6"
diffmessage="$7"
pushcleanArg="$8"
localMainBranch="$9"
cd $sourceDir
createNewBranch $tool $mainBranch $localMainBranch
updateDescriptionFile $descriptionFile $descriptRevision $currentrevision
git add $descriptionFile
git commit -m "ENH: Update $tool from revision $descriptRevision to $currentrevision" -m "" -m "$diffmessage"
#Update Extensions
updateExtensions $tool $pushcleanArg $localMainBranch
}
if ( [ $# -ne 2 ] || ( [ "$2" != "master" ] && [ "$2" != "4.3" ] && [ "$2" != "4.4" ] ) ) && ( [ $# -ne 3 ] || ([ "$3" != "push" ] && [ "$3" != "clean" ] ) )
then
echo "Usage: $0 SlicerExtensionBuildDirectory [master|4.3|4.4] [push|clean]"
exit 1
fi
mainBranch="$2"
if [ "$mainBranch" == "master" ]
then
localMainBranch=""
else
localMainBranch="-${mainBranch}"
fi
pushcleanArg="$3"
#pushclean cannot be empty
if [ "$pushcleanArg" == "" ]
then
pushcleanArg="none"
fi
currentDir=`pwd`
#Define all our tools included in ExtensionsIndex
toolsNIRALList=(CMFreg DTIAtlasBuilder DTIPrep DTIProcess DTIAtlasFiberAnalyzer FiberViewerLight \
ShapePopulationViewer SPHARM-PDM IntensitySegmenter ModelToModelDistance MeshToLabelMap \
Q3DC EasyClip AnglePlanesExtension MeshStatisticsExtension PickAndPaintExtension \
ResampleDTIlogEuclidean DeveloperToolsForExtensions DTI-Reg\
)
#Find real binary directory
cd $1
var=`more CMakeCache.txt | grep SlicerExtensions_BINARY_DIR`
binaryDir=${var#"SlicerExtensions_BINARY_DIR:STATIC="}
echo "Slicer Extension Build Directory: $binaryDir"
#Find source dir containing s4ext files
var=`more CMakeCache.txt | grep Slicer_EXTENSION_DESCRIPTION_DIR`
sourceDir=${var#"Slicer_EXTENSION_DESCRIPTION_DIR:PATH="}
echo "Slicer Extension Source Directory: $sourceDir"
#Update ExtensionsIndex source code
cd $sourceDir
#Clean if $pushcleanArg == "clean"
if [ "$pushcleanArg" == "clean" ]
then
git fetch origin
git checkout master
for tool in ${toolsNIRALList[@]}
do
branchName=`git branch | grep -e "update-${tool}${localMainBranch}$"`
name=`expr "$branchName" : ".*\(update-.*\)$"`
if [ "$name" != "" ]; then
echo "Removing existing local branch: $branchName"
git branch -D $branchName
fi
done
for tool in ${toolsNIRALList[@]}
do
branchName=`git branch -a | grep -e "origin/update-${tool}${localMainBranch}$"`
name=`expr "$branchName" : ".*\(update-.*\)$"`
if [ "$name" != "" ]; then
echo "Removing existing remote branch: $name"
git push origin :$name
fi
done
exit 0
fi
echo "Update SlicerExtensions"
if [ "`git remote | grep -c upstream`" -eq 0 ]
then
git remote add upstream git://github.com/Slicer/ExtensionsIndex
fi
git fetch upstream
##################################################################
#Checks if mainBranch already exists locally. Otherwise we need to check it out.
if [ `git branch -a |grep -e "${mainBranch}$" |grep -ve "[a-z]" |grep -c ${mainBranch}` -eq 0 ]
then
echo "Branch was not detected locally, we need to checkout it out from the remote repository"
git checkout -b ${mainBranch} origin/${mainBranch}
fi
##################################################
git checkout $mainBranch
git reset --hard upstream/$mainBranch
git push origin $mainBranch
#For all the tools we want to update, go download latest version and compare with
#version that is currently included in this project (ExtensionsIndex). If a
#newer version exists, replace current version included in this project with
#latest version
for tool in ${toolsNIRALList[@]}
do
cd $binaryDir
echo "-----------------------------------------------------"
echo "Tool: $tool"
descriptionFile=$sourceDir/${tool}.s4ext
if [ ! -e $descriptionFile ]
then
echo "Description file $descriptionFile not found. Skipping $tool"
continue
fi
scm=`grep "scm" $descriptionFile`
descriptRevision=`grep "scmrevision" $descriptionFile`
descriptRevision=`expr "$descriptRevision" : " *scmrevision *\(\([a-f]*[0-9]*\)*\) *$"`
echo "Current Description file Revision: $descriptRevision"
repository=`grep "scmurl" $descriptionFile`
repository=`expr "$repository" : " *scmurl *\([a-z].*\)$"`
echo "Repository: $repository"
if [ "`echo $scm | grep -ci git`" -gt 0 ]
then
echo "$tool is a git project"
#Get source code
if [ ! -d $tool ] || [ ! "$(ls -A $tool)" ]
then
echo "git Repository: $repository"
git clone $repository $tool
cd $binaryDir/$tool
else
cd $binaryDir/$tool
echo "Pulling"
git pull origin master
fi
#get current (=latest) commit hash
currentgithash=`git rev-parse HEAD`
echo "Current Project Git hash: $currentgithash"
timeStampDescription=`git log -1 --format="%ct" $descriptRevision`
echo "Description time stamp: `git log -1 --format="%ci" $descriptRevision` - UNIX format: $timeStampDescription"
timeStampCurrent=`git log -1 --format="%ct" $currentgithash`
echo "Current time stamp: `git log -1 --format="%ci" $currentgithash` - UNIX format: $timeStampCurrent"
#if description commit hash is older than the last commit, we update the description file
if [ "$timeStampCurrent" -gt "$timeStampDescription" ]; then
#Create github diff link
repository=`expr "$repository" : "\(.*\)\.git"`
repository=`expr "$repository" : ".*github.com\/\(.*\)"`
diffmessage="https://www.github.com/$repository/compare/$descriptRevision%E2%80%A6$currentgithash"
ExtensionGit $sourceDir $tool $mainBranch $descriptionFile $descriptRevision $currentgithash "$diffmessage" $pushcleanArg $localMainBranch
fi
continue
fi
if [ "`echo $scm | grep -ci svn`" -gt 0 ]
then
echo "$tool is an SVN project"
###get username and password from description file
svnUser=`grep "svnusername" $descriptionFile`
svnUser="--username "`expr "$svnUser" : " *svnusername *\(\([a-z]*[0-9]*\)*\) *$"`
echo "SVN User Name: $svnUser"
svnPassword=`grep "svnpassword" $descriptionFile`
svnPassword="--password "`expr "$svnPassword" : " *svnpassword *\(\([a-z]*[0-9]*\)*\) *$"`
echo "SVN Password: $svnPassword"
#checkout or update project
if [ ! -d $tool ] || [ ! "$(ls -A $tool)" ]
then
echo "SVN Repository: $repository"
svn checkout $svnUser $svnPassword $repository $tool
cd $binaryDir/$tool
else
cd $binaryDir/$tool
svn update $svnUser $svnPassword
fi
#get current revision number
currentrevision=`svnversion`
echo "Current Revision: $currentrevision"
#if mismatch, update description file revision
if [ $currentrevision -gt $descriptRevision ] ;then
#get tool logs and copy them to the ExtensionIndex commit message
diffmessage=""
for i in `seq $currentrevision -1 $((descriptRevision+1))`
do
diffmessage=$diffmessage`svn log $svnUser $svnPassword -r $i`$'\n'
done
ExtensionGit $sourceDir $tool $mainBranch $descriptionFile $descriptRevision $currentrevision "$diffmessage" $pushcleanArg $localMainBranch
fi
continue
else
echo "$tool is of an unknown type. Skipping"
fi
done
cd $SOURCE_DIR
cd $currentDir