datalad_sync.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. statuslist = 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. print("list of files to drop")
  33. # get data from datalad status, where state was not clean, and print each element in one row:
  34. for v in statuslist:
  35. if v['state']!="clean":
  36. statuslist3 += [v['path']]
  37. for v in statuslist3:
  38. print(v)
  39. q_answer = input("Do you want to erase (from this computer) all the big files that were uploaded just now, they will be on the server, you can downlaod them with `datalad get <path-to-file>` ? [y/n]")
  40. if q_answer == "y":
  41. for v in statuslist3:
  42. dl.drop(print(v), recursive=True)
  43. q_answer = input("Do you want to drop all big files, they will be on the server but not on this computer anymore ? [y/n]")
  44. if q_answer == "y":
  45. dl.drop(".", recursive=True)