datalad_sync.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from heapq import merge
  2. import os
  3. import sys
  4. import datalad.api as dl
  5. # Set folder where script will be executed
  6. loc = os.path.dirname(os.path.abspath(__file__))
  7. print(loc)
  8. os.chdir(loc)
  9. os.chdir('../')
  10. #projectdir = dl.Repo(loc, create=False).get_toppath()
  11. # initialise
  12. if not os.path.isfile("06_dissemination/README_DISSEMINATION.md"):
  13. print("running project repository initiation (first run)")
  14. dl.get(".", recursive=True, get_data=False)
  15. dl.update(how='merge', recursive=True)
  16. # Set commit message
  17. commitmessage = input("Optionally enter a commit message, and hit return: ")
  18. if not commitmessage:
  19. print("using date as commit message")
  20. commitmessage = "commit on" + {datetime.now().strftime('%Y-%m-%d')}
  21. # sync
  22. dl.update(how='merge', recursive=True)
  23. dl.save(".", message=commitmessage, recursive=True)
  24. dl.push(".", to="origin", recursive=True)
  25. # Set dropping option
  26. 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]")
  27. if q_answer == "y":
  28. dl.drop(".", recursive=True)