def exit_signal_handler(sigcode, frame):
sys.exit(-sigcode)
-def main(arguments=None, output_to=sys.stdout):
+def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
args = parse_arguments(arguments)
if args.progress:
except (IOError, OSError):
pass # Couldn't open cache directory/file. Continue without it.
except ResumeCacheConflict:
- output_to.write(
+ stdout.write(
"arv-put: Another process is already uploading this data.\n")
sys.exit(1)
for sigcode in CAUGHT_SIGNALS}
if writer.bytes_written > 0: # We're resuming a previous upload.
- print >>sys.stderr, "\n".join([
+ print >>stderr, "\n".join([
"arv-put: Resuming previous upload from last checkpoint.",
" Use the --no-resume option to start over."])
writer.finish_current_stream()
if args.progress: # Print newline to split stderr from stdout for humans.
- print >>sys.stderr
+ print >>stderr
if args.stream:
output = writer.manifest_text()
# Print the locator (uuid) of the new collection.
output = collection['uuid']
- output_to.write(output)
+ stdout.write(output)
if not output.endswith('\n'):
- output_to.write('\n')
+ stdout.write('\n')
for sigcode, orig_handler in orig_signal_handlers.items():
signal.signal(sigcode, orig_handler)
class ArvadosPutTest(ArvadosKeepLocalStoreTestCase):
def call_main_on_test_file(self):
- self.main_output = StringIO()
+ self.main_stdout = StringIO()
+ self.main_stderr = StringIO()
with self.make_test_file() as testfile:
path = testfile.name
- arv_put.main(['--stream', '--no-progress', path], self.main_output)
+ arv_put.main(['--stream', '--no-progress', path],
+ self.main_stdout, self.main_stderr)
self.assertTrue(
os.path.exists(os.path.join(os.environ['KEEP_LOCAL_STORE'],
'098f6bcd4621d373cade4e832627b4f6')),
"did not find file stream in Keep store")
+ def tearDown(self):
+ for outbuf in ['main_stdout', 'main_stderr']:
+ if hasattr(self, outbuf):
+ getattr(self, outbuf).close()
+ delattr(self, outbuf)
+ super(ArvadosPutTest, self).tearDown()
+
def test_simple_file_put(self):
self.call_main_on_test_file()