From f9f0173e8e8c0bcae7a3da701592a5cdf3317df7 Mon Sep 17 00:00:00 2001 From: Scott Black Date: Wed, 18 Jul 2018 12:47:03 -0600 Subject: [PATCH 1/3] [#2833] add unzip to IrodsStorage --- storage.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/storage.py b/storage.py index 79f3639..0648e0e 100644 --- a/storage.py +++ b/storage.py @@ -98,6 +98,31 @@ def zipup(self, in_name, out_name): # SessionException will be raised from run() in icommands.py self.session.run("ibun", None, '-cDzip', '-f', out_name, in_name) + def unzip(self, zip_file_path): + """ + run iRODS ibun command to unzip files + :param zip_file_path: path of the zipped file to be unzipped + :return: the folder files were unzipped to + """ + + abs_path = os.path.dirname(zip_file_path) + unzipped_folder = os.path.splitext(os.path.basename(zip_file_path))[0] + unzipped_folder = self.__get_nonexistant_path(os.path.join(abs_path, unzipped_folder)) + + # SessionException will be raised from run() in icommands.py + self.session.run("ibun", None, '-xDzip', zip_file_path, unzipped_folder) + return unzipped_folder + + def __get_nonexistant_path(self, path): + if not self.exists(path): + return path + i = 1 + new_path = "{}-{}".format(path, i) + while self.exists(new_path): + i += 1 + new_path = "{}-{}".format(path, i) + return new_path + def setAVU(self, name, attName, attVal, attUnit=None): """ set AVU on resource collection - this is used for on-demand bagging by indicating From dbbabe13c245c1b60c5a5a706c2572cdf83c0e67 Mon Sep 17 00:00:00 2001 From: Scott Black Date: Wed, 18 Jul 2018 15:32:43 -0600 Subject: [PATCH 2/3] [#2833] underscore typo and update docstring --- storage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/storage.py b/storage.py index 0648e0e..511c699 100644 --- a/storage.py +++ b/storage.py @@ -100,20 +100,20 @@ def zipup(self, in_name, out_name): def unzip(self, zip_file_path): """ - run iRODS ibun command to unzip files + run iRODS ibun command to unzip files into a new folder :param zip_file_path: path of the zipped file to be unzipped :return: the folder files were unzipped to """ abs_path = os.path.dirname(zip_file_path) unzipped_folder = os.path.splitext(os.path.basename(zip_file_path))[0] - unzipped_folder = self.__get_nonexistant_path(os.path.join(abs_path, unzipped_folder)) + unzipped_folder = self._get_nonexistant_path(os.path.join(abs_path, unzipped_folder)) # SessionException will be raised from run() in icommands.py self.session.run("ibun", None, '-xDzip', zip_file_path, unzipped_folder) return unzipped_folder - def __get_nonexistant_path(self, path): + def _get_nonexistant_path(self, path): if not self.exists(path): return path i = 1 From ded1df01f105b0bca3240f2e1dd1f46ebacc9226 Mon Sep 17 00:00:00 2001 From: Scott Black Date: Wed, 25 Jul 2018 13:01:53 -0600 Subject: [PATCH 3/3] [#2833] - strip foldernames to prevent whitespace in name --- storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage.py b/storage.py index 511c699..d3b604d 100644 --- a/storage.py +++ b/storage.py @@ -106,7 +106,7 @@ def unzip(self, zip_file_path): """ abs_path = os.path.dirname(zip_file_path) - unzipped_folder = os.path.splitext(os.path.basename(zip_file_path))[0] + unzipped_folder = os.path.splitext(os.path.basename(zip_file_path))[0].strip() unzipped_folder = self._get_nonexistant_path(os.path.join(abs_path, unzipped_folder)) # SessionException will be raised from run() in icommands.py