diff options
author | prathamesh | 2016-09-23 13:15:06 +0530 |
---|---|---|
committer | prathamesh | 2016-09-23 13:15:06 +0530 |
commit | d4a0ace8042f590659b8e7ec02fcdc3a24fe0592 (patch) | |
tree | fe804651f57ba0e364a11d1719edcf3d260f5ebe /yaksh/file_utils.py | |
parent | 03e54d7f6a42c0d9207db554abba9da854d494e4 (diff) | |
parent | 8e4ead8ab4caa9366e5357840e1912cbfb8cdb85 (diff) | |
download | online_test-d4a0ace8042f590659b8e7ec02fcdc3a24fe0592.tar.gz online_test-d4a0ace8042f590659b8e7ec02fcdc3a24fe0592.tar.bz2 online_test-d4a0ace8042f590659b8e7ec02fcdc3a24fe0592.zip |
Merge branch 'master' of https://github.com/FOSSEE/online_test into regrade_papers
Resolved
Conflicts:
yaksh/models.py
yaksh/test_models.py
yaksh/urls.py
yaksh/views.py
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 + |