datalad_sync.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. # 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('%Y-%m-%d')}
  24. # sync
  25. dl.update(how='merge', recursive=True)
  26. dl.save(".", message=commitmessage, recursive=True)
  27. dl.push(".", to="origin", recursive=True)
  28. # Set dropping option
  29. 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]")
  30. if q_answer == "y":
  31. dl.drop(".", recursive=True)