Export the specific image to remote host or local file system
504523
def image_export(cls, source_path, dest_url, **kwargs):
        
        dest_path = urlparse.urlparse(dest_url).path
        if kwargs['remote_host']:
            target_path = ':'.join([kwargs['remote_host'], dest_path])
            command = ' '.join(['/usr/bin/scp',
                                "-P", CONF.zvm.remotehost_sshd_port,
                                "-o StrictHostKeyChecking=no",
                                '-r ', source_path, target_path])
            (rc, output) = zvmutils.execute(command)
            if rc:
                msg = ("Error happened when copying image file to remote "
                       "host with reason: %s" % output)
                LOG.error(msg)
                raise exception.SDKImageOperationError(rs=21, msg=output)
        else:
            # Copy to local file system
            LOG.debug("Remote_host not specified, will copy to local server")
            try:
                shutil.copyfile(source_path, dest_path)
            except Exception as err:
                msg = ("Export image from %(src)s to local file system"
                       " %(dest)s failed: %(err)s" %
                       {'src': source_path,
                        'dest': dest_path,
                        'err': six.text_type(err)})
                LOG.error(msg)
                raise exception.SDKImageOperationError(rs=22,
                                                       err=six.text_type(err))
1129461
def store_image(self, http_client, link_hash, src, config):
        
        # check for a cache hit already on disk
        image = self.read_localfile(link_hash, src, config)
        if image:
            return image

        # no cache found download the image
        data = self.fetch(http_client, src)
        if data:
            image = self.write_localfile(data, link_hash, src, config)
            if image:
                return image

        return None
320770
def send(self, local, remote, makedirs=False):
        '''
        
        '''
        if makedirs:
            self.exec_cmd('mkdir -p {0}'.format(os.path.dirname(remote)))

        # scp needs [<ipv6}
        host = self.host
        if ':' in host:
            host = '[{0}]'.format(host)

        cmd = '{0} {1}:{2}'.format(local, host, remote)
        cmd = self._cmd_str(cmd, ssh='scp')

        logmsg = 'Executing command: {0}'.format(cmd)
        if self.passwd:
            logmsg = logmsg.replace(self.passwd, ('*' * 6))
        log.debug(logmsg)

        return self._run_cmd(cmd)
617341
def image_to_file(self, path, get_image=True):
        """"""
        if not self.image_url or get_image:
            if not self.refresh_image():
                return False

        response = requests.get(self.image_url, stream=True)

        if response.status_code != 200:
            _LOGGER.warning(
                "Unexpected response code %s when requesting image: %s",
                str(response.status_code), response.text)
            raise AbodeException((ERROR.CAM_IMAGE_REQUEST_INVALID))

        with open(path, 'wb') as imgfile:
            copyfileobj(response.raw, imgfile)

        return True
632367
def _export_local_images(project, image, z):
    
    from ..compute import MODULES

    for module in MODULES:
        try:
            img_directory = module.instance().get_images_directory()
        except NotImplementedError:
            # Some modules don't have images
            continue

        directory = os.path.split(img_directory)[-1:][0]
        if os.path.exists(image):
            path = image
        else:
            path = os.path.join(img_directory, image)

        if os.path.exists(path):
            arcname = os.path.join("images", directory, os.path.basename(image))
            z.write(path, arcname)
            return
1345148
def download_file(client, bucket, remote_path, local_path, overwrite=False):
    """"""
    bucket = client.get_bucket(bucket)
    if (not overwrite) and os.path.isfile(local_path):
        raise OSError('File already exists!')
    with open(local_path, 'wb') as ofh:
        bucket.get_blob(remote_path).download_to_file(ofh)
126585
def main(input_file, output, format):
    """"""

    try:
        process_image(input_file, subfolder=output, ext=format)
    except Exception as e:
        sys.exit(e)
