From dc61b1bf951ae4408ec1cfdb11d2ba4d4221b7cf Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 30 Jul 2017 21:44:53 -0700 Subject: [PATCH] Clean data item code --- dvc/path/data_item.py | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/dvc/path/data_item.py b/dvc/path/data_item.py index 86876d2bf..04fb341a1 100644 --- a/dvc/path/data_item.py +++ b/dvc/path/data_item.py @@ -13,34 +13,21 @@ class DataItemError(DvcException): class NotInDataDirError(DvcException): - def __init__(self, msg): + def __init__(self, file, data_dir, pattern='the file "{}" is not in the data directory "{}"'): + msg = pattern.format(file, data_dir) super(NotInDataDirError, self).__init__(msg) - @staticmethod - def build(file, data_dir): - msg = 'the file "{}" is not in the data directory "{}"'.format(file, data_dir) - return NotInDataDirError(msg) - class DataItemInStatusDirError(NotInDataDirError): - def __init__(self, msg): - super(DataItemInStatusDirError, self).__init__(msg) - - @staticmethod - def build(file, data_dir): - msg = 'the file "{}" is in state directory, not in the data directory "{}"'.format( - file, data_dir) - return DataItemInStatusDirError(msg) + def __init__(self, file, data_dir): + pattern = 'the file "{}" is in state directory, not in the data directory "{}"' + super(DataItemInStatusDirError, self).__init__(file, data_dir, pattern) class NotInGitDirError(NotInDataDirError): - def __init__(self, msg): - super(NotInGitDirError, self).__init__(msg) - - @staticmethod - def build(file, git_dir): - msg = 'the file "{}" is not in git directory "{}"'.format(file, git_dir) - return NotInGitDirError(msg) + def __init__(self, file, git_dir): + pattern = 'the file "{}" is not in git directory "{}"' + super(NotInGitDirError, self).__init__(file, git_dir, pattern) class DataItem(object): @@ -55,16 +42,14 @@ class DataItem(object): self._data = Path(data_file, git) if not self._data.abs.startswith(self._git.git_dir_abs): - raise NotInGitDirError.build(data_file, self._git.git_dir_abs) + raise NotInGitDirError(data_file, self._git.git_dir_abs) if self._data.abs.startswith(self.state_dir_abs): - raise DataItemInStatusDirError.build(data_file, self._config.data_dir) + raise DataItemInStatusDirError(data_file, self._config.data_dir) - if not self._data.abs.startswith(self.data_dir_abs): - raise NotInDataDirError.build(data_file, self._config.data_dir) - - if not self._data.dvc.startswith(self._config.data_dir): - raise NotInDataDirError.build(data_file, self._config.data_dir) + if not self._data.abs.startswith(self.data_dir_abs) or \ + not self._data.dvc.startswith(self._config.data_dir): + raise NotInDataDirError(data_file, self._config.data_dir) pass def copy(self, cache_file=None):