示例#1
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
示例#2
0
def convert_project(path, project='', apiurl='', **package_states):
    """Convert working copy to the new format.

    path is the path to the project working copy.

    Keyword arguments:
    project -- the name of the project (default: '')
    apiurl -- the apiurl of the project (default: '')
    **package_states -- a package to state mapping (default: {})

    """
    Project.repair(path,
                   project=project,
                   apiurl=apiurl,
                   no_packages=True,
                   **package_states)
    _write_storefile(path, '_version', str(_VERSION))
    project = wc_read_project(path)
    apiurl = wc_read_apiurl(path)
    packages = wc_read_packages(path)
    for entry in packages:
        package = entry.get('name')
        package_path = os.path.join(path, package)
        storedir = wc_pkg_data_mkdir(path, package)
        convert_package(package_path,
                        project=project,
                        package=package,
                        apiurl=apiurl,
                        ext_storedir=storedir)
示例#3
0
    def __init__(self, path, verify_format=True, **kwargs):
        """Constructs a new project object.

        path is the path to the working copy.
        Raises a ValueError exception if path is
        no valid project working copy.
        Raises a WCInconsistentError if the wc's
        metadata is corrupt.

        Keyword arguments:
        verify_format -- verify working copy format (default: True)
        kwargs -- see class WorkingCopy for the details

        """
        if verify_format:
            wc_verify_format(path)
        meta, xml_data, pkg_data = self.wc_check(path)
        if meta or xml_data or pkg_data:
            raise WCInconsistentError(path, meta, xml_data, pkg_data)
        self.apiurl = wc_read_apiurl(path)
        self.name = wc_read_project(path)
        with wc_lock(path):
            self._packages = wc_read_packages(path)
        super(Project, self).__init__(path, ProjectUpdateState,
                                      ProjectCommitState, **kwargs)
示例#4
0
    def __init__(self, path, verify_format=True, **kwargs):
        """Constructs a new project object.

        path is the path to the working copy.
        Raises a ValueError exception if path is
        no valid project working copy.
        Raises a WCInconsistentError if the wc's
        metadata is corrupt.

        Keyword arguments:
        verify_format -- verify working copy format (default: True)
        kwargs -- see class WorkingCopy for the details

        """
        if verify_format:
            wc_verify_format(path)
        meta, xml_data, pkg_data = self.wc_check(path)
        if meta or xml_data or pkg_data:
            raise WCInconsistentError(path, meta, xml_data, pkg_data)
        self.apiurl = wc_read_apiurl(path)
        self.name = wc_read_project(path)
        with wc_lock(path):
            self._packages = wc_read_packages(path)
        super(Project, self).__init__(path, ProjectUpdateState,
                                      ProjectCommitState, **kwargs)
示例#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 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 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')
示例#9
0
    def repair(path, project='', apiurl='', no_packages=False,
               **package_states):
        """Repair a working copy.

        path is the path to the project working copy.

        Keyword arguments:
        project -- the name of the project (default: '')
        apiurl -- the apiurl of the project (default: '')
        no_packages -- do not repair the project's packages (default: False)
        **package_states -- a package to state mapping (default: {})

        """
        global _PKG_DATA
        missing, xml_data, pkg_data = Project.wc_check(path)
        if '_project' in missing:
            if not project:
                raise ValueError('project argument required')
            wc_write_project(path, project)
        if '_apiurl' in missing:
            if not apiurl:
                raise ValueError('apiurl argument required')
            wc_write_apiurl(path, apiurl)
        if '_packages' in missing or xml_data:
            if not package_states:
                raise ValueError('package states required')
            wc_write_packages(path, '<packages/>')
            packages = wc_read_packages(path)
            for package, st in package_states.items():
                packages.add(package, state=st)
            packages.write()
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        if not no_packages:
            project = wc_read_project(path)
            apiurl = wc_read_apiurl(path)
            packages = wc_read_packages(path)
            missing, xml_data, pkg_data = Project.wc_check(path)
            # only pkg data left
            for package in pkg_data:
                package_path = os.path.join(path, package)
                if os.path.isdir(package_path):
                    storedir = wc_pkg_data_mkdir(path, package)
                    Package.repair(package_path, project=project,
                                   package=package, apiurl=apiurl,
                                   ext_storedir=storedir)
                else:
                    packages.remove(package)
                    packages.write()
