Пример #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 _update(info):
    path = os.getcwd()
    par_path = os.path.join(path, os.pardir)
    expand = ''
    if hasattr(info, 'expand'):
        expand = info.expand
    if hasattr(info, 'package') and not wc_is_project(par_path):
        pkg = Package(path, transaction_listner=[MyTransactionListener()])
        pkg.update(expand=expand)
    elif hasattr(info, 'package') and wc_is_project(par_path):
        prj = Project(par_path, transaction_listener=[MyTransactionListener()])
        prj.update(*[info.package], expand=expand)
    elif wc_is_project(path):
        prj = Project(path, transaction_listener=[MyTransactionListener()])
        prj.update(expand=expand)
Пример #3
0
def _update(info):
    path = os.getcwd()
    par_path = os.path.join(path, os.pardir)
    expand = ''
    if hasattr(info, 'expand'):
        expand = info.expand
    if hasattr(info, 'package') and not wc_is_project(par_path):
        pkg = Package(path, transaction_listner=[MyTransactionListener()])
        pkg.update(expand=expand)
    elif hasattr(info, 'package') and wc_is_project(par_path):
        prj = Project(par_path, transaction_listener=[MyTransactionListener()])
        prj.update(*[info.package], expand=expand)
    elif wc_is_project(path):
        prj = Project(path, transaction_listener=[MyTransactionListener()])
        prj.update(expand=expand)
Пример #4
0
    def wc_resolve(self, path=''):
        """Try to read components from path.

        If path is specified it overrides the path which was passed
        to __init__.
        If all conditions are met (see class description for details)
        a dict is returned which contains the matches
        (some optional and _non_optional matches might be None).
        Otherwise None is returned.

        """
        path = path or self._path
        if not path:
            return None
        unresolved = dict([(comp.name, None) for comp in self._components])
        has_prj = 'project' in unresolved
        has_pkg = 'package' in unresolved and 'project' in unresolved
        if has_pkg:
            if wc_is_package(path):
                ret = {'apiurl': wc_read_apiurl(path),
                       'project': wc_read_project(path),
                       'package': wc_read_package(path)}
                unresolved.update(ret)
                return unresolved
        pkg_opt = True
        for comp in self._components:
            if comp.name == 'package':
                pkg_opt = comp.opt
        if has_prj and pkg_opt:
            if wc_is_project(path):
                ret = {'apiurl': wc_read_apiurl(path),
                       'project': wc_read_project(path)}
                unresolved.update(ret)
                return unresolved
        return None
Пример #5
0
 def test22(self):
     """test wc_parent (package)"""
     path = self.fixture_file('prj1', 'added')
     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')
Пример #6
0
 def test22(self):
     """test wc_parent (package)"""
     path = self.fixture_file('prj1', 'added')
     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')
Пример #7
0
 def _checkout_package(self, apiurl, project, package, info):
     tl = RendererUpdateTransactionListener(self._renderer)
     path = self._path_join(project)
     if wc_is_project(path):
         prj = Project(path, transaction_listener=[tl])
     else:
         prj = Project.init(path, project, apiurl,
                            transaction_listener=[tl])
     self._update_project(prj, info, package)
Пример #8
0
 def _checkout_package(self, apiurl, project, package, info):
     tl = RendererUpdateTransactionListener(self._renderer)
     path = self._path_join(project)
     if wc_is_project(path):
         prj = Project(path, transaction_listener=[tl])
     else:
         prj = Project.init(path,
                            project,
                            apiurl,
                            transaction_listener=[tl])
     self._update_project(prj, info, package)
