summaryrefslogtreecommitdiff
path: root/yaksh/file_utils.py
diff options
context:
space:
mode:
authormaheshgudi2016-08-03 15:16:08 +0530
committermaheshgudi2016-08-03 15:16:08 +0530
commit40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb (patch)
tree7885b674d2deb064137f1f501ed1707bfd54daf8 /yaksh/file_utils.py
parent1b71abc9437d721a41f017db406f312755f5a4c4 (diff)
parent2b03aeb36fa333ea1644a248c742cf0c1df12a5f (diff)
downloadonline_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.gz
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.bz2
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.zip
rebase changes with stdio evaluator
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r--yaksh/file_utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py
new file mode 100644
index 0000000..8f6f6e5
--- /dev/null
+++ b/yaksh/file_utils.py
@@ -0,0 +1,33 @@
+import shutil
+import os
+import zipfile
+
+
+def copy_files(file_paths):
+ """ Copy Files to current directory, takes
+ tuple with file paths and extract status"""
+
+ files = []
+ for src in file_paths:
+ file_path, extract = src
+ 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()
+ return files
+
+
+def delete_files(files):
+ """ Delete Files from current directory """
+
+ for file in files:
+ if os.path.exists(file):
+ if os.path.isfile(file):
+ os.remove(file)
+ else:
+ shutil.rmtree(file)