示例#10
0
    def repair(path, project='', apiurl='', no_packages=False,
               **package_states):
        """Repair a working copy.

        path is the path to the project working copy.

        Keyword arguments:
        project -- the name of the project (default: '')
        apiurl -- the apiurl of the project (default: '')
        no_packages -- do not repair the project's packages (default: False)
        **package_states -- a package to state mapping (default: {})

        """
        global _PKG_DATA
        missing, xml_data, pkg_data = Project.wc_check(path)
        if '_project' in missing:
            if not project:
                raise ValueError('project argument required')
            wc_write_project(path, project)
        if '_apiurl' in missing:
            if not apiurl:
                raise ValueError('apiurl argument required')
            wc_write_apiurl(path, apiurl)
        if '_packages' in missing or xml_data:
            if not package_states:
                raise ValueError('package states required')
            wc_write_packages(path, '<packages/>')
            packages = wc_read_packages(path)
            for package, st in package_states.iteritems():
                packages.add(package, state=st)
            packages.write()
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        if not no_packages:
            project = wc_read_project(path)
            apiurl = wc_read_apiurl(path)
            packages = wc_read_packages(path)
            missing, xml_data, pkg_data = Project.wc_check(path)
            # only pkg data left
            for package in pkg_data:
                package_path = os.path.join(path, package)
                if os.path.isdir(package_path):
                    storedir = wc_pkg_data_mkdir(path, package)
                    Package.repair(package_path, project=project,
                                   package=package, apiurl=apiurl,
                                   ext_storedir=storedir)
                else:
                    packages.remove(package)
                    packages.write()
示例#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 repair(path, ext_storedir=None, revision='latest', **kwargs):
        """Repair a working copy.

        path is the path to the package working copy.

        Keyword arguments:
        project -- name of the project (default: '')
        package -- name of the package (default: '')
        apiurl -- apiurl is the apiurl (default: '')
        revision -- the revision of the package (default: 'latest')
        ext_storedir -- path to the storedir (default: None)

        """
        global _PKG_DATA
        if not os.path.exists(_storedir(path)):
            wc_init(path, ext_storedir=ext_storedir)
        missing, xml_data, pkg_data = Package.wc_check(path)
        for filename in ('_project', '_package', '_apiurl'):
            if filename not in missing:
                continue
            key = filename[1:]
            if key not in kwargs:
                raise ValueError("%s argument required" % key)
            meth_name = 'wc_write_' + key
            globals()[meth_name](path, kwargs[key])
        project = wc_read_project(path)
        package = wc_read_package(path)
        apiurl = wc_read_apiurl(path)
        if '_files' in missing or xml_data:
            spkg = SourcePackage(project, package)
            directory = spkg.list(rev=revision, apiurl=apiurl)
            xml_data = etree.tostring(directory, pretty_print=True)
            wc_write_files(path, xml_data)
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        files = wc_read_files(path)
        # check again - only pkg_data left
        missing, xml_data, pkg_data = Package.wc_check(path)
        for filename in pkg_data:
            fname = wc_pkg_data_filename(path, filename)
            f = files.find(filename).file()
            f.write_to(fname)
        # clean unused storefiles
        store = wc_pkg_data_filename(path, '')
        for filename in os.listdir(store):
            if files.find(filename) is None:
                os.unlink(os.path.join(store, filename))
