def handle_clear(self, segments, usernames, start_date, end_date,
                     **options):
        """Clear segments for usernames."""
        with lockfile(LOCKFILE, LOCK_EX, wait=True):
            user_segments = [get_user_segments(s, usernames,
                                               start_date=start_date,
                                               end_date=end_date)
                             for s in segments]
            # Print all the segments that will be cleared.
            for user_segment in chain(*user_segments):
                self.info(repr(user_segment), **options)
            total = sum(len(l) for l in user_segments)
            self.info('Total: %d' % total, **options)
            if not total:
                return
            # Confirm this action.
            if options.get('interactive'):
                confirm = raw_input('Clear these segments? [yN] ')
            else:
                confirm = 'y'
            # Clear segments.
            if confirm and confirm in 'yY':
                for p in chain(*user_segments):
                    p.delete()
                self.info('Cleared: %d' % total, **options)
            else:
                self.info('Aborted.', **options)
dataset/ETHPy150Open e-loue/django-lean/django_lean/lean_segments/management/commands/lean_segments.py/Command.handle_clear/original