Example #1
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)
Example #2
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)