From: tierno Date: Tue, 4 Dec 2018 15:37:23 +0000 (+0000) Subject: bug 605. New method at fslocal for rename folders X-Git-Tag: v5.0.3~3 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F7035%2F3;p=osm%2Fcommon.git bug 605. New method at fslocal for rename folders Change-Id: Ic0acd82873a3790f228641ba676d2da9235059f1 Signed-off-by: tierno --- diff --git a/osm_common/__init__.py b/osm_common/__init__.py index ecd9261..73fd77e 100644 --- a/osm_common/__init__.py +++ b/osm_common/__init__.py @@ -15,6 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -version = '0.1.14' +version = '0.1.15' # TODO add package version filling commit id with 0's; e.g.: '5.0.0.post11+00000000.dirty-1' -date_version = '2018-11-27' +date_version = '2018-12-05' diff --git a/osm_common/fsbase.py b/osm_common/fsbase.py index b941c21..87d974d 100644 --- a/osm_common/fsbase.py +++ b/osm_common/fsbase.py @@ -62,6 +62,9 @@ class FsBase(object): def mkdir(self, folder): raise FsException("Method 'mkdir' not implemented") + def dir_rename(self, src, dst): + raise FsException("Method 'dir_rename' not implemented") + def file_exists(self, storage): raise FsException("Method 'file_exists' not implemented") diff --git a/osm_common/fslocal.py b/osm_common/fslocal.py index 61600ec..bd243f0 100644 --- a/osm_common/fslocal.py +++ b/osm_common/fslocal.py @@ -63,6 +63,22 @@ class FsLocal(FsBase): except Exception as e: raise FsException(str(e), http_code=HTTPStatus.INTERNAL_SERVER_ERROR) + def dir_rename(self, src, dst): + """ + Rename one directory name. If dst exist, it replaces (deletes) existing directory + :param src: source directory + :param dst: destination directory + :return: None or raises and exception + """ + try: + if os.path.exists(self.path + dst): + rmtree(self.path + dst) + + os.rename(self.path + src, self.path + dst) + + except Exception as e: + raise FsException(str(e), http_code=HTTPStatus.INTERNAL_SERVER_ERROR) + def file_exists(self, storage, mode=None): """ Indicates if "storage" file exist @@ -143,7 +159,7 @@ class FsLocal(FsBase): def file_delete(self, storage, ignore_non_exist=False): """ - Delete storage content recursivelly + Delete storage content recursively :param storage: can be a str or list of str :param ignore_non_exist: not raise exception if storage does not exist :return: None