Browse Source

Small style tweaks in management commands (#1022)

* Small style changes in rebuildpostssearch

* Unify codestyle in management commands
Rafał Pitoń 7 years ago
parent
commit
ef322cdf36

+ 7 - 9
misago/threads/management/commands/clearattachments.py

@@ -28,18 +28,16 @@ class Command(BaseCommand):
             self.sync_attachments(queryset, attachments_to_sync)
 
     def sync_attachments(self, queryset, attachments_to_sync):
-        message = "Clearing %s attachments...\n"
-        self.stdout.write(message % attachments_to_sync)
+        self.stdout.write("Clearing {} attachments...\n".format(attachments_to_sync))
 
-        message = "\n\nCleared %s attachments"
-
-        synchronized_count = 0
-        show_progress(self, synchronized_count, attachments_to_sync)
+        cleared_count = 0
+        show_progress(self, cleared_count, attachments_to_sync)
         start_time = time.time()
+        
         for attachment in chunk_queryset(queryset):
             attachment.delete()
 
-            synchronized_count += 1
-            show_progress(self, synchronized_count, attachments_to_sync, start_time)
+            cleared_count += 1
+            show_progress(self, cleared_count, attachments_to_sync, start_time)
 
-        self.stdout.write(message % synchronized_count)
+        self.stdout.write("\n\nCleared {} attachments".format(cleared_count))

+ 10 - 13
misago/threads/management/commands/rebuildpostssearch.py

@@ -11,21 +11,18 @@ class Command(BaseCommand):
     help = "Rebuilds posts search"
 
     def handle(self, *args, **options):
-        posts_to_sync = Post.objects.filter(is_event=False).count()
+        posts_to_reindex = Post.objects.filter(is_event=False).count()
 
-        if not posts_to_sync:
+        if not posts_to_reindex:
             self.stdout.write("\n\nNo posts were found")
         else:
-            self.sync_threads(posts_to_sync)
+            self.rebuild_posts_search(posts_to_reindex)
 
-    def sync_threads(self, posts_to_sync):
-        message = "Rebuilding %s posts...\n"
-        self.stdout.write(message % posts_to_sync)
+    def rebuild_posts_search(self, posts_to_reindex):
+        self.stdout.write("Rebuilding search for {} posts...\n".format(posts_to_reindex))
 
-        message = "\n\nRebuild %s posts"
-
-        synchronized_count = 0
-        show_progress(self, synchronized_count, posts_to_sync)
+        rebuild_count = 0
+        show_progress(self, rebuild_count, posts_to_reindex)
         start_time = time.time()
 
         queryset = Post.objects.select_related('thread').filter(is_event=False)
@@ -39,7 +36,7 @@ class Command(BaseCommand):
             post.update_search_vector()
             post.save(update_fields=['search_vector'])
 
-            synchronized_count += 1
-            show_progress(self, synchronized_count, posts_to_sync, start_time)
+            rebuild_count += 1
+            show_progress(self, rebuild_count, posts_to_reindex, start_time)
 
-        self.stdout.write(message % synchronized_count)
+        self.stdout.write("\n\nRebuild search for {} posts".format(rebuild_count))

+ 3 - 5
misago/threads/management/commands/synchronizethreads.py

@@ -19,14 +19,12 @@ class Command(BaseCommand):
             self.sync_threads(threads_to_sync)
 
     def sync_threads(self, threads_to_sync):
-        message = "Synchronizing %s threads...\n"
-        self.stdout.write(message % threads_to_sync)
-
-        message = "\n\nSynchronized %s threads"
+        self.stdout.write("Synchronizing {} threads...\n".format(threads_to_sync))
 
         synchronized_count = 0
         show_progress(self, synchronized_count, threads_to_sync)
         start_time = time.time()
+
         for thread in chunk_queryset(Thread.objects.all()):
             thread.synchronize()
             thread.save()
@@ -34,4 +32,4 @@ class Command(BaseCommand):
             synchronized_count += 1
             show_progress(self, synchronized_count, threads_to_sync, start_time)
 
-        self.stdout.write(message % synchronized_count)
+        self.stdout.write("\n\nSynchronized {} threads".format(synchronized_count))

+ 2 - 3
misago/threads/management/commands/updatepostschecksums.py

@@ -20,8 +20,7 @@ class Command(BaseCommand):
             self.update_posts_checksums(posts_to_update)
 
     def update_posts_checksums(self, posts_to_update):
-        message = "Updating %s posts checksums...\n"
-        self.stdout.write(message % posts_to_update)
+        self.stdout.write("Updating {} posts checksums...\n".format(posts_to_update))
 
         updated_count = 0
         show_progress(self, updated_count, posts_to_update)
@@ -35,4 +34,4 @@ class Command(BaseCommand):
             updated_count += 1
             show_progress(self, updated_count, posts_to_update, start_time)
 
-        self.stdout.write("\n\nUpdated %s posts checksums" % updated_count)
+        self.stdout.write("\n\nUpdated {} posts checksums".format(updated_count))

+ 2 - 2
misago/users/management/commands/createsuperuser.py

@@ -166,8 +166,8 @@ class Command(BaseCommand):
             )
 
             if verbosity >= 1:
