mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
oracle: use 'Bytes' instead of custom calculation
This commit is contained in:
parent
5f9152bec3
commit
9e6028799a
1 changed files with 6 additions and 7 deletions
|
@ -2,11 +2,10 @@ import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
from bootstrapvz.common.bytes import Bytes
|
||||||
|
|
||||||
|
|
||||||
class OracleStorageAPIClient:
|
class OracleStorageAPIClient:
|
||||||
MEGABYTE = 1024**2
|
|
||||||
|
|
||||||
def __init__(self, username, password, identity_domain, container):
|
def __init__(self, username, password, identity_domain, container):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
@ -41,10 +40,10 @@ class OracleStorageAPIClient:
|
||||||
@property
|
@property
|
||||||
def chunk_size(self):
|
def chunk_size(self):
|
||||||
file_size = os.path.getsize(self.file_path)
|
file_size = os.path.getsize(self.file_path)
|
||||||
if file_size > (300 * self.MEGABYTE):
|
if file_size > int(Bytes('300MiB')):
|
||||||
chunk_size = 100 * self.MEGABYTE
|
chunk_size = int(Bytes('100MiB'))
|
||||||
else:
|
else:
|
||||||
chunk_size = 50 * self.MEGABYTE
|
chunk_size = int(Bytes('50MiB'))
|
||||||
return chunk_size
|
return chunk_size
|
||||||
|
|
||||||
def compare_files(self):
|
def compare_files(self):
|
||||||
|
@ -55,7 +54,7 @@ class OracleStorageAPIClient:
|
||||||
for f, h in zip(files, hashes):
|
for f, h in zip(files, hashes):
|
||||||
with open(f, 'rb') as current_file:
|
with open(f, 'rb') as current_file:
|
||||||
while True:
|
while True:
|
||||||
data = current_file.read(self.MEGABYTE)
|
data = current_file.read(int(Bytes('8MiB')))
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
h.update(data)
|
h.update(data)
|
||||||
|
@ -88,7 +87,7 @@ class OracleStorageAPIClient:
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
self._fail(response.text)
|
self._fail(response.text)
|
||||||
with open(self.target_file_path, 'wb') as f:
|
with open(self.target_file_path, 'wb') as f:
|
||||||
for chunk in response.iter_content(chunk_size=self.MEGABYTE):
|
for chunk in response.iter_content(chunk_size=int(Bytes('8MiB'))):
|
||||||
if chunk:
|
if chunk:
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue