示例#1
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))
示例#2
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))
示例#3
0
 def _perform_adds(self, ustate, **kwargs):
     uinfo = ustate.info
     tl = self.notifier.listener
     for package in uinfo.added:
         tmp_dir = os.path.join(ustate.location, package)
         storedir = wc_pkg_data_filename(self.path, package)
         if ustate.state == UpdateStateMixin.STATE_PREPARE:
             os.mkdir(storedir)
             pkg = Package.init(tmp_dir, self.name, package,
                                self.apiurl, storedir,
                                transaction_listener=tl)
             pkg.update(**kwargs)
             ustate.state = UpdateStateMixin.STATE_UPDATING
         # fixup symlink
         new_dir = os.path.join(self.path, package)
         path = os.path.relpath(storedir, new_dir)
         old_storelink = _storedir(tmp_dir)
         if os.path.isdir(tmp_dir):
             if os.path.exists(old_storelink):
                 os.unlink(old_storelink)
             os.symlink(path, old_storelink)
             os.rename(tmp_dir, new_dir)
         ustate.processed(package, ' ')
         self.notifier.processed(package, ' ', None)
示例#4
0
 def _perform_adds(self, ustate, **kwargs):
     uinfo = ustate.info
     tl = self.notifier.listener
     for package in uinfo.added:
         tmp_dir = os.path.join(ustate.location, package)
         storedir = wc_pkg_data_filename(self.path, package)
         if ustate.state == UpdateStateMixin.STATE_PREPARE:
             os.mkdir(storedir)
             pkg = Package.init(tmp_dir, self.name, package,
                                self.apiurl, storedir,
                                transaction_listener=tl)
             pkg.update(**kwargs)
             ustate.state = UpdateStateMixin.STATE_UPDATING
         # fixup symlink
         new_dir = os.path.join(self.path, package)
         path = os.path.relpath(storedir, new_dir)
         old_storelink = _storedir(tmp_dir)
         if os.path.isdir(tmp_dir):
             if os.path.exists(old_storelink):
                 os.unlink(old_storelink)
             os.symlink(path, old_storelink)
             os.rename(tmp_dir, new_dir)
         ustate.processed(package, ' ')
         self.notifier.processed(package, ' ', None)
示例#5
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)
示例#6
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)