Skip to content

Commit

Permalink
test webpages rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
TomKellyGenetics committed Feb 11, 2020
1 parent 3e838cb commit 08a9ce2
Showing 1 changed file with 138 additions and 24 deletions.
162 changes: 138 additions & 24 deletions wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
# sh wrapper.sh --repo make-novice --create
# sh wrapper.sh --repo make-novice --import
# sh wrapper.sh --repo make-novice --account GitHubUser --import

# sh wrapper.sh --repo r-novice-gapmnder --account swcarpentry-ja --import --webpages

# create (implemented): subroutine to create new PO files from an English lesson not currently being translated
# import (testing): subroutine to pull a lesson being translated from remote to make changes locally
# webpages (work-in-progress): subroutine to render webpages from current PO files and export Japanese lessons to remote repos
# webpages (testing): subroutine to render webpages from current PO files and export Japanese lessons to remote repos
# update (to-do later): subroutine to pull updates from remote English lesson and merge based on archived ancestor (only new sections need to be translated)


pc_user=`whoami`
echo $pc_user account for pc `hostname`
git_user=`git config user.name`
remote_user=$git_user
git_email=`git config user.email`
remote_account=$git_user
echo $git_user \<${git_email}\> account detected for git
Expand Down Expand Up @@ -58,7 +59,7 @@ for op in "$@"; do
remote_user="${1/%\//}"
next=true
else
echo("specify remote account for: $git_user")
echo "specify remote account for: $git_user"
remote_user=$git_user
next=true
fi
Expand All @@ -80,7 +81,7 @@ for op in "$@"; do
;;
-u|--update)
shift
import=true
update=true
next=true
;;
-*)
Expand Down Expand Up @@ -111,19 +112,34 @@ echo import ${repo} : $import
echo render webpages : $render

#check if remote i18n repo exists
root_dir=`git ls-remote https://github.com/$remote_user/i18n.git | grep "ja" | wc -l`
root_dir=`git ls-remote https://github.com/${remote_user}/i18n.git | grep "ja" | wc -l`
echo i18 repo: $root_dir
if [ $root_dir -eq 1 ]; then
echo "remote found: https://github.com/$remote_user/i18n.git"
echo "remote found: https://github.com/${remote_user}/i18n.git"
elif [ $root_dir -eq 0 ]; then
echo remote not found for user repo: https://github.com/$remote_user/i18n.git \n please create a fork
echo remote not found for user repo: https://github.com/${remote_user}/i18n.git \n please create a fork
exit 1
else
echo ambiguous repo:
git ls-remote https://github.com/$remote_user/i18n.git
git ls-remote https://github.com/${remote_user}/i18n.git
exit 1
fi

#check if remote repo exists
root_dir=`git ls-remote https://github.com/${remote_user}/${repo}.git | grep "ja" | wc -l`
echo i18 repo: $root_dir
if [ $root_dir -eq 1 ]; then
echo "remote found: https://github.com/${remote_user}/${repo}.git"
elif [ $root_dir -eq 0 ]; then
echo remote not found for user repo: https://github.com/${remote_user}/${repo}.git \n please create a fork
exit 1
else
echo ambiguous repo:
git ls-remote https://github.com/${remote_user}/${repo}.git
exit 1
fi


if [[ $create == true ]]; then
echo "runnning"
if [[ -d i18n ]]; then
Expand All @@ -148,8 +164,41 @@ if [[ $create == true ]]; then
git submodule init
git submodule import

echo "import local submodules"
git submodule import --recursive --remote --merge
echo "update local submodules"
#git submodule update --recursive --merge

