-
Notifications
You must be signed in to change notification settings - Fork 5
/
cy
executable file
·252 lines (204 loc) · 5.68 KB
/
cy
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/sh
#
# @(#) cy version 2.0.0 9/15/2015
#
# USAGE:
# init
#
# DESCRIPTION:
# Cytoscape 3 repository management utility.
# This script is only for core developers.
#
# Reqiirments:
# - git
# - git-flow
#
# By Keiichiro Ono (kono at ucsd edu)
#
###############################################################################
# Command Name
CMDNAME=$(basename $0)
# Error Message
ERROR_MESSAGE="Usage: $CMDNAME [-h] [action]"
# Help
HELP='Cytoscape repository management tool'
# Git base URL
BASE_URL='git@github.com:cytoscape/cytoscape-'
# Core Apps URL
APP_URL='git@github.com:cytoscape/'
NON_CORE_URL='git://github.com/cytoscape/cytoscape-'
# Cytoscape repository names
REPOSITORIES=(. parent api impl support app gui-distribution app-developer)
# List of Core Apps
CORE_APPS=(biopax command-dialog datasource-biogrid network-analyzer network-merge psi-mi sbml welcome webservice-psicquic-client webservice-biomart-client)
#######################################
# Handling command-line arguments #
#######################################
while getopts 'hrd:' OPT
do
case $OPT in
r) FLG_R=1
echo " - Using read-only repository."
;;
h) FLG_H=1
echo "$HELP: $ERROR_MESSAGE"
exit 0
;;
?) echo $ERROR_MESSAGE 1>&2
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
COMMAND=$1
TARGET_DIR=$2
if [[ -z $COMMAND ]]; then
echo "COMMAND is required. $ERROR_MESSAGE" 1>&2
exit 1
fi
###############################################################################
# Functrions
###############################################################################
function reset {
echo "This command resets all of your local changes!"
confirm
for REPO in "${REPOSITORIES[@]}"; do
echo "\n - Resetting local changes: $REPO"
pushd $REPO
git clean -f -d
git reset --hard
popd ..
done
}
function pull {
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO
echo "Downloading changes from upstream: $REPO"
git pull
popd
done
}
function push {
echo "- Sending all local commits to upstream..."
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO
git push -u origin
popd
done
}
function status {
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO || { echo Could not find subproject; exit 1; }
echo "\n- $REPO:"
git status
popd
done
}
function switch {
TARGET="${TARGET_DIR}"
if [[ -z $TARGET ]]; then
echo "Branch name is required: cy switch BRANCH_NAME" 1>&2
exit 1
fi
for REPO in "${REPOSITORIES[@]}"; do
echo "\n - Switching to ${TARGET}: $REPO"
pushd $REPO || { echo Could not find subproject; exit 1; }
# Switch
git checkout $TARGET || { echo Could not checkout branch $TARGET; }
popd
done
}
# Not finished yet.
function resetAll {
git checkout master
git reset --hard $(git BRANCH -av | grep "remotes/origin/master" | awk '{ print $2 }')
git clean -d -f
git checkout develop
git reset --hard $(git BRANCH -av | grep "remotes/origin/develop" | awk '{ print $2 }')
git clean -d -f
git checkout $BRANCH
git reset --hard $(git BRANCH -av | grep "remotes/origin/$BRANCH" | awk '{ print $2 }')
git clean -d -f
git BRANCH -avv
}
function confirm {
printf 'Do you really want to continue? Type [yes] to proceed: '
read answer
if [[ $answer != 'yes' || -z $answer ]]; then
echo "Abort\n"
exit 0
fi
}
#################################################################################
#
# Project initializer.
#
# This function clones top-level pom.xml and then clones all sub-projects
# into the top-level Cytoscape directory.
#
# Use -d option to specify directory. Otherwise, it will create new project
# in the current directory.
#
#################################################################################
function init {
# By default, clone everything in current directory.
echo "Target directory = $TARGET_DIR"
if [[ -z "$TARGET_DIR" ]]; then
TARGET_DIR=$(pwd)
elif ! [ -e "$TARGET_DIR" ]; then
echo "No such dir: $TARGET_DIR"
exit 1
fi
echo "Cytoscape project will be cloned to: ${TARGET_DIR}"
cd $TARGET_DIR || { echo Could not find target directory: $TARGET_DIR; exit 1; }
# Clone cy
let LENGTH=${#BASE_URL}-1
CY3REPO_URL=$(echo $BASE_URL | cut -c 1-$LENGTH)
git clone "${CY3REPO_URL}.git" || { echo Could not clone remote repository: $TARGET_DIR; exit 1; }
cd cytoscape
for REPO in "${REPOSITORIES[@]}"; do
if [ ${REPO} != . ]
then
REPO_URL="$BASE_URL$REPO.git"
echo "Cloning: $REPO (URI = $REPO_URL)"
git clone $REPO_URL $REPO || { echo Could not clone remote repository: $TARGET_DIR; exit 1; }
pushd $REPO
git checkout master
git flow init -d
git checkout develop
if [[ $REPO == "app" ]]; then
echo "Initializing Core App Submodules..."
git submodule init
git submodule update
fi
popd
fi
done
echo "\n\n - Finished: here is the current status:\n"
status
}
function apps {
mkdir ./apps
cd apps
for app in "${CORE_APPS[@]}"; do
echo "\n - Cloning $app"
REPO_URL="$APP_URL$app.git"
git clone $REPO_URL || { echo Could not clone remote repository: $REPO_URL; exit 1; }
done
cd ..
}
###############################################################################
# Main workflow
###############################################################################
# Save current directory location
START_DIR=$(pwd)
case $COMMAND in
init ) init ;;
reset ) reset ;;
push ) push ;;
pull ) pull ;;
switch ) switch ;;
status ) status ;;
apps ) apps ;;
* ) echo "Invalid command $COMMAND: $ERROR_MESSAGE"
exit 1;;
esac