Kaynağa Gözat

adding manual elements

julien colomb 1 yıl önce
ebeveyn
işleme
5247588f61
9 değiştirilmiş dosya ile 349 ekleme ve 0 silme
  1. 12 0
      .Rprofile
  2. 6 0
      .notinlabreport.txt
  3. 112 0
      .scripts/GIN-sync
  4. 40 0
      .scripts/datalad_sync.py
  5. 27 0
      .scripts/setginserver
  6. 61 0
      .scripts/template_init.command
  7. 76 0
      sync-gin-unix
  8. 8 0
      sync.bat
  9. 7 0
      sync_unix

+ 12 - 0
.Rprofile

@@ -0,0 +1,12 @@
+source("~/.Rprofile")
+message ("\n
+         ")
+message ("This is a tonic repository with submodule, use git functionalities of Rstudio only with care.
+You may want to make a project out of the data analysis submodule to control the versions of the code.
+Refer to https://gindata.biologie.hu-berlin.de/G-Node/info/wiki/Working+with+Rstudio.  
+         
+To update all the data in all repositories 
+  Use the sync script or run  `datalad get -n -r .` in the terminal ;)")
+  
+
+

+ 6 - 0
.notinlabreport.txt

@@ -0,0 +1,6 @@
+Please run the GIN initiation script (datalad scripts is not doing this (yet?).
+
+This will push the dissemination and figures to the lab report repository.
+
+
+This file will also be removed.

+ 112 - 0
.scripts/GIN-sync

@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+#
+# Upload changes from inside repository using GIN CLI
+# Works with submodules.
+# needs git config to be set and user should be logged in
+# needs submodules and main repo to be initialised (gin init)
+
+
+
+
+
+
+
+# Checking synchronisation option and giving feedback
+checkargs() {
+    case "$1" in
+        download)
+            echo "Downloading and keep all large file content"
+            ;;
+        keep)
+            echo "Keeping existing local large file content, do not downlad extra files"
+            ;;
+        remove)
+            echo "Removing all local large file content"
+            ;;
+        *)
+            usage
+            ;;
+    esac
+}
+
+checkargs "${syncopt}"
+
+checkerror() {
+    err=$1
+    msg=$2
+    if [[ ${err} != 0 ]]; then
+        echo "${msg}" >> ./.log/gin.log
+	echo "${err}" >> ./.log/gin.log
+        echo "${msg}"
+        echo "Press [Enter] to close this window"
+        read -r
+        exit 1
+    fi
+}
+
+# Set commit message
+echo "Optionally enter a commit message, and hit return: "  
+read commitmessage 
+
+if [[ "$commitmessage" == "" ]]; then
+        echo "using date as commit message"
+	commitmessage="commit on $(date +%Y-%m-%d)"    
+fi
+
+
+# write log
+mkdir -p ./.log
+echo "$(date +'%Y-%m-%dT%H:%M:%S'): Sync script executed" >> ./.log/gin.log
+
+# create empty .gitmodules if it does not exist
+FILE=.gitmodules
+if [ -f "$FILE" ]; then
+    echo "$FILE already exists."
+else 
+    touch "$FILE"
+fi
+
+echo "intialise submodules"
+gin git submodule foreach gin init
+
+echo "Synchronising submodules"
+gin git submodule foreach gin commit . -m "$commitmessage"
+checkerror $? "Error occurred during 'gin commit'"
+gin git submodule foreach gin sync
+checkerror $? "Error occurred during 'gin sync'"
+
+gin git submodule foreach gin upload
+checkerror $? "Error occurred during 'gin upload'"
+
+## remove uploaded (annexed) content
+if [[ "$syncopt" == "remove" ]]; then
+        git submodule foreach gin remove-content 
+        checkerror $? "Error occurred during 'gin remove-content'"
+    fi
+# get annexed content 
+if [[ "${syncopt}" == "download" ]]; then
+        git submodule foreach gin get-content .
+        checkerror $? "Error occurred during 'gin get-content .'"
+    fi    
+
+
+echo "Synchronising main repository"
+
+# add content
+gin commit . -m "$commitmessage"
+# add submodule changes 
+gin git commit . --amend -m "$commitmessage"
+# upload files
+gin sync
+gin upload
+
+# remove uploaded (annexed) content
+if [[ "$syncopt" == "remove" ]]; then
+        gin remove-content 
+        checkerror $? "Error occurred during 'gin remove-content' in main repo"
+    fi
+# get annexed content 
+if [[ "${syncopt}" == "download" ]]; then
+        gin get-content .
+        checkerror $? "Error occurred during 'gin get-content . in main repo'"
+    fi   

