示例#1
0
    def match(self, path):
        """Checks if path is a wc path.

        If path is a wc path a WCPath object is returned
        otherwise None.

        """
        project_path = package_path = filename_path = None
        if not path:
            path = os.getcwd()
        path = os.path.normpath(path)
        par_dir = wc_parent(path)
        if wc_is_package(path):
            package_path = path
            project_path = par_dir
        elif wc_is_project(path):
            project_path = path
        elif par_dir is not None:
            if wc_is_package(par_dir):
                filename_path = path
                package_path = par_dir
                # check if package has a parent
                par_dir = wc_parent(package_path)
                if par_dir is not None and wc_is_project(par_dir):
                    project_path = par_dir
            elif wc_is_project(par_dir):
                project_path = par_dir
                package_path = path
            else:
                return None
        else:
            return None
        return {self._name: WCPath(project_path, package_path, filename_path)}
示例#2
0
 def test27(self):
     """test wc_parent (package/non_existent - no parent)"""
     path = self.fixture_file('package', 'non_existent')
     self.assertFalse(os.path.exists(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_package(par_dir))
     self.assertEqual(wc_read_package(par_dir), 'package')
示例#3
0
 def test24(self):
     """test wc_parent (package/file)"""
     path = self.fixture_file('prj1', 'added', 'foo')
     self.assertTrue(os.path.isfile(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_package(par_dir))
     self.assertEqual(wc_read_package(par_dir), 'added')
示例#4
0
 def test27(self):
     """test wc_parent (package/non_existent - no parent)"""
     path = self.fixture_file('package', 'non_existent')
     self.assertFalse(os.path.exists(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_package(par_dir))
     self.assertEqual(wc_read_package(par_dir), 'package')
示例#5
0
 def test24(self):
     """test wc_parent (package/file)"""
     path = self.fixture_file('prj1', 'added', 'foo')
     self.assertTrue(os.path.isfile(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_package(par_dir))
     self.assertEqual(wc_read_package(par_dir), 'added')
示例#6
0
 def test30(self):
     """test wc_parent in non-standard hierarchy"""
     # currently, such a hierarchy is not created by osc2
     # but we should resolve the parent with the help of
     # the storedir link
     path = self.fixture_file('prj1', 'hierarchy', 'non-standard')
     self.assertTrue(wc_is_package(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_project(par_dir))
     self.assertEqual(wc_read_project(par_dir), 'prj1')
示例#7
0
 def test30(self):
     """test wc_parent in non-standard hierarchy"""
     # currently, such a hierarchy is not created by osc2
     # but we should resolve the parent with the help of
     # the storedir link
     path = self.fixture_file('prj1', 'hierarchy', 'non-standard')
     self.assertTrue(wc_is_package(path))
     par_dir = wc_parent(path)
     self.assertIsNotNone(par_dir)
     self.assertTrue(wc_is_project(par_dir))
     self.assertEqual(wc_read_project(par_dir), 'prj1')
示例#8
0
 def test28(self):
     """test wc_parent cwd (package/non_existent - no parent)"""
     pkg_path = self.fixture_file('package')
     path = 'non_existent'
     cwd = os.getcwd()
     try:
         os.chdir(pkg_path)
         self.assertFalse(os.path.exists(path))
         par_dir = wc_parent(path)
         self.assertIsNotNone(par_dir)
         self.assertTrue(wc_is_package(par_dir))
         self.assertEqual(wc_read_package(par_dir), 'package')
     finally:
         os.chdir(cwd)
示例#9
0
 def test23(self):
     """test wc_parent (cwd)"""
     pkg_path = self.fixture_file('prj1', 'added')
     path = os.curdir
     cwd = os.getcwd()
     try:
         os.chdir(pkg_path)
         self.assertTrue(os.path.isdir(path))
         par_dir = wc_parent(path)
         self.assertIsNotNone(par_dir)
         self.assertTrue(wc_is_project(par_dir))
         self.assertEqual(wc_read_project(par_dir), 'prj1')
     finally:
         os.chdir(cwd)
示例#10
0
 def test28(self):
     """test wc_parent cwd (package/non_existent - no parent)"""
     pkg_path = self.fixture_file('package')
     path = 'non_existent'
     cwd = os.getcwd()
     try:
         os.chdir(pkg_path)
         self.assertFalse(os.path.exists(path))
         par_dir = wc_parent(path)
         self.assertIsNotNone(par_dir)
         self.assertTrue(wc_is_package(par_dir))
         self.assertEqual(wc_read_package(par_dir), 'package')
     finally:
         os.chdir(cwd)
示例#11
0
 def test23(self):
     """test wc_parent (cwd)"""
     pkg_path = self.fixture_file('prj1', 'added')
     path = os.curdir
     cwd = os.getcwd()
     try:
         os.chdir(pkg_path)
         self.assertTrue(os.path.isdir(path))
         par_dir = wc_parent(path)
         self.assertIsNotNone(par_dir)
         self.assertTrue(wc_is_project(par_dir))
         self.assertEqual(wc_read_project(par_dir), 'prj1')
     finally:
         os.chdir(cwd)
示例#12
0
 def test29(self):
     """test wc_parent (project - no parent)"""
     path = self.fixture_file('project')
     self.assertTrue(os.path.isdir(path))
     par_dir = wc_parent(path)
     self.assertIsNone(par_dir)
示例#13
0
 def test26(self):
     """test wc_parent (package - no parent)"""
     path = self.fixture_file('package')
     self.assertTrue(os.path.isdir(path))
     par_dir = wc_parent(path)
     self.assertIsNone(par_dir)
示例#14
0
 def test29(self):
     """test wc_parent (project - no parent)"""
     path = self.fixture_file('project')
     self.assertTrue(os.path.isdir(path))
     par_dir = wc_parent(path)
     self.assertIsNone(par_dir)
示例#15
0
 def test26(self):
     """test wc_parent (package - no parent)"""
     path = self.fixture_file('package')
     self.assertTrue(os.path.isdir(path))
     par_dir = wc_parent(path)
     self.assertIsNone(par_dir)