Exemple #1
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)
Exemple #2
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()
Exemple #3
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()
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)