+ 40 - 0
.scripts/datalad_sync.py

@@ -0,0 +1,40 @@
+from datetime import datetime
+import os
+import sys
+
+import datalad.api as dl
+
+# Set folder where script will be executed
+loc = os.path.dirname(os.path.abspath(__file__))
+print(loc)
+os.chdir(loc)
+os.chdir('../')
+#projectdir = dl.Repo(loc, create=False).get_toppath()
+
+# initialise
+if not os.path.isfile("06_dissemination/README_DISSEMINATION.md"):
+    print("running project repository initiation (first run)")
+    dl.get(".", recursive=True, get_data=False)
+    dl.update(how='merge', recursive=True)
+
+# Give info on changes
+print('results of datalad status call:')
+dl.status(recursive=True, eval_subdataset_state ='commit', result_renderer ='tailored')
+
+# Set commit message
+commitmessage = input("Optionally enter a commit message, and hit return: ")
+if not commitmessage:
+    print("using date as commit message")
+    commitmessage = "commit on " + datetime.now().strftime("%B %d, %Y")
+# sync
+print("update changes from server")
+dl.update(how='merge', recursive=True)
+print("saving changes")
+dl.save(".", message=commitmessage, recursive=True)
+print("pushing saved changes to server")
+dl.push(to="origin", recursive=True)
+
+# Set dropping option
+q_answer = input("Do you want to drop all files that were uploaded, they will be on the server but not on this computer anymore ? [y/n]")
+if q_answer == "y":
+    dl.drop(".", recursive=True)

+ 27 - 0
.scripts/setginserver

@@ -0,0 +1,27 @@
+# set server, use HU server
+if ! gin use-server hu; then
+  echo "set gin server"
+  # set gin remote from git information (on the hu server)
+  gin add-server --web https://gindata.biologie.hu-berlin.de:443 --git git@gindata.biologie.hu-berlin.de:10022 hu
+fi
+
+# chose hu server for this computer
+  gin use-server hu
+  
+# set remote
+if ! gin remotes; then
+  echo "set gin remote"
+  # set gin remote from git information (on the hu server)
+  remotegit=$(git remote get-url origin)
+  remotegin="$(echo "$remotegit" | cut -d'/' -f4,5)"
+
+  remotegin="$(echo $remotegin | cut -d' ' -f1)"
+  remotegin="$(echo "hu:""${remotegin/.git}")"
+  gin add-remote primary "$remotegin"
+else
+    echo gin remote set
+fi
+
+
+
+

+ 61 - 0
.scripts/template_init.command