-                message = "Superuser #%(pk)s has been created successfully."
-                self.stdout.write(message % {'pk': user.pk})
+                message = "Superuser #{pk} has been created successfully."
+                self.stdout.write(message.format(pk=user.pk))
         except ValidationError as e:
             self.stderr.write(e.messages[0])
         except IntegrityError as e:

+ 2 - 2
misago/users/management/commands/invalidatebans.py

@@ -20,7 +20,7 @@ class Command(BaseCommand):
         queryset = queryset.filter(expires_on__lt=timezone.now())
 
         expired_count = queryset.update(is_checked=False)
-        self.stdout.write("Bans invalidated: %s" % expired_count)
+        self.stdout.write("Bans invalidated: {}".format(expired_count))
 
     def handle_bans_caches(self):
         queryset = BanCache.objects.filter(expires_on__lt=timezone.now())
@@ -34,4 +34,4 @@ class Command(BaseCommand):
         expired_count += queryset.count()
         queryset.delete()
 
-        self.stdout.write("Ban caches emptied: %s" % expired_count)
+        self.stdout.write("Ban caches emptied: {}".format(expired_count))

+ 1 - 1
misago/users/management/commands/populateonlinetracker.py

@@ -18,4 +18,4 @@ class Command(BaseCommand):
             Online.objects.create(user=user, last_click=user.last_login)
             entries_created += 1
 
-        self.stdout.write("Tracker entries created: %s" % entries_created)
+        self.stdout.write("Tracker entries created: {}".format(entries_created))

+ 3 - 3
misago/users/management/commands/synchronizeusers.py

@@ -25,12 +25,12 @@ class Command(BaseCommand):
     def sync_users(self, users_to_sync):
         categories = Category.objects.root_category().get_descendants()
 
-        message = "Synchronizing %s users...\n"
-        self.stdout.write(message % users_to_sync)
+        self.stdout.write("Synchronizing {} users...\n".format(users_to_sync))
 
         synchronized_count = 0
         show_progress(self, synchronized_count, users_to_sync)
         start_time = time.time()
+        
         for user in chunk_queryset(UserModel.objects.all()):
             user.threads = user.thread_set.filter(
                 category__in=categories,
@@ -52,4 +52,4 @@ class Command(BaseCommand):
             synchronized_count += 1
             show_progress(self, synchronized_count, users_to_sync, start_time)
 
-        self.stdout.write("\n\nSynchronized %s users" % synchronized_count)
+        self.stdout.write("\n\nSynchronized {} users".format(synchronized_count))