Пример #9
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')
Пример #10
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')
Пример #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 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)
Пример #13
0
    def add(self, package, *filenames, **kwargs):
        """Add a new package to the project.

        package is the name of the directory which will be added.
        A ValueError is raised if package is already tracked or if
        package is already an osc working copy.
        Also if prj/package does not exist or is no directory
        a ValueError is raised.
        If filenames are specified they are added to package.
        If no filenames are specified all files will be added
        to the package.
        A ValueError is raised if filenames and no_files=True
        is specified.

        Keyword arguments:
        no_files -- add no files (default: False)

        """
        super(Project, self).add(package)
        no_files = kwargs.get('no_files', False)
        if filenames and no_files:
            raise ValueError("filenames and no_files are mutually exclusive")
        with wc_lock(self.path):
            if self._status(package) != '?':
                raise ValueError("package \"%s\" is already tracked" % package)
            pkg_path = os.path.join(self.path, package)
            if not os.path.isdir(pkg_path):
                raise ValueError("path \"%s\" is no dir" % pkg_path)
            elif wc_is_project(pkg_path) or wc_is_package(pkg_path):
                msg = ("path \"%s\" is already an initialized"
                       "working copy" % pkg_path)
                raise ValueError(msg)
            storedir = wc_pkg_data_mkdir(self.path, package)
            pkg = Package.init(pkg_path, self.name, package, self.apiurl,
                               ext_storedir=storedir)
            self._packages.add(package, state='A')
            self._packages.write()
            if no_files:
                filenames = []
            elif not filenames:
                filenames = [f for f in os.listdir(pkg.path)
                             if os.path.isfile(os.path.join(pkg.path, f))]
            for filename in filenames:
                pkg.add(filename)
Пример #14
0
    def add(self, package, *filenames, **kwargs):
        """Add a new package to the project.

        package is the name of the directory which will be added.
        A ValueError is raised if package is already tracked or if
        package is already an osc working copy.
        Also if prj/package does not exist or is no directory
        a ValueError is raised.
        If filenames are specified they are added to package.
        If no filenames are specified all files will be added
        to the package.
        A ValueError is raised if filenames and no_files=True
        is specified.

        Keyword arguments:
        no_files -- add no files (default: False)

        """
        super(Project, self).add(package)
        no_files = kwargs.get('no_files', False)
        if filenames and no_files:
            raise ValueError("filenames and no_files are mutually exclusive")
        with wc_lock(self.path):
            if self._status(package) != '?':
                raise ValueError("package \"%s\" is already tracked" % package)
            pkg_path = os.path.join(self.path, package)
            if not os.path.isdir(pkg_path):
                raise ValueError("path \"%s\" is no dir" % pkg_path)
            elif wc_is_project(pkg_path) or wc_is_package(pkg_path):
                msg = ("path \"%s\" is already an initialized"
                       "working copy" % pkg_path)
                raise ValueError(msg)
            storedir = wc_pkg_data_mkdir(self.path, package)
            pkg = Package.init(pkg_path, self.name, package, self.apiurl,
                               ext_storedir=storedir)
            self._packages.add(package, state='A')
            self._packages.write()
            if no_files:
                filenames = []
            elif not filenames:
                filenames = [f for f in os.listdir(pkg.path)
                             if os.path.isfile(os.path.join(pkg.path, f))]
            for filename in filenames:
                pkg.add(filename)
Пример #15
0
 def test3(self):
     """test wc_is_project"""
     self.assertFalse(wc_is_project('/'))
Пример #16
0
 def test2(self):
     """test wc_is_project"""
     path = self.fixture_file('package')
     self.assertFalse(wc_is_project(path))
Пример #17
0
 def test1(self):
     """test wc_is_project"""
     path = self.fixture_file('project')
     self.assertTrue(wc_is_project(path))
Пример #18
0
 def test1(self):
     """test wc_is_project"""
     path = self.fixture_file('project')
     self.assertTrue(wc_is_project(path))
Пример #19
0
 def test3(self):
     """test wc_is_project"""
     self.assertFalse(wc_is_project('/'))
Пример #20
0
 def test2(self):
     """test wc_is_project"""
     path = self.fixture_file('package')
     self.assertFalse(wc_is_project(path))