#remove _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
if [ `git remote -v | grep "swc-ja" | wc -l` -ge 1 ]
then
git remote remove swc-ja
fi
#reset all repos to remote
url=https://github.com/swcarpentry-ja/${dir}.git
git remote add swc-ja $url
if [[ `git branch -v | grep "master" | wc -l` -ge 1 ]]
then
git pull master -f
fi
git remote add swc-ja $url
if [[ `git branch -v | grep "gh-pages" | wc -l` -ge 1 ]]
then
git branch -D gh-pages
fi
git checkout -b gh-pages `git rev-list HEAD | tail -n 1`
git pull swc-ja gh-pages -f
git add -u
git commit -m "reset branch"
git checkout HEAD
rm -rf _locale
cd ..
fi
done


if [[ ! -z $repo ]]; then
if [[ -d $repo ]]; then
Expand Down Expand Up @@ -203,6 +252,18 @@ if [[ $create == true ]]; then
echo "run compile on po4gitbook to create new lessson"
po4gitbook/compile.sh > /dev/null 2>&1
echo lesson $repo created in locale/ja/$repo

#restore _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
git reset --hard
cd ..
fi
done

fi

if [[ $import == true ]]; then
Expand All @@ -229,8 +290,41 @@ if [[ $import == true ]]; then
git submodule init
git submodule import

echo "import local submodules"
git submodule import --recursive --remote --merge
echo "update local submodules"
git submodule update --recursive --remote --merge

#remove _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
if [ `git remote -v | grep "swc-ja" | wc -l` -ge 1 ]
then
git remote remove swc-ja
fi
#reset all repos to remote
url=https://github.com/swcarpentry-ja/${dir}.git
git remote add swc-ja $url
if [[ `git branch -v | grep "master" | wc -l` -ge 1 ]]
then
git pull master -f
fi
git remote add swc-ja $url
if [[ `git branch -v | grep "gh-pages" | wc -l` -ge 1 ]]
then
git branch -D gh-pages
fi
git checkout -b gh-pages `git rev-list HEAD | tail -n 1`
git pull swc-ja gh-pages -f
git add -u
git commit -m "reset branch"
git checkout HEAD
rm -rf _locale
cd ..
fi
done


if [[ ! -z $repo ]]; then
if [[ -d $repo ]]; then
Expand All @@ -253,7 +347,7 @@ if [[ $import == true ]]; then
fi
fi

if [[ $import == true ]]; then
if [[ $render == true ]]; then
echo "runnning"
if [[ -d i18n ]]; then
cd i18n
Expand Down Expand Up @@ -309,7 +403,6 @@ if [[ $import == true ]]; then
#create all Japanese lessons
echo "run compile on po4gitbook"
find
po4gitbook/compile.sh > /dev/null 2>&1
#commite updates to source PO files
Expand Down Expand Up @@ -344,33 +437,54 @@ find
#add update lessons to remote
cd ../${repo}-ja
git init
remotes=`git remote | grep "swc" | wc -l`
remotes=`git remote | grep "swc-ja" | wc -l`
if [[ remotes -le 0 ]]; then
git remote add swc https://github.com/$remote_user/$repo-ja.git
git remote add swc-ja https://github.com/$remote_user/$repo-ja.git
fi
git pull swc master
git pull swc-ja master
# remove files provided by template
rm -rf bin/boilerplate
rm -rf _layouts _includes _episodes_rmd assets bin code
git add *
git commit -m "update lesson files"
git push swc master
git push swc-ja master
#update original lesson to import translated content
cd ../i18n # or English lesson
git submodule foreach git pull origin master
#####################################
# to do : create locale submodule #
# in original lesson if none exists #
###############$#####################
#restore locale lessons (only English lessons translated)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
git reset --hard
cd ..
fi
done
cd ${repo}
git add -u
#create lesson in locale if not existing or update
if [ -d ./locale/ja ]
then
cd locale/ja
git pull origin master
cd ../..
else
mkdir -p locale
url="https://github.com/$remote_user/${repo}-ja.git"
git submodule add $url ./locale/ja
fi
#push updated locale lessons to English lesson
git add -u
git commit -m "update Japanese lessons"
git push origin gh-pages
git push swc-ja gh-pages
cd ..
fi

0 comments on commit 08a9ce2

Please sign in to comment.