use dash_open

This commit is contained in:
Thomas Waldmann 2017-07-04 02:56:50 +02:00
parent a96dede632
commit e728d102ec
1 changed files with 7 additions and 14 deletions

View File

@ -65,6 +65,7 @@ from .helpers import basic_json_data, json_print
from .helpers import replace_placeholders from .helpers import replace_placeholders
from .helpers import ChunkIteratorFileWrapper from .helpers import ChunkIteratorFileWrapper
from .helpers import popen_with_error_handling from .helpers import popen_with_error_handling
from .helpers import dash_open
from .nanorst import rst_to_terminal from .nanorst import rst_to_terminal
from .patterns import ArgparsePatternAction, ArgparseExcludeFileAction, ArgparsePatternFileAction, parse_exclude_pattern from .patterns import ArgparsePatternAction, ArgparseExcludeFileAction, ArgparsePatternFileAction, parse_exclude_pattern
from .patterns import PatternMatcher from .patterns import PatternMatcher
@ -778,10 +779,8 @@ class Archiver:
else: else:
filter = args.tar_filter filter = args.tar_filter
if args.tarfile == '-': tarstream = dash_open(args.tarfile, 'wb')
tarstream, tarstream_close = sys.stdout.buffer, False tarstream_close = args.tarfile != '-'
else:
tarstream, tarstream_close = open(args.tarfile, 'wb'), True
if filter: if filter:
# When we put a filter between us and the final destination, # When we put a filter between us and the final destination,
@ -1737,10 +1736,7 @@ class Archiver:
fd.write('\n') fd.write('\n')
fd.write(' ]\n}\n') fd.write(' ]\n}\n')
if args.path == '-': with dash_open(args.path, 'w') as fd:
output(sys.stdout)
else:
with open(args.path, 'w') as fd:
output(fd) output(fd)
return EXIT_SUCCESS return EXIT_SUCCESS
@ -1752,10 +1748,7 @@ class Archiver:
meta = prepare_dump_dict(msgpack.fallback.unpackb(data, object_hook=StableDict, unicode_errors='surrogateescape')) meta = prepare_dump_dict(msgpack.fallback.unpackb(data, object_hook=StableDict, unicode_errors='surrogateescape'))
if args.path == '-': with dash_open(args.path, 'w') as fd:
json.dump(meta, sys.stdout, indent=4)
else:
with open(args.path, 'w') as fd:
json.dump(meta, fd, indent=4) json.dump(meta, fd, indent=4)
return EXIT_SUCCESS return EXIT_SUCCESS