Commits

Apostolis Bessas committed 5f11c0b

Allow to specify the minimum_perc option with the set command.

Comments (0)

Files changed (3)

txclib/commands.py

         except IndexError:
             parser.error("Please specify an remote url")
         _auto_remote(path_to_tx, url)
+        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
     # if we have --source, we set source
     elif options.is_source:
         resource = options.resource
         # Calculate relative path
         path_to_file = relpath(file, path_to_tx)
         _set_source_file(path_to_tx, resource, options.language, path_to_file)
+        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
     elif options.i18n_type:
         resource = options.resource
         if not resource:
         prj = project.Project(path_to_tx)
         prj.set_i18n_type(resources, options.i18n_type)
         prj.save()
+        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
+    elif options.minimum_perc is not None:
+        _set_minimum_perc(options.resource, options.minimum_perc, path_to_tx)
     else:
         resource = options.resource
         lang = options.language
                 ".<resource_slug> and the valid characters include [_-\w].")
 
         _set_translation(path_to_tx, resource, lang, path_to_file)
-
     logger.info("Done.")
-
     return
 
 
             "Did you forget to run 'tx init' first?"
         )
     os.chdir(path)
+
+
+def _set_minimum_perc(resource, value, path_to_tx):
+    """Set the minimum percentage in the .tx/config file.
+
+    If the resource is None, set the setting as global.
+    """
+    if value is None:
+        return
+    if not resource:
+        logger.debug("Setting the minimum percentage for all resources.")
+        resources = []
+    else:
+        msg = "Setting the minimum percentage for resource %s."
+        logger.debug(msg % resource)
+        resources = [resource, ]
+    prj = project.Project(path_to_tx)
+    prj.set_min_perc(resources, value)
+    prj.save()

txclib/parsers.py

             "http://help.transifex.net/features/formats.html"
         )
     )
+    parser.add_option("--minimum-perc", action="store", dest="minimum_perc",
+        help=(
+            "Specify the minimum acceptable percentage of a translation "
+            "in order to download it."
+        )
+    )
     group = OptionGroup(parser, "Extended options", "These options can only be"
         " used with the --auto-local command.")
     group.add_option("-s","--source-language", action="store",

txclib/project.py

         for r in resources:
             self.config.set(r, 'type', i18n_type)
 
+    def set_min_perc(self, resources, perc):
+        """Set the minimum percentage for the resources.
+
+        If resources is empty. set the percent globally.
+        """
+        if not resources:
+            self.config.set('main', 'minimum_perc', perc)
+            return
+        for r in resources:
+            self.config.set(r, 'minimum_perc', perc)
+