def handle_update(self, segments, usernames, start_date, end_date,
                      **options):
        """Update segments for usernames, but only if they are missing."""
        with lockfile(LOCKFILE, LOCK_EX, wait=options['wait']):
            total = 0
            users = get_users(usernames=usernames)
            for user in users:
                for segment in segments:
                    assigned = segment.objects.assign(user=user,
                                                      start_date=start_date,
                                                      end_date=end_date)
                    if assigned:
                        self.info('Updated %r: %d' % (user, len(assigned)),
                                  **options)
                        total += len(assigned)
            self.info('Updated: %d' % total, **options)
dataset/ETHPy150Open e-loue/django-lean/django_lean/lean_segments/management/commands/lean_segments.py/Command.handle_update/original