@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+#
+# update template submodules manually
+# run once in the main folder after the template has been made by tonic
+
+
+
+# Set folder where script will be executed
+#loc=$(dirname $0)
+#projectdir=$(git -C ${loc} rev-parse --show-toplevel)
+#
+#pushd ${loc} > /dev/null
+
+# get info for gin remote information
+
+GINinfo="$(gin remotes)"
+Gitadress="$(echo $GINinfo | cut -d'/' -f3)"
+
+Orga="$(echo $GINinfo | cut -d'/' -f4)"
+repo2="$(echo $GINinfo | cut -d'/' -f5)"
+repo="$(echo $repo2 | cut -d' ' -f1)"
+reposhort="$(echo "${repo/.main}")"
+
+
+
+# add some submodules to labreport repository.
+
+gin git submodule update --init --recursive
+
+if test -f ".notinlabreport.txt" ;
+  then
+    # delete file telling the initialisation need to be done
+    rm ".notinlabreport.txt"
+    
+    # add submodule to PI repo
+    # get labreports repo and write new folder for the project
+    cd ../
+    gin get ""$Orga""/labreports""
+    cd labreports
+    mkdir "$reposhort"
+    mkdir "$reposhort/05_figures"
+    
+    
+    # add 2 submodule for figures and dissemination files there
+    
+    gin git submodule add "../$reposhort.05_figures_990_shared_figures.git" ""$reposhort"/05_figures/990_shared_figures"
+    gin git submodule add "../$reposhort.06_dissemination" ""$reposhort"/06_dissemination"
+    
+    # add a file to tell the user/script to initialise the submodules next time.
+    
+    echo "submodules need intitialisation due to project "$reposhort"." >> "initialise.txt"
+
+    gin git add "initialise.txt"
+   
+    # push changes on the server and remove the repo from the computer.
+    gin git commit  -m "added project $reposhort"
+
+    gin upload
+    cd ../
+    rm -rf labreports
+fi

+ 76 - 0
sync-gin-unix

@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+#
+# Initialise or Upload changes from inside repository
+# using GIN CLI
+# Works with submodules and repo made by tonic v1 (not copying submodules content).
+# needs git config to be set 
+# needs SSH access to GIN
+# future dvt using datalad will allow use of non-GIN repositories
+
+# logic: template has a specific file to label it needs initialisation.
+# if this file is present, code 1 is done: template_initialisation
+# if it is absent but submodules are empty, code 2 is done: submodule_initialisation
+# if none of the above code 3 is done: synchronisation
+
+# Set folder where script will be executed 
+loc=$(dirname $0)
+projectdir=$(git -C ${loc} rev-parse --show-toplevel)
+
+pushd ${loc} > /dev/null
+
+## set gin server and remote
+
+sh .scripts/setginserver
+
+
+#login if needed
+if ! gin info; then
+  echo "set gin login"
+  gin login
+else
+    echo "gin logged"
+fi
+
+## code 1, add to labreports
+if test -f ".notinlabreport.txt" ;
+  then
+  echo "Adding project to labreports repository."
+  sh .scripts/template_init.command
+fi
+## code 2, initialising
+
+if grep -q 06_dissemination ".gitmodules"; 
+  then
+  if  (test -f "06_dissemination/README_DISSEMINATION.md") ;
+    then
+    echo "submodules are initialised"
+
+    else
+    echo "initialising submodules"
+    gin git submodule update --init --recursive
+    gin git submodule foreach gin init
+    fi
+  else
+  echo "not a tonic repo, please initialise submodules manually if there are any"
+fi 
+
+
+## code 3
+
+
+usage() {
+    echo "$0 <sync-option>"
+    echo
+    echo "<sync-option>     The sync option defines what to do with the content of large files."
+    echo "                  It should be one of the following values:"
+    echo "                     download - Download all large file content from the server"
+    echo "                     keep     - Keep all large file content but do not download missing large files"
+    echo "                     remove   - Do not download large files and remove existing local large file content"
+    exit 1
+}
+
+# Set the variable for synchronisation option, see above 
+syncopt="remove"
+
+echo "start synchronisation in "$syncopt" mode, close window to cancel. change mode by changing the code in a text application"
+sh .scripts/GIN-SYNC

+ 8 - 0
sync.bat

@@ -0,0 +1,8 @@
+:: this script should run the sync bash script on windows, once cygwin has been installed
+
+set curdir=%~dp0
+
+python .scripts/datalad_sync.py
+
+
+pause

+ 7 - 0
sync_unix

@@ -0,0 +1,7 @@
+# Set folder where script will be executed 
+loc=$(dirname $0)
+projectdir=$(git -C ${loc} rev-parse --show-toplevel)
+
+pushd ${loc} > /dev/null
+
+python3 .scripts/datalad_sync.py