示例#14
0
    def repair(path, ext_storedir=None, revision='latest', **kwargs):
        """Repair a working copy.

        path is the path to the package working copy.

        Keyword arguments:
        project -- name of the project (default: '')
        package -- name of the package (default: '')
        apiurl -- apiurl is the apiurl (default: '')
        revision -- the revision of the package (default: 'latest')
        ext_storedir -- path to the storedir (default: None)

        """
        global _PKG_DATA
        if not os.path.exists(_storedir(path)):
            wc_init(path, ext_storedir=ext_storedir)
        missing, xml_data, pkg_data = Package.wc_check(path)
        for filename in ('_project', '_package', '_apiurl'):
            if filename not in missing:
                continue
            key = filename[1:]
            if key not in kwargs:
                raise ValueError("%s argument required" % key)
            meth_name = 'wc_write_' + key
            globals()[meth_name](path, kwargs[key])
        project = wc_read_project(path)
        package = wc_read_package(path)
        apiurl = wc_read_apiurl(path)
        if '_files' in missing or xml_data:
            spkg = SourcePackage(project, package)
            directory = spkg.list(rev=revision, apiurl=apiurl)
            xml_data = etree.tostring(directory, pretty_print=True)
            wc_write_files(path, xml_data)
        if '_version' in missing:
            wc_write_version(path)
        if _PKG_DATA in missing:
            os.mkdir(wc_pkg_data_filename(path, ''))
        files = wc_read_files(path)
        # check again - only pkg_data left
        missing, xml_data, pkg_data = Package.wc_check(path)
        for filename in pkg_data:
            fname = wc_pkg_data_filename(path, filename)
            f = files.find(filename).file()
            f.write_to(fname)
        # clean unused storefiles
        store = wc_pkg_data_filename(path, '')
        for filename in os.listdir(store):
            if files.find(filename) is None:
                os.unlink(os.path.join(store, filename))
示例#15
0
    def __init__(self,
                 path,
                 skip_handlers=None,
                 commit_policies=None,
                 merge_class=Merge,
                 verify_format=True,
                 **kwargs):
        """Constructs a new package object.

        path is the path to the working copy.
        Raises a ValueError exception if path is
        no valid package working copy.
        Raises a WCInconsistentError if the wc's
        metadata is corrupt.

        Keyword arguments:
        skip_handlers -- list of FileSkipHandler objects
                         (default: [])
        commit_policies -- list of FileCommitPolicy objects
                           (default: None)
        merge_class -- class which is used for a file merge
                       (default: Merge)
        verify_format -- verify working copy format (default: True)
        **kwargs -- see class WorkingCopy for the details

        """
        if verify_format:
            wc_verify_format(path)
        (meta, xml_data, pkg_data) = self.wc_check(path)
        if meta or xml_data or pkg_data:
            raise WCInconsistentError(path, meta, xml_data, pkg_data)
        self.apiurl = wc_read_apiurl(path)
        self.project = wc_read_project(path)
        self.name = wc_read_package(path)
        self.skip_handlers = skip_handlers or []
        self.commit_policies = commit_policies or []
        self.merge_class = merge_class
        with wc_lock(path):
            self._files = wc_read_files(path)
        # call super at the end due to finish_pending_transaction
        super(Package, self).__init__(path, PackageUpdateState,
                                      PackageCommitState, **kwargs)
示例#16
0
    def __init__(self, project_path, package_path, filename_path):
        """Constructs a new WCPath object.

        project_path is the path to the project wc. package_path is
        the path to the package wc. filename_path is the path to
        the wc filename. Either project_path or package_path or
        both aren't None.

        """
        self.project_path = project_path
        self.package_path = package_path
        self.filename_path = filename_path
        self.project = self.package = self.filename = None
        if self.project_path is not None:
            self.project = wc_read_project(self.project_path)
        if self.package_path is not None:
            if wc_is_package(self.package_path):
                self.package = wc_read_package(self.package_path)
            else:
                self.package = os.path.basename(self.package_path)
        if self.filename_path is not None:
            self.filename = os.path.basename(self.filename_path)
示例#17
0
文件: convert.py 项目: bergmannf/osc2
def convert_project(path, project='', apiurl='', **package_states):
    """Convert working copy to the new format.

    path is the path to the project working copy.

    Keyword arguments:
    project -- the name of the project (default: '')
    apiurl -- the apiurl of the project (default: '')
    **package_states -- a package to state mapping (default: {})

    """
    Project.repair(path, project=project, apiurl=apiurl, no_packages=True,
                   **package_states)
    _write_storefile(path, '_version', str(_VERSION))
    project = wc_read_project(path)
    apiurl = wc_read_apiurl(path)
    packages = wc_read_packages(path)
    for entry in packages:
        package = entry.get('name')
        package_path = os.path.join(path, package)
        storedir = wc_pkg_data_mkdir(path, package)
        convert_package(package_path, project=project, package=package,
                        apiurl=apiurl, ext_storedir=storedir)
示例#18
0
    def __init__(self, path, skip_handlers=None, commit_policies=None,
                 merge_class=Merge, verify_format=True, **kwargs):
        """Constructs a new package object.

        path is the path to the working copy.
        Raises a ValueError exception if path is
        no valid package working copy.
        Raises a WCInconsistentError if the wc's
        metadata is corrupt.

        Keyword arguments:
        skip_handlers -- list of FileSkipHandler objects
                         (default: [])
        commit_policies -- list of FileCommitPolicy objects
                           (default: None)
        merge_class -- class which is used for a file merge
                       (default: Merge)
        verify_format -- verify working copy format (default: True)
        **kwargs -- see class WorkingCopy for the details

        """
        if verify_format:
            wc_verify_format(path)
        (meta, xml_data, pkg_data) = self.wc_check(path)
        if meta or xml_data or pkg_data:
            raise WCInconsistentError(path, meta, xml_data, pkg_data)
        self.apiurl = wc_read_apiurl(path)
        self.project = wc_read_project(path)
        self.name = wc_read_package(path)
        self.skip_handlers = skip_handlers or []
        self.commit_policies = commit_policies or []
        self.merge_class = merge_class
        with wc_lock(path):
            self._files = wc_read_files(path)
        # call super at the end due to finish_pending_transaction
        super(Package, self).__init__(path, PackageUpdateState,
                                      PackageCommitState, **kwargs)
示例#19
0
def convert_package(path, ext_storedir=None, **kwargs):
    """Convert working copy to the new format.

    path is the path to the package working copy.

    Keyword arguments:
    project -- name of the project (default: '')
    package -- name of the package (default: '')
    apiurl -- apiurl is the apiurl (default: '')
    ext_storedir -- path to the external storedir (default: None)

    """
    data_path = wc_pkg_data_filename(path, '')
    if not os.path.exists(data_path):
        os.mkdir(data_path)
    if missing_storepaths(path, '_project'):
        project = kwargs.get('project', '')
        if not project:
            raise ValueError('project argument required')
    else:
        project = wc_read_project(path)
    deleted = []
    added = []
    conflicted = []
    if os.path.exists(_storefile(path, '_to_be_deleted')):
        deleted = _read_storefile(path, '_to_be_deleted').split()
        os.unlink(_storefile(path, '_to_be_deleted'))
    if os.path.exists(_storefile(path, '_to_be_added')):
        added = _read_storefile(path, '_to_be_added').split()
        os.unlink(_storefile(path, '_to_be_added'))
    if os.path.exists(_storefile(path, '_in_conflict')):
        conflicted = _read_storefile(path, '_in_conflict').split()
        os.unlink(_storefile(path, '_in_conflict'))
    try:
        files = wc_read_files(path)
    except ValueError:
        files = None
    if files is not None:
        files._xml.set('project', project)
        for entry in files:
            filename = entry.get('name')
            store = _storefile(path, filename)
            data = wc_pkg_data_filename(path, filename)
            if os.path.exists(store):
                os.rename(store, data)
            if filename in added:
                files.set(filename, 'A')
            elif filename in deleted:
                files.set(filename, 'D')
            elif filename in conflicted:
                files.set(filename, 'C')
            else:
                files.set(filename, ' ')
        for filename in added:
            if files.find(filename) is None:
                files.add(filename, 'A')
        files.write()
    if _storefile(path, '_osclib_version'):
        os.unlink(_storefile(path, '_osclib_version'))
    if ext_storedir is not None:
        # move all files to the new location
        storedir = _storedir(path)
        for filename in os.listdir(_storefile(path, '')):
            old = os.path.join(storedir, filename)
            new = os.path.join(ext_storedir, filename)
            os.rename(old, new)
        os.rmdir(storedir)
        os.symlink(os.path.relpath(ext_storedir, path), storedir)
    Package.repair(path, ext_storedir=ext_storedir, **kwargs)
示例#20
0
文件: convert.py 项目: bergmannf/osc2
def convert_package(path, ext_storedir=None, **kwargs):
    """Convert working copy to the new format.

    path is the path to the package working copy.

    Keyword arguments:
    project -- name of the project (default: '')
    package -- name of the package (default: '')
    apiurl -- apiurl is the apiurl (default: '')
    ext_storedir -- path to the external storedir (default: None)

    """
    data_path = wc_pkg_data_filename(path, '')
    if not os.path.exists(data_path):
        os.mkdir(data_path)
    if missing_storepaths(path, '_project'):
        project = kwargs.get('project', '')
        if not project:
            raise ValueError('project argument required')
    else:
        project = wc_read_project(path)
    deleted = []
    added = []
    conflicted = []
    if os.path.exists(_storefile(path, '_to_be_deleted')):
        deleted = _read_storefile(path, '_to_be_deleted').split()
        os.unlink(_storefile(path, '_to_be_deleted'))
    if os.path.exists(_storefile(path, '_to_be_added')):
        added = _read_storefile(path, '_to_be_added').split()
        os.unlink(_storefile(path, '_to_be_added'))
    if os.path.exists(_storefile(path, '_in_conflict')):
        conflicted = _read_storefile(path, '_in_conflict').split()
        os.unlink(_storefile(path, '_in_conflict'))
    try:
        files = wc_read_files(path)
    except ValueError:
        files = None
    if files is not None:
        files._xml.set('project', project)
        for entry in files:
            filename = entry.get('name')
            store = _storefile(path, filename)
            data = wc_pkg_data_filename(path, filename)
            if os.path.exists(store):
                os.rename(store, data)
            if filename in added:
                files.set(filename, 'A')
            elif filename in deleted:
                files.set(filename, 'D')
            elif filename in conflicted:
                files.set(filename, 'C')
            else:
                files.set(filename, ' ')
        for filename in added:
            if files.find(filename) is None:
                files.add(filename, 'A')
        files.write()
    if _storefile(path, '_osclib_version'):
        os.unlink(_storefile(path, '_osclib_version'))
    if ext_storedir is not None:
        # move all files to the new location
        storedir = _storedir(path)
        for filename in os.listdir(_storefile(path, '')):
            old = os.path.join(storedir, filename)
            new = os.path.join(ext_storedir, filename)
            os.rename(old, new)
        os.rmdir(storedir)
        os.symlink(os.path.relpath(ext_storedir, path), storedir)
    Package.repair(path, ext_storedir=ext_storedir, **kwargs)
示例#21
0
 def info(self):
     """Return the ProjectUpdateInfo object."""
     name = wc_read_project(self._path)
     lists = self._lists()
     return PackageUpdateInfo(name, **lists)
示例#22
0
 def info(self):
     """Return the ProjectUpdateInfo object."""
     name = wc_read_project(self._path)
     lists = self._lists()
     return PackageUpdateInfo(name, **lists)
示例#23
0
 def test7(self):
     """test wc_read_project"""
     path = self.fixture_file('project')
     self.assertEqual(wc_read_project(path), 'project')
示例#24
0
 def test8(self):
     """test wc_read_project"""
     path = self.fixture_file('package')
     self.assertEqual(wc_read_project(path), 'foobar')
示例#25
0
 def test7(self):
     """test wc_read_project"""
     path = self.fixture_file('project')
     self.assertEqual(wc_read_project(path), 'project')
示例#26
0
 def test8(self):
     """test wc_read_project"""
     path = self.fixture_file('package')
     self.assertEqual(wc_read_project(path), 'foobar')