472861
def send_file_to_remote(dev, src_file, dst_filename, filesize, dst_mode='wb'):
    
    bytes_remaining = filesize
    save_timeout = dev.timeout
    dev.timeout = 1
    while bytes_remaining > 0:
        # Wait for ack so we don't get too far ahead of the remote
        ack = dev.read(1)
        if ack is None or ack != b'\x06':
            sys.stderr.write("timed out or error in transfer to remote\n")
            sys.exit(2)

        if HAS_BUFFER:
            buf_size = BUFFER_SIZE
        else:
            buf_size = BUFFER_SIZE // 2
        read_size = min(bytes_remaining, buf_size)
        buf = src_file.read(read_size)
        #sys.stdout.write('\r%d/%d' % (filesize - bytes_remaining, filesize))
        #sys.stdout.flush()
        if HAS_BUFFER:
            dev.write(buf)
        else:
            dev.write(binascii.hexlify(buf))
        bytes_remaining -= read_size
    #sys.stdout.write('\r')
    dev.timeout = save_timeout
524770
public void export() throws IOException {
		final byte[] imageData = getImageData();
		if (imageData != null) {
			final File file = ImageFileChooser.chooseImage(this, false, getFileName());
			if (file != null) {
				try (OutputStream fileOutputStream = new BufferedOutputStream(
						new FileOutputStream(file))) {
					fileOutputStream.write(imageData);
				}
			}
		}
	}
556273
def scp(self, local_file, remote_path=''):
        """"""
        if self.args.user:
            upload_spec = '{0}@{1}:{2}'.format(self.args.user,
                                               self.args.server,
                                               remote_path)
        else:
            upload_spec = '{0}:{1}'.format(self.args.server, remote_path)

        return self.sh('scp', local_file, upload_spec)
507415
def parse_remote(cls, filename):
        """"""
        blob_file = cls._URL_FORMAT.search(filename)
        return cls._REMOTE_FILE("blob",
                                storage=blob_file.group("storage"),
                                container=blob_file.group("container"),
                                blob=blob_file.group("blob"))
726216
def copy_remote_directory_to_local(sftp, remote_path, local_path):
    ''''''
    try:
        os.makedirs(local_path, exist_ok=True)
        files = sftp.listdir(remote_path)
        for file in files:
            remote_full_path = os.path.join(remote_path, file)
            local_full_path = os.path.join(local_path, file)
            try:
                if sftp.listdir(remote_full_path):
                    copy_remote_directory_to_local(sftp, remote_full_path, local_full_path)
            except:
                sftp.get(remote_full_path, local_full_path)
    except Exception:
        pass
890990
def to_file(self, filename):
        

        img = self.to_image()
        img.save(filename, optimize=True)
        return self
193173
def export(self, filename, fmt="DER"):
        
        f = open(filename, "wb")
        if fmt == "DER":
            f.write(self.der)
        elif fmt == "PEM":
            f.write(self.pem)
        f.close()
709965
def _file_local_or_remote(f, get_retriever):
    
    if os.path.exists(f):
        return f
    integration, config = get_retriever.integration_and_config(f)
    if integration:
        return integration.file_exists(f, config)
408071
def export(path=None, user_content=False, context=None,
           username=None, password=None, render_offline=False,
           render_wide=False, render_inline=True, out_filename=None,
           api_url=None, title=None, quiet=False, grip_class=None):
    
    export_to_stdout = out_filename == '-'
    if out_filename is None:
        if path == '-':
            export_to_stdout = True
        else:
            filetitle, _ = os.path.splitext(
                os.path.relpath(DirectoryReader(path).root_filename))
            out_filename = '{0}.html'.format(filetitle)

    if not export_to_stdout and not quiet:
        print('Exporting to', out_filename, file=sys.stderr)

    page = render_page(path, user_content, context, username, password,
                       render_offline, render_wide, render_inline, api_url,
                       title, None, quiet, grip_class)

    if export_to_stdout:
        try:
            print(page)
        except IOError as ex:
            if ex.errno != 0 and ex.errno != errno.EPIPE:
                raise
    else:
        with io.open(out_filename, 'w', encoding='utf-8') as f:
            f.write(page)
1256434
def jpegrescan(ext_args):
    """"""
    args = copy.copy(_JPEGRESCAN_ARGS)
    if Settings.jpegrescan_multithread:
        args += ['-t']
    if Settings.destroy_metadata:
        args += ['-s']
    args += [ext_args.old_filename, ext_args.new_filename]
    extern.run_ext(args)
    return _JPEG_FORMAT