예제 #1
0
파일: packagedb.py 프로젝트: esodan/icbuild
    def uninstall(self, package_name):
        '''Remove a module from the install cache.'''
        entry = self.get(package_name)

        if entry is None:
            raise KeyError

        if entry.manifest is None:
            logging.error("no manifest for '%s', can't uninstall.  Try building again, then uninstalling." % (package_name,))
            return

        # Skip files that aren't in the prefix; otherwise we
        # may try to remove the user's ~ or something
        # (presumably we'd fail, but better not to try)
        to_delete = fileutils.filter_files_by_prefix(self.config, entry.manifest)

        # Don't warn on non-empty directories; we want to allow multiple
        # modules to share the same directory.  We could improve this by
        # reference-counting directories.
        for (path, was_deleted, error_string) in fileutils.remove_files_and_dirs(to_delete, allow_nonempty_dirs=True):
            if was_deleted:
                logging.info("Deleted: %(file)r" % {'file': path})
            elif error_string is None:
                pass
            else:
                logging.warn("Failed to delete %(file)r: %(msg)s" % { 'file': path,
                                                                      'msg': error_string})

        entry.remove()
예제 #2
0
파일: __init__.py 프로젝트: esodan/icbuild
    def process_install(self, buildscript, revision):
        assert self.supports_install_destdir
        destdir = self.get_destdir(buildscript)
        self._clean_la_files(buildscript, destdir)
        self._clean_texinfo_dir_files(buildscript, destdir)

        prefix_without_drive = os.path.splitdrive(buildscript.config.prefix)[1]
        stripped_prefix = prefix_without_drive[1:]

        install_succeeded = False
        save_broken_tree = False
        broken_name = destdir + '-broken'
        destdir_prefix = os.path.join(destdir, stripped_prefix)
        new_contents = fileutils.accumulate_dirtree_contents(destdir_prefix)
        errors = []
        if os.path.isdir(destdir_prefix):
            destdir_install = True
            logging.info('Moving temporary DESTDIR %r into build prefix' % (destdir, ))
            num_copied = self._process_install_files(destdir, destdir_prefix,
                                                     buildscript.config.prefix,
                                                     errors)

            # Now the destdir should have a series of empty directories:
            # $JHBUILD_PREFIX/_icbuild/root-foo/$JHBUILD_PREFIX
            # Remove them one by one to clean the tree to the state we expect,
            # so we can better spot leftovers or broken things.
            prefix_dirs = filter(lambda x: x != '', stripped_prefix.split(os.sep))
            while len(prefix_dirs) > 0:
                dirname = prefix_dirs.pop()
                subprefix = os.path.join(*([destdir] + prefix_dirs))
                target = os.path.join(subprefix, dirname)
                assert target.startswith(buildscript.config.prefix)
                try:
                    os.rmdir(target)
                except OSError as e:
                    pass

            remaining_files = os.listdir(destdir)
            if len(remaining_files) > 0:
                logging.warn("Files remaining in buildroot %(dest)r; module may have installed files outside of prefix." % {'num': len(remaining_files),
                                                                                                                            'dest': broken_name})
                save_broken_tree = True
            # Even if there are some files outside the DESTDIR, count that as success for now; we just warn
            install_succeeded = True
        else:
            save_broken_tree = True

        if save_broken_tree:
            if os.path.exists(broken_name):
                assert broken_name.startswith(buildscript.config.top_builddir)
                shutil.rmtree(broken_name)
            fileutils.rename(destdir, broken_name)
        else:
            assert destdir.startswith(buildscript.config.prefix)
            os.rmdir(destdir)

        if not install_succeeded:
            raise CommandError("Module failed to install into DESTDIR %(dest)r" % {'dest': broken_name})
        else:
            to_delete = set()
            previous_entry = buildscript.moduleset.packagedb.get(self.name)
            if previous_entry:
                previous_contents = previous_entry.get_manifest()
                if previous_contents:
                    to_delete.update(fileutils.filter_files_by_prefix(self.config, previous_contents))

            for filename in new_contents:
                to_delete.discard (os.path.join(self.config.prefix, filename))

            if to_delete:
                # paranoid double-check
                assert to_delete == set(fileutils.filter_files_by_prefix(self.config, to_delete))

                logging.info('%d files remaining from previous build' % (len(to_delete),))
                for (path, was_deleted, error_string) in fileutils.remove_files_and_dirs(to_delete, allow_nonempty_dirs=True):
                    if was_deleted:
                        logging.info('Deleted: %(file)r' % { 'file': path, })
                    elif error_string is None:
                        # We don't warn on not-empty directories
                        pass
                    else:
                        logging.warn("Failed to delete no longer installed file %(file)r: %(msg)s" % { 'file': path,
                                                                                                       'msg': error_string})

            buildscript.moduleset.packagedb.add(self.name, revision or '',
                                                new_contents,
                                                self.configure_cmd)

        if errors:
            raise CommandError('Install encountered errors: %(num)d '
                               'errors raised, %(files)d files copied. '
                               'The errors are:\n  %(err)s' %
                               {'num'   : len(errors),
                                'files' : num_copied,
                                'err'   : '\n  '.join(errors)})
        else:
            logging.info('Install complete: %d files copied' %
                         (num_copied, ))