datalad_sync.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 = print("commit on" , datetime.now())
  24. # sync
  25. print("update")
  26. dl.update(how='merge', recursive=True)
  27. print("save")
  28. dl.save(".", message=commitmessage, recursive=True)
  29. print("push")
  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)