def project_config_directory(self): """Property holding the project's config directory path in the home directory """ if not self._project_config_directory_: self._project_config_directory_ = find.home_directory( project_name=self.name) return self._project_config_directory_
def _mkdir(self, project_name): """Creates the project config directory in the home directory. Also creates a empty file which is used to identify this as a test directory. """ path = find.home_directory(project_name=project_name) os.mkdir(path) filename = os.path.join(path, '___dodai_test___') f = open(filename, 'w') f.close()
def _build_project_name(self): """Builds the name of the project. This also checks to insure that no directory exists for this project already exists. If the directory already exists, a new name will be generated """ project_name = self._build_random_text() dir = find.home_directory(project_name=project_name) if os.path.exists(dir): return self._build_project_name() else: self._mkdir(project_name) return project_name
def clean_up(self): """This recursively removes any dodai test config directories """ path = find.home_directory() dirs = [] for name in os.listdir(path): if name.startswith("."): filepath = os.path.join(path, name) filename = os.path.join(filepath, '___dodai_test___') if os.path.exists(filename): dirs.append(filepath) for dir in dirs: for root, dirs, files in os.walk(dir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(dir)
def test_find_home_directory_with_project(self): directory = find.home_directory(self.project) self.assertTrue(directory.endswith(self.project))
def test_find_home_directory(self): directory = find.home_directory() self.assertTrue(os.path.exists(directory))
def load(cls): directory = find.home_directory(cls.PROJECT) obj = cls(directory) obj.build() return obj