extract zipfile on checkout

This commit is contained in:
2014-11-05 11:24:57 +01:00
parent 41992ee72f
commit 9157ed1dc0
2 changed files with 24 additions and 7 deletions

View File

@@ -117,12 +117,17 @@ class bam_utils:
@staticmethod
def checkout(paths):
import sys
import os
import requests
# TODO(cam) multiple paths
path = paths[0]
del paths
# TODO(cam) we may want to checkout a single file? how to handle this?
# we may want to checkout a dir too
dst_dir = os.path.basename(path)
payload = {
"filepath": path,
"command": "checkout",
@@ -140,12 +145,12 @@ class bam_utils:
return
# TODO(cam) how to tell if we get back a message payload? or real data???
local_filename = payload['filepath'].split('/')[-1]
dst_dir_data = payload['filepath'].split('/')[-1]
if 1:
local_filename += ".zip"
dst_dir_data += ".zip"
with open(local_filename, 'wb') as f:
with open(dst_dir_data, 'wb') as f:
import struct
ID_MESSAGE = 1
ID_PAYLOAD = 2
@@ -172,7 +177,18 @@ class bam_utils:
sys.stdout.write("\rdownload: [%03d%%]" % ((100 * tot_size) // msg_size))
sys.stdout.flush()
sys.stdout.write("\nwritten: %r\n" % local_filename)
# ---------------
# extract the zip
import zipfile
with open(dst_dir_data, 'rb') as zip_file:
zip_handle = zipfile.ZipFile(zip_file)
zip_handle.extractall(dst_dir)
del zipfile, zip_file
os.remove(dst_dir_data)
sys.stdout.write("\nwritten: %r\n" % dst_dir)
@staticmethod
def commit(paths, message):

View File

@@ -220,9 +220,10 @@ class FileAPI(Resource):
import zipfile
tmp_extracted_folder = os.path.splitext(tmp_filepath)[0]
with open(tmp_filepath, 'rb') as zipped_file:
z = zipfile.ZipFile(zipped_file)
z.extractall(tmp_extracted_folder)
with open(tmp_filepath, 'rb') as zip_file:
zip_handle = zipfile.ZipFile(zip_file)
zip_handle.extractall(tmp_extracted_folder)
del zip_file, zip_handle
with open(os.path.join(tmp_extracted_folder, '.bam_paths_remap.json'), 'r') as path_remap:
path_remap = json.load(path_remap)