Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)