diff options
author | adityacp | 2016-08-30 22:39:45 +0530 |
---|---|---|
committer | adityacp | 2016-08-30 22:39:45 +0530 |
commit | 3b8a17eb28ff5360449c4a1b6098860069fc0dc3 (patch) | |
tree | 4d36aff10190e6ee97731b13e987df217124551d /yaksh/file_utils.py | |
parent | e8769f5d8c43ee7c2655133b676ae53d2987c79c (diff) | |
parent | aefc8eed3b0c18520059b4005978f1db9cf5591b (diff) | |
download | online_test-3b8a17eb28ff5360449c4a1b6098860069fc0dc3.tar.gz online_test-3b8a17eb28ff5360449c4a1b6098860069fc0dc3.tar.bz2 online_test-3b8a17eb28ff5360449c4a1b6098860069fc0dc3.zip |
removed extract_files and read_json files from views
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index 8f6f6e5..afcf9e8 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -13,12 +13,10 @@ def copy_files(file_paths): file_name = os.path.basename(file_path) files.append(file_name) shutil.copy(file_path, os.getcwd()) - if extract and zipfile.is_zipfile(file_name): - unzip = zipfile.ZipFile(file_name) - for zip_files in unzip.namelist(): - files.append(zip_files) - unzip.extractall() - unzip.close() + if extract: + z_files = extract_files(file_name) + for file in z_files: + files.append(file) return files @@ -31,3 +29,15 @@ def delete_files(files): os.remove(file) else: shutil.rmtree(file) + + +def extract_files(zip_file): + zfiles = [] + if zipfile.is_zipfile(zip_file): + zip_file = zipfile.ZipFile(zip_file, 'r') + for z_file in zip_file.namelist(): + zfiles.append(z_file) + zip_file.extractall() + zip_file.close() + return zfiles + |