datalad_sync.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. #projectdir = dl.Repo(loc, create=False).get_toppath()
  10. # initialise
  11. if not os.path.isfile("06_dissemination/README_DISSEMINATION.md"):
  12. print("running project repository initiation (first run)")
  13. dl.get(".", recursive=True, get_data=False)
  14. dl.update(merge=True, recursive=True)
  15. # Set commit message
  16. commitmessage = input("Optionally enter a commit message, and hit return: ")
  17. if not commitmessage:
  18. print("using date as commit message")
  19. commitmessage = "commit on" + {datetime.now().strftime('%Y-%m-%d')}
  20. # sync
  21. dl.update(merge=True, recursive=True)
  22. dl.save(".", message=commitmessage, recursive=True)
  23. dl.push(".", to="origin", recursive=True)
  24. # Set dropping option
  25. 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]")
  26. if q_answer == "y":
  27. dl.drop(".", recursive=True)