-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve script to update solutions & data
- Loading branch information
1 parent
963aa11
commit 88b175c
Showing
2 changed files
with
97 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,60 @@ | ||
#!/bin/bash | ||
|
||
if [[ $# < 1 ]]; then | ||
echo "usage: $0 project" | ||
echo "" | ||
echo "where project is one of 'shotgun', 'fmri' or 'robot'" | ||
exit 1 | ||
if [[ $1 == "help" ]]; then | ||
cat <<EOH | ||
Usage: | ||
- update solutions for all projects to latest version: | ||
$ $0 | ||
- update data for all projects to latest version: | ||
$ $0 data | ||
- update solutions to specific version (get version checksum from history): | ||
$ $0 2d6b147 | ||
- display this help page: | ||
$ $0 help | ||
EOH | ||
exit 1 | ||
fi | ||
|
||
user=kcl-bmeis | ||
repo=oop | ||
|
||
case $1 in | ||
shotgun) | ||
branch=shotgun_sequencing_solution | ||
remote_folder=projects/DNA_shotgun_sequencing/solution | ||
;; | ||
fmri) | ||
branch=fmri_solution | ||
remote_folder=projects/fMRI/solution | ||
;; | ||
fmri) | ||
branch=robot_solution | ||
remote_folder=projects/robot_arm/solution | ||
;; | ||
*) | ||
echo "no such project: $1" | ||
exit 1; | ||
;; | ||
esac | ||
|
||
|
||
curl -s https://api.github.com/repos/$user/$repo/git/trees/$branch?recursive=1 | \ | ||
while read -r line; do | ||
[[ "$line" =~ \"path\":\ *\"${remote_folder}/(.*)\" ]] || continue | ||
filename=${BASH_REMATCH[1]}; | ||
echo updating $filename | ||
curl --silent --create-dirs --output $filename https://raw.githubusercontent.com/$user/$repo/$branch/$remote_folder/$filename | ||
what=solution | ||
[[ $1 == "data" ]] && { what="data"; shift; } | ||
|
||
# get_folder_listing branch root_folder subfolder | ||
get_folder_listing() { | ||
# Avoid using GitHub API due to rate limiting restrictions: | ||
curl --silent https://github.com/$user/$repo/tree/$1/$2/$3 | while read -r line; do | ||
[[ "$line" =~ \"tree\":\{\"items\":\[([^\]]*)\] ]] || continue; | ||
items=${BASH_REMATCH[1]}; | ||
while [[ "$items" =~ ^[^\}]*\"path\":\"([^\"]*)[^\}]*\"contentType\":\"([^\"]*)[^\}]*\} ]]; do | ||
if [[ ${BASH_REMATCH[2]} == "directory" ]]; then | ||
get_folder_listing $1 $2 ${BASH_REMATCH[1]#"$2"} | ||
else | ||
echo ${BASH_REMATCH[1]} | ||
fi | ||
items="${items#"${BASH_REMATCH[0]}"}"; | ||
done; | ||
done | ||
} | ||
|
||
# update_project_files branch project_folder [SHA1] | ||
update_project_files() { | ||
branch=${3:-$1} | ||
for filename in $(get_folder_listing $branch projects/$2 $what); do | ||
local_filename=${filename#projects/} | ||
echo updating $local_filename | ||
curl --silent --create-dirs --output $local_filename https://raw.githubusercontent.com/$user/$repo/$branch/$filename | ||
done | ||
} | ||
|
||
update_project_files shotgun_sequencing_solution DNA_shotgun_sequencing $1 | ||
update_project_files fmri_solution fMRI $1 | ||
update_project_files robot_solution robot_arm $1 | ||
|
||
|
||
|