Exemple #1
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)
Exemple #2
0
def do_image_download(gc, args):
    """Download a specific image."""
    image = utils.find_resource(gc.images, args.image)
    body = image.data()
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        print('No redirection or local file specified for downloaded image '
              'data. Please specify a local file with --file to save '
              'downloaded image or redirect output to another source.')
Exemple #3
0
 def test_iter_iterator_display_progress_bar(self):
     size = 100
     iterator = iter('X' * 100)
     saved_stdout = sys.stdout
     try:
         sys.stdout = output = test_utils.FakeTTYStdout()
         # Consume iterator.
         data = list(progressbar.VerboseIteratorWrapper(iterator, size))
         self.assertEqual(['X'] * 100, data)
         self.assertEqual('[%s>] 100%%\n' % ('=' * 29), output.getvalue())
     finally:
         sys.stdout = saved_stdout
Exemple #4
0
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if body is None:
        msg = ('Image %s has no data.' % args.id)
        utils.exit(msg)

    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    if not (sys.stdout.isatty() and args.file is None):
        utils.save_image(body, args.file)
    else:
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)
 def test_iter_iterator_display_progress_bar(self):
     size = 100
     # create fake response object to return request-id with iterator
     resp = requests.Response()
     resp.headers['x-openstack-request-id'] = 'req-1234'
     iterator_with_len = utils.IterableWithLength(iter('X' * 100), size)
     requestid_proxy = utils.RequestIdProxy((iterator_with_len, resp))
     saved_stdout = sys.stdout
     try:
         sys.stdout = output = test_utils.FakeTTYStdout()
         # Consume iterator.
         data = list(
             progressbar.VerboseIteratorWrapper(requestid_proxy, size))
         self.assertEqual(['X'] * 100, data)
         self.assertEqual('[%s>] 100%%\n' % ('=' * 29), output.getvalue())
     finally:
         sys.stdout = saved_stdout
def do_image_download(gc, args):
    """Download a specific image."""
    if sys.stdout.isatty() and (args.file is None):
        msg = ('No redirection or local file specified for downloaded image '
               'data. Please specify a local file with --file to save '
               'downloaded image or redirect output to another source.')
        utils.exit(msg)

    try:
        body = gc.images.data(args.id)
    except (exc.HTTPForbidden, exc.HTTPException) as e:
        msg = "Unable to download image '%s'. (%s)" % (args.id, e)
        utils.exit(msg)

    if body is None:
        msg = ('Image %s has no data.' % args.id)
        utils.exit(msg)

    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))

    utils.save_image(body, args.file)
def do_image_download(gc, args):
    """Download a specific image."""
    body = gc.images.data(args.id)
    if args.progress:
        body = progressbar.VerboseIteratorWrapper(body, len(body))
    utils.save_image(body, args.file)