Commit 7b4a264e authored by Pavel Emelyanov's avatar Pavel Emelyanov

crit: Small inf/outf evaluation cleanup

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a9ccdccc
...@@ -26,45 +26,35 @@ def handle_cmdline_opts(): ...@@ -26,45 +26,35 @@ def handle_cmdline_opts():
return opts return opts
def inf(opts):
if opts['in']:
return open(opts['in'], 'r')
else:
return sys.stdin
def outf(opts):
if opts['out']:
return open(opts['out'], 'w+')
else:
return sys.stdout
def decode(opts): def decode(opts):
indent = None indent = None
img = pycriu.images.load(inf(opts))
# If no input file is set -- stdin is used.
if opts['in']:
with open(opts['in'], 'r') as f:
img = pycriu.images.load(f)
else:
img = pycriu.images.load(sys.stdin)
# For stdout --format nice is set by default. # For stdout --format nice is set by default.
if opts['format'] == 'nice' or (opts['format'] == None and opts['out'] == None): if opts['format'] == 'nice' or (opts['format'] == None and opts['out'] == None):
indent = 4 indent = 4
# If no output file is set -- stdout is used. f = outf(opts)
if opts['out']: json.dump(img, f, indent=indent)
with open(opts['out'], 'w+') as f: if f == sys.stdout:
json.dump(img, f, indent=indent) f.write("\n")
else:
json.dump(img, sys.stdout, indent=indent)
sys.stdout.write("\n")
def encode(opts): def encode(opts):
# If no input file is set -- stdin is used. img = json.load(inf(opts))
if opts['in']: pycriu.images.dump(img, outf(opts))
with open(opts['in'], 'r') as f:
img = json.load(f)
else:
img = json.load(sys.stdin)
# If no output file is set -- stdout is used.
if opts['out']:
with open(opts['out'], 'w+') as f:
pycriu.images.dump(img, f)
else:
pycriu.images.dump(img, sys.stdout)
def main(): def main():
#Handle cmdline options #Handle cmdline options
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment