Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. from yaml import load, dump
  2. try:
  3. from yaml import CLoader as Loader, CDumper as Dumper
  4. except ImportError:
  5. from yaml import Loader, Dumper
  6. import yaml, tempfile, subprocess, sys
  7.  
  8. def edit(data):
  9.  
  10. fd, temp_path = tempfile.mkstemp(prefix='punctual.')
  11. with open(temp_path, "r+") as f:
  12. f.write(yaml.safe_dump(data, default_flow_style=False, allow_unicode=True))
  13. f.truncate()
  14. f.close()
  15.  
  16. while True:
  17. with open(temp_path, "r+") as f:
  18. subprocess.check_call('vim -c "set syntax=yaml" ' + temp_path, shell=True)
  19. f.close
  20. try:
  21. data = yaml.load(open(temp_path,"r+").read())
  22. break
  23. except Exception as E:
  24. print(E)
  25. input("Press Enter to continue...")
  26. return data
  27.  
  28. edit({})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement