diff options
author | prathamesh | 2016-11-01 09:30:53 +0530 |
---|---|---|
committer | prathamesh | 2016-11-01 09:30:53 +0530 |
commit | 6f9d5d2779e64212988c0d164fa05ce2d05e696a (patch) | |
tree | e7a1c316b97df44ec701384feea421ca66e3aa9c /yaksh/file_utils.py | |
parent | 3b66e5fb8af12ce756f34966bb684373062551dd (diff) | |
parent | f563640af941a50642dc5eb6e63b1d63a1685046 (diff) | |
download | online_test-6f9d5d2779e64212988c0d164fa05ce2d05e696a.tar.gz online_test-6f9d5d2779e64212988c0d164fa05ce2d05e696a.tar.bz2 online_test-6f9d5d2779e64212988c0d164fa05ce2d05e696a.zip |
Merge branch 'master' of https://github.com/FOSSEE/online_test into UI-modifications
Resolved
Conflicts:
yaksh/templates/manage.html
yaksh/templates/yaksh/design_questionpaper.html
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index afcf9e8..f41c531 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -1,6 +1,7 @@ import shutil import os import zipfile +import tempfile def copy_files(file_paths): @@ -14,16 +15,19 @@ def copy_files(file_paths): files.append(file_name) shutil.copy(file_path, os.getcwd()) if extract: - z_files = extract_files(file_name) + z_files, path = extract_files(file_name, os.getcwd()) for file in z_files: files.append(file) return files -def delete_files(files): - """ Delete Files from current directory """ - - for file in files: +def delete_files(files, file_path=None): + """ Delete Files from directory """ + for file_name in files: + if file_path: + file = os.path.join(file_path, file_name) + else: + file = file_name if os.path.exists(file): if os.path.isfile(file): os.remove(file) @@ -31,13 +35,18 @@ def delete_files(files): shutil.rmtree(file) -def extract_files(zip_file): +def extract_files(zip_file, path=None): + """ extract files from zip """ 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() + if path: + extract_path = path + else: + extract_path = tempfile.gettempdir() + zip_file.extractall(extract_path) zip_file.close() - return zfiles + return zfiles, extract_path |