datalad_sync.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from datetime import datetime
  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. # Give info on changes
  17. print('results of datalad status call:')
  18. dl.status(recursive=True, eval_subdataset_state ='commit', result_renderer ='tailored')
  19. # Set commit message
  20. commitmessage = input("Optionally enter a commit message, and hit return: ")
  21. if not commitmessage:
  22. print("using date as commit message")
  23. commitmessage = "commit on " + datetime.now().strftime("%B %d, %Y")
  24. # sync
  25. print("update changes from server")
  26. dl.update(how='merge', recursive=True)
  27. print("saving changes")
  28. dl.save(".", message=commitmessage, recursive=True)
  29. print("pushing saved changes to server")
  30. dl.push(to="origin", recursive=True)
  31. # Set dropping option
  32. 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]")
  33. if q_answer == "y":
  34. dl.drop(".", recursive=True)