Commit f16b9ead authored by Rafael Monnerat's avatar Rafael Monnerat

product/SlapOS: Remove duplicates script

  This script is a copy the one on product/ERP5/bin/bigfile_client_example.py
parent 799c9a4b
Pipeline #10763 failed with stage
in 0 seconds
input_file = open('big_file.log', 'r')
import httplib
connection = httplib.HTTPConnection('192.168.242.68:12001')
import base64
base64string = base64.encodestring('zope:insecure')[:-1]
n = 1 << 20
######################################
# Create new document
######################################
headers = {
'Authorization': 'Basic %s' % base64string,
}
connection.request('POST', "/erp5/portal_contributions/newContent?" \
"portal_type=Big%20File&filename=big_file.log&container_path=big_file_module&data=", "", headers)
result = connection.getresponse()
path = result.getheader("X-Document-Location")
result.close()
path = '/%s' % '/'.join(path.split('/')[3:])
print path
######################################
# Upload chunks
######################################
input_file.seek(0, 2)
end = input_file.tell()
input_file.seek(0)
pos = input_file.tell()
first = True
while pos < end:
next_pos = pos + n
if next_pos > end:
next_pos = end
body_content = input_file.read(next_pos-pos)
if first:
headers = {
'Authorization': 'Basic %s' % base64string,
}
else:
headers = {
'Authorization': 'Basic %s' % base64string,
'Content-Range': 'bytes %i-%i/%i' % (pos, next_pos-1, next_pos),
}
connection.request('PUT', path, body_content, headers)
result = connection.getresponse()
pos = input_file.tell()
first = False
######################################
# Download chunks
######################################
output_file = open('output_big_file.log', 'wb')
output_file.seek(0)
headers = {
'Authorization': 'Basic %s' % base64string,
'Content-Range': 'bytes */*',
}
connection.request('PUT', path, '', headers)
result = connection.getresponse()
filerange = result.getheader('Range')
size = int(filerange.split('-')[1])
pos = 0
while pos < size:
next_pos = pos + n
if next_pos > size:
next_pos = size
headers = {
'Authorization': 'Basic %s' % base64string,
'Range': 'bytes=%s-%s' % (pos, next_pos),
}
connection.request('GET', path, '', headers)
result = connection.getresponse()
output_file.write(result.read())
result.close()
pos = output_file.tell()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment