diff options
author | Prabhu Ramachandran | 2016-09-21 17:48:06 +0530 |
---|---|---|
committer | GitHub | 2016-09-21 17:48:06 +0530 |
commit | 4f384f81cbde58f5eaa616dce85f1e4d60ea2c66 (patch) | |
tree | 42f7c05744a87ad615d801324113472aaeb72492 /yaksh/file_utils.py | |
parent | f78647307f2e5f858d1c1f74507a8626ec117223 (diff) | |
parent | e1811e3560742a4070f3e92e059a7cd1c50f1f36 (diff) | |
download | online_test-4f384f81cbde58f5eaa616dce85f1e4d60ea2c66.tar.gz online_test-4f384f81cbde58f5eaa616dce85f1e4d60ea2c66.tar.bz2 online_test-4f384f81cbde58f5eaa616dce85f1e4d60ea2c66.zip |
Merge pull request #127 from adityacp/create_course_fixtures
Create course fixtures
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 + |