def get_by_format(self, save_as, url):
        fd = io.FileIO(save_as, mode='wb')
        creds = self.credentials

        # move to auth.py?
        token = {"access_token": creds.access_token, "token_type": "Bearer"}
        session = OAuth2Session(creds.client_id, scope=SCOPE, token=token)

        with open(save_as, 'wb') as f:
            response = session.get(url, stream=True)
            return_content = response.content
            if self.file_size:
                total_length = int(self.file_size)
                print "total size = %d Bytes" % total_length

                mega = 1048576  # 1024*1024
                downloaded = 0
                total_in_mega = int(total_length / mega)

                for data in response.iter_content(chunk_size=mega):
                    f.write(data)
                    downloaded += len(data)
                    done = int(50 * downloaded / total_length)
                    done_percent = int(downloaded / total_length * 100)
                    done_in_mega = int(downloaded / mega)
                    sys.stdout.write("\r[%s%s] %3d%%, %d of %d MB" % (
                        '=' * done, ' ' * (50 - done), done_percent, done_in_mega, total_in_mega))
                    sys.stdout.flush()
            else:
                f.write(return_content)

        # for sys.stdout.flush()
        print ""

        # local size check
        local_size = int(os.path.getsize(save_as))
        print "File location: %s" % save_as

        if self.file_size:
            if(int(self.file_size) == local_size):
                return True, return_content, local_size
            else:
                return False, return_content, local_size
        else:
            print "File size in bytes: %d" % local_size
            return True, return_content, local_size
Show detail for a specified RAID device
dataset/ETHPy150Open tienfuc/gdcmdtools/gdcmdtools/get.py/GDGet.get_by_format--crossover with--dataset/ETHPy150Open saltstack/salt/salt/modules/mdadm.py/detail