Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys, os
- print os.path.basename(sys.argv[0]), sys.argv[1:]
- $ 1.py -1 dfd 'gf g' "df df"
- 1.py ['-1', 'dfd', 'gf g', 'df df']
- args = parser.parse_args()
- logName = "." + (os.path.splitext(os.path.basename(sys.argv[0])))[0] + ".json"
- if os.path.exists(logName):
- print "!!! I've found log", logName
- Args = bk_loads_json(logName)
- for arg in Args:
- exec('args.{0} = Args["{0}"]'.format(arg))
- else:
- print "!!! the log of args is saved to", logName
- bk_saves_json(args.__dict__, logName)
- def bk_saves_json(myCustomDct, flNm):
- "Takes dict, and writes it to the file."
- FlNm = open(flNm, 'w')
- tmpJsn = json.dumps(myCustomDct, sort_keys=True, indent=4)
- FlNm.write(tmpJsn)
- FlNm.close()
- def bk_loads_json(flNm):
- "Takes file of the json and returns it as a dict."
- json_data=open(flNm)
- data = json.load(json_data)
- json_data.close()
- return data
- import pipes # or shlex if python3
- print sys.argv[0], ' '.join( [pipes.quote(s) for s in sys.argv[1:]] )
- import subprocess, sys
- print subprocess.list2cmdline(sys.args[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement