Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys, os
  4. print os.path.basename(sys.argv[0]), sys.argv[1:]
  5.  
  6. $ 1.py -1 dfd 'gf g' "df df"
  7. 1.py ['-1', 'dfd', 'gf g', 'df df']
  8.  
  9. args = parser.parse_args()
  10.  
  11. logName = "." + (os.path.splitext(os.path.basename(sys.argv[0])))[0] + ".json"
  12. if os.path.exists(logName):
  13. print "!!! I've found log", logName
  14. Args = bk_loads_json(logName)
  15. for arg in Args:
  16. exec('args.{0} = Args["{0}"]'.format(arg))
  17. else:
  18. print "!!! the log of args is saved to", logName
  19. bk_saves_json(args.__dict__, logName)
  20.  
  21. def bk_saves_json(myCustomDct, flNm):
  22. "Takes dict, and writes it to the file."
  23.  
  24. FlNm = open(flNm, 'w')
  25. tmpJsn = json.dumps(myCustomDct, sort_keys=True, indent=4)
  26. FlNm.write(tmpJsn)
  27. FlNm.close()
  28.  
  29. def bk_loads_json(flNm):
  30. "Takes file of the json and returns it as a dict."
  31.  
  32. json_data=open(flNm)
  33. data = json.load(json_data)
  34. json_data.close()
  35. return data
  36.  
  37. import pipes # or shlex if python3
  38. print sys.argv[0], ' '.join( [pipes.quote(s) for s in sys.argv[1:]] )
  39.  
  40. import subprocess, sys
  41. print subprocess.list2cmdline(sys.args[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement