def write_ring(self, btype, builder):
        """Write out new ring files

        :param btype: The builder type
        :param builder: The builder to dump
        :returns: new ring file md5
        """
        try:
            self.pause_if_asked()
            ring_file = self.ring_files[btype]
            fd, tmppath = mkstemp(dir=self.swiftdir, suffix='.tmp.ring.gz')
            builder.get_ring().save(tmppath)
            close(fd)
            if not is_valid_ring(tmppath):
                unlink(tmppath)
                raise Exception('Ring Validate Failed')
            backup, backup_md5 = make_backup(ring_file, self.backup_dir)
            self.logger.notice('--> Backed up %s to %s (%s)' %
                              (ring_file, backup, backup_md5))
            chmod(tmppath, 0644)
            rename(tmppath, ring_file)
        except Exception as err:
            raise Exception('Error writing builder: %s' % err)
        finally:
            if fd:
                try:
                    close(fd)
                except OSError:
                    pass
            if tmppath:
                try:
                    unlink(tmppath)
                except OSError:
                    pass
        return get_md5sum(ring_file)
    def write_builder(self, btype, builder):
        """Write out new builder file

        :param btype: The builder type
        :param builder: The builder to dump
        :returns: new ring file md5
        """
        self.pause_if_asked()
        builder_file = self.builder_files[btype]
        try:
            fd, tmppath = mkstemp(dir=self.swiftdir, suffix='.tmp.builder')
            pickle.dump(builder.to_dict(), fdopen(fd, 'wb'), protocol=2)
            backup, backup_md5 = make_backup(builder_file, self.backup_dir)
            self.logger.notice('--> Backed up %s to %s (%s)' %
                              (builder_file, backup, backup_md5))
            chmod(tmppath, 0644)
            rename(tmppath, builder_file)
        except Exception as err:
            raise Exception('Error writing builder: %s' % err)
        finally:
            if fd:
                try:
                    close(fd)
                except OSError:
                    pass
            if tmppath:
                try:
                    unlink(tmppath)
                except OSError:
                    pass
        return get_md5sum(builder_file)