Repository: translate/pootle

Issue:
update_tmserver: Refactor options
Right now `update_tmserver` accepts several options (`--rebuild`, `--overwrite`) but it is not clear what they are for. After a discussion with @dwaynebailey we outlined three scenarios:

1) Add translations added since last indexed revision. This creates the index if missing, and adds translations from start if there is no last indexed revision. This is just calling `update_tmserver`.
2) Destroy index if it exists, create the index, and add all translations. This is calling `update_tmserver --rebuild`.
3) Add all translations from start, regardless of if there is last indexed revision, so this updates previously indexed translations in case they were changed afterwards and keeps previously indexed translations that are now gone (e.g. translations from removed projects). This creates the index if missing (this is scenario 1) with no previous index). What makes this scenario different from scenario 2) is that the index is not destroyed. This is calling `update_tmserver --refresh`.

Note that `--dry-run` can also be used for any of those three scenarios. In this case no changes to the index are done (no destroy, no create, no update).



Discussion:
I might have misunderstood the description, but I see no specific suggestions being made here :confused:

@julen I think the 1), 2), 3) are the options i.e. `--rebuild` `--refresh` and keeping `--dry-run`

This is not about specific suggestions being made. It is just stating how it should be. Right now the command handles the following scenarios:

1) This is as 1) scenario in issue description above.
2) This is as 2) scenario in issue description above.
3) Using `--overwrite`. This is not completely clear what achieves. According to docs this might even be run alongside `--rebuild`: _"To ensure that the TM server remains available when you rebuild you can add `--overwrite`."_ in http://docs.translatehouse.org/projects/pootle/en/stable-2.7.2/server/commands.html#update-tmserver

You can also provide `--dry-run` for all these scenarios, resulting in no change to the index is actually performed.

The purpose of this issue is to clarify all the possible scenarios, and provide clear distinctive flags for each (scenarios 1) and 2) will be left unchanged). Also see #4135 for keeping TM alive while updating it, a functionality that `--overwrite` is supposed to provide, but actually doesn't.

So is this only about adding a `--refresh` flag which will replace `--overwrite`?

@unho now even I'm unclear. Can we just PR something related to this.  It seems any discussion just confuses things here.  Please don't rely on the docs, they're quite possibly wrong.  Realise this command is a port from Perl and was a throwaway command until it landed in Python where we use it almost always only once to create the initial TM.  And since I did the port and even I've been unclear - well take that as your position on which parts to believe.

@julen yip that is about my summary.  But really making `--overwrite` clearly its own command and trying to make its use more clear.


Resolving patch:
diff --git a/pootle/apps/pootle_app/management/commands/update_tmserver.py b/pootle/apps/pootle_app/management/commands/update_tmserver.py
--- a/pootle/apps/pootle_app/management/commands/update_tmserver.py
+++ b/pootle/apps/pootle_app/management/commands/update_tmserver.py
@@ -29,13 +29,12 @@
 class Command(BaseCommand):
     help = "Load Local Translation Memory"
     option_list = BaseCommand.option_list + (
-        make_option('--overwrite',
+        make_option('--refresh',
                     action="store_true",
-                    dest='overwrite',
+                    dest='refresh',
                     default=False,
-                    help='Process all items, not just the new ones (useful to '
-                         'overwrite properties while keeping the index in a '
-                         'working condition)'),
+                    help='Process all items, not just the new ones, so '
+                         'existing translations are refreshed'),
         make_option('--rebuild',
                     action="store_true",
                     dest='rebuild',
@@ -141,7 +140,7 @@ def handle(self, *args, **options):
             es.indices.create(index=self.INDEX_NAME)
 
         if (not options['rebuild'] and
-            not options['overwrite'] and
+            not options['refresh'] and
             es.indices.exists(self.INDEX_NAME)):
             result = es.search(
                 index=self.INDEX_NAME,


Test patch: