def get_file(self,
                 path,
                 dest='',
                 makedirs=False,
                 saltenv='base',
                 gzip=None,
                 cachedir=None):
        '''
        Get a single file from the salt-master
        path must be a salt server location, aka, salt://path/to/file, if
        dest is omitted, then the downloaded file will be placed in the minion
        cache
        '''
        path, senv = salt.utils.url.split_env(path)
        if senv:
            saltenv = senv

        # Check if file exists on server, before creating files and
        # directories
        hash_server = self.hash_file(path, saltenv)
        if hash_server == '':
            log.debug(
                'Could not find file from saltenv \'{0}\', \'{1}\''.format(
                    saltenv, path
                )
            )
            return False

        # Hash compare local copy with master and skip download
        # if no difference found.
        dest2check = dest
        if not dest2check:
            rel_path = self._check_proto(path)

            log.debug(
                'In saltenv \'{0}\', looking at rel_path \'{1}\' to resolve '
                '\'{2}\''.format(saltenv, rel_path, path)
            )
            with self._cache_loc(
                    rel_path, saltenv, cachedir=cachedir) as cache_dest:
                dest2check = cache_dest

        log.debug(
            'In saltenv \'{0}\', ** considering ** path \'{1}\' to resolve '
            '\'{2}\''.format(saltenv, dest2check, path)
        )

        if dest2check and os.path.isfile(dest2check):
            hash_local = self.hash_file(dest2check, saltenv)
            if hash_local == hash_server:
                log.info(
                    'Fetching file from saltenv \'{0}\', ** skipped ** '
                    'latest already in cache \'{1}\''.format(
                        saltenv, path
                    )
                )
                return dest2check

        log.debug(
            'Fetching file from saltenv \'{0}\', ** attempting ** '
            '\'{1}\''.format(saltenv, path)
        )
        d_tries = 0
        transport_tries = 0
        path = self._check_proto(path)
        load = {'path': path,
                'saltenv': saltenv,
                'cmd': '_serve_file'}
        if gzip:
            gzip = int(gzip)
            load['gzip'] = gzip

        fn_ = None
        if dest:
            destdir = os.path.dirname(dest)
            if not os.path.isdir(destdir):
                if makedirs:
                    os.makedirs(destdir)
                else:
                    return False
            fn_ = salt.utils.fopen(dest, 'wb+')
        else:
            log.debug('No dest file found {0}'.format(dest))

        while True:
            if not fn_:
                load['loc'] = 0
            else:
                load['loc'] = fn_.tell()
            data = self.channel.send(load)
            try:
                if not data['data']:
                    if not fn_ and data['dest']:
                        # This is a 0 byte file on the master
                        with self._cache_loc(
                                data['dest'],
                                saltenv,
                                cachedir=cachedir) as cache_dest:
                            dest = cache_dest
                            with salt.utils.fopen(cache_dest, 'wb+') as ofile:
                                ofile.write(data['data'])
                    if 'hsum' in data and d_tries < 3:
                        # Master has prompted a file verification, if the
                        # verification fails, re-download the file. Try 3 times
                        d_tries += 1
                        hsum = salt.utils.get_hash(dest, data.get('hash_type', 'md5'))
                        if hsum != data['hsum']:
                            log.warning('Bad download of file {0}, attempt {1} '
                                     'of 3'.format(path, d_tries))
                            continue
                    break
                if not fn_:
                    with self._cache_loc(
                            data['dest'],
                            saltenv,
                            cachedir=cachedir) as cache_dest:
                        dest = cache_dest
                        # If a directory was formerly cached at this path, then
                        # remove it to avoid a traceback trying to write the file
                        if os.path.isdir(dest):
                            salt.utils.rm_rf(dest)
                        fn_ = salt.utils.fopen(dest, 'wb+')
                if data.get('gzip', None):
                    data = salt.utils.gzip_util.uncompress(data['data'])
                else:
                    data = data['data']
                fn_.write(data)
            except (TypeError, KeyError) as e:
                transport_tries += 1
                log.warning('Data transport is broken, got: {0}, type: {1}, '
                            'exception: {2}, attempt {3} of 3'.format(
                                data, type(data), e, transport_tries)
                            )
                self._refresh_channel()
                if transport_tries > 3:
                    log.error('Data transport is broken, got: {0}, type: {1}, '
                              'exception: {2}, '
                              'Retry attempts exhausted'.format(
                                data, type(data), e)
                            )
                    break

        if fn_:
            fn_.close()
            log.info(
                'Fetching file from saltenv \'{0}\', ** done ** '
                '\'{1}\''.format(saltenv, path)
            )
        else:
            log.debug(
                'In saltenv \'{0}\', we are ** missing ** the file '
                '\'{1}\''.format(saltenv, path)
            )

        return dest
dataset/ETHPy150Open saltstack/salt/salt/fileclient.py/RemoteClient.get_file/original