Esempio n. 1
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()
Esempio n. 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()
Esempio n. 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)
Esempio n. 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)
Esempio n. 5
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)
Esempio n. 6
0
    def wc_check(cls, path):
        """Check path is a consistent project working copy.

        A 2-tuple (missing, xml_data) is returned:
        - missing is a tuple which contains all missing storefiles
        - xml_data is a str which contains the invalid packages xml str
          (if the xml is valid xml_data is the empty str (''))

        """
        meta = missing_storepaths(path, '_project', '_apiurl',
                                  '_packages', '_version')
        dirs = missing_storepaths(path, 'data', dirs=True)
        missing = meta + dirs
        if '_packages' in missing:
            return (missing, '', [])
        # check if _packages file is a valid xml
        try:
            packages = wc_read_packages(path)
        except ValueError:
            return (missing, wc_read_packages(path, raw=True), [])
        packages = [p.get('name') for p in packages]
        pkg_data = missing_storepaths(path, *packages, data=True, dirs=True)
        return (missing, '', pkg_data)
Esempio n. 7
0
    def wc_check(cls, path):
        """Check path is a consistent project working copy.

        A 2-tuple (missing, xml_data) is returned:
        - missing is a tuple which contains all missing storefiles
        - xml_data is a str which contains the invalid packages xml str
          (if the xml is valid xml_data is the empty str (''))

        """
        meta = missing_storepaths(path, '_project', '_apiurl',
                                  '_packages', '_version')
        dirs = missing_storepaths(path, 'data', dirs=True)
        missing = meta + dirs
        if '_packages' in missing:
            return (missing, '', [])
        # check if _packages file is a valid xml
        try:
            packages = wc_read_packages(path)
        except ValueError:
            return (missing, wc_read_packages(path, raw=True), [])
        packages = [p.get('name') for p in packages]
        pkg_data = missing_storepaths(path, *packages, data=True, dirs=True)
        return (missing, '', pkg_data)
Esempio n. 8
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)