def run_checks(self, unit=None, project=None, batch=False): """Update checks for this unit.""" if unit is None: try: unit = self.units[0] except IndexError: return content_hash = unit.content_hash src = unit.get_source_plurals() if project is None: project = self.component.project # Fetch old checks if self.component.checks_cache is not None: old_checks = self.component.checks_cache.get( (content_hash, None), [] ) else: old_checks = set( Check.objects.filter( content_hash=content_hash, project=project, language=None ).values_list('check', flat=True) ) create = [] # Run all source checks for check, check_obj in CHECKS.items(): if batch and check_obj.batch_update: if check in old_checks: # Do not remove batch checks in batch processing old_checks.remove(check) continue if check_obj.source and check_obj.check_source(src, unit): if check in old_checks: # We already have this check old_checks.remove(check) else: # Create new check create.append(Check( content_hash=content_hash, project=project, language=None, ignore=False, check=check )) if create: Check.objects.bulk_create_ignore(create) # Remove stale checks if old_checks: Check.objects.filter( content_hash=content_hash, project=project, language=None, check__in=old_checks ).delete()
def run_checks(self, same_state=True, same_content=True): """Update checks for this unit.""" was_change = False has_checks = None is_source = self.translation.is_source src = self.get_source_plurals() tgt = self.get_target_plurals() old_checks = set(self.check_set.values_list('check', flat=True)) create = [] # Run all checks for check, check_obj in CHECKS.items(): # Do not remove batch checks in batch processing if self.is_batch_update and check_obj.batch_update: old_checks.discard(check) continue # Does the check fire? if ( not is_source and check_obj.target and check_obj.check_target(src, tgt, self) ) or (is_source and check_obj.source and check_obj.check_source(src, self)): if check in old_checks: # We already have this check old_checks.remove(check) else: # Create new check create.append( Check( unit=self, ignore=False, check=check, ) ) was_change = True has_checks = True if create: Check.objects.bulk_create_ignore(create) # Delete no longer failing checks if old_checks: was_change = True Check.objects.filter( unit=self, check__in=old_checks, ).delete() # Update failing checks flag if not self.is_batch_update and (was_change or not same_content): self.update_has_failing_check(was_change, has_checks)
def run_batch_checks(self, attr_name): """Run batch executed checks.""" from weblate.trans.models import Unit create = [] meth_name = 'check_{}_project'.format(attr_name) for check, check_obj in CHECKS.items(): if not getattr(check_obj, attr_name) or not check_obj.batch_update: continue self.log_info('running batch check: %s', check) # List of triggered checks data = getattr(check_obj, meth_name)(self) # Fetch existing check instances existing = set( Check.objects.filter( unit__translation__component__project=self, check=check).values_list('unit__content_hash', 'unit__translation__language_id')) # Create new check instances for item in data: if 'translation__language' not in item: item['translation__language'] = self.source_language.id key = (item['content_hash'], item['translation__language']) if key in existing: existing.discard(key) else: units = Unit.objects.filter( translation__component__project=self, translation__language_id=item['translation__language'], content_hash=item['content_hash'], ) for unit in units: create.append( Check(unit=unit, check=check, ignore=False)) # Remove stale instances if existing: query = functools.reduce( lambda q, value: q | (Q(unit__content_hash=value[0]) & Q(unit__translation__language_id=value[1])), existing, Q(), ) Check.objects.filter(check=check).filter(query).delete() # Create new checks if create: Check.objects.bulk_create(create, batch_size=500, ignore_conflicts=True)
def run_checks(self, units=None, unit=None): """Update checks for this unit.""" units = self.units if units is None else units if not units: return unit = units[0] if unit is None else unit content_hash = unit.content_hash src = unit.get_source_plurals() project = self.component.project was_change = False has_checks = None # Fetch old checks old_checks = set( Check.objects.filter(content_hash=content_hash, project=project, language=None).values_list('check', flat=True)) # Run all source checks for check, check_obj in CHECKS.items(): if CHECKS[check].source and check_obj.check_source(src, unit): if check in old_checks: # We already have this check old_checks.remove(check) else: # Create new check Check.objects.create(content_hash=content_hash, project=project, language=None, ignore=False, check=check) was_change = True has_checks = True # Remove stale checks if old_checks: Check.objects.filter(content_hash=content_hash, project=project, language=None, check__in=old_checks).delete() was_change = True # Update unit flags if was_change: for unit in units: unit.update_has_failing_check(was_change, has_checks)
def run_batch_checks(self, attr_name): """Run batch executed checks""" create = [] meth_name = 'check_{}_project'.format(attr_name) for check, check_obj in CHECKS.items(): if not getattr(check_obj, attr_name) or not check_obj.batch_update: continue self.log_info('running batch check: %s', check) # List of triggered checks data = getattr(check_obj, meth_name)(self) # Fetch existing check instances existing = set( Check.objects.filter( project=self, check=check ).values_list( 'content_hash', 'language_id' ) ) # Create new check instances for item in data: if 'translation__language' not in item: item['translation__language'] = None key = (item['content_hash'], item['translation__language']) if key in existing: existing.discard(key) else: create.append(Check( content_hash=item['content_hash'], project=self, language_id=item['translation__language'], check=check, ignore=False, )) # Remove stale instances if existing: query = functools.reduce( lambda q, value: q | (Q(content_hash=value[0]) & Q(language_id=value[1])), existing, Q() ) Check.objects.filter(check=check).filter(query).delete() # Create new checks if create: Check.objects.bulk_create_ignore(create)
def run_checks(self, unit=None): """Update checks for this unit.""" if unit is None: try: unit = self.units[0] except IndexError: return content_hash = unit.content_hash src = unit.get_source_plurals() project = self.component.project # Fetch old checks old_checks = set( Check.objects.filter( content_hash=content_hash, project=project, language=None ).values_list('check', flat=True) ) # Run all source checks for check, check_obj in CHECKS.items(): if check_obj.source and check_obj.check_source(src, unit): if check in old_checks: # We already have this check old_checks.remove(check) else: # Create new check Check.objects.create( content_hash=content_hash, project=project, language=None, ignore=False, check=check ) # Remove stale checks if old_checks: Check.objects.filter( content_hash=content_hash, project=project, language=None, check__in=old_checks ).delete()
def run_checks(self, unit=None, project=None): """Update checks for this unit.""" if unit is None: try: unit = self.units[0] except IndexError: return content_hash = unit.content_hash src = unit.get_source_plurals() if project is None: project = self.component.project # Fetch old checks old_checks = set( Check.objects.filter(content_hash=content_hash, project=project, language=None).values_list('check', flat=True)) # Run all source checks for check, check_obj in CHECKS.items(): if check_obj.source and check_obj.check_source(src, unit): if check in old_checks: # We already have this check old_checks.remove(check) else: # Create new check Check.objects.create(content_hash=content_hash, project=project, language=None, ignore=False, check=check) # Remove stale checks if old_checks: Check.objects.filter(content_hash=content_hash, project=project, language=None, check__in=old_checks).delete()
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from weblate.checks import CHECKS EXTRA_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.default_disabled } EXTRA_FLAGS['rst-text'] = ugettext_lazy('RST text') EXTRA_FLAGS['md-text'] = ugettext_lazy('Markdown text') EXTRA_FLAGS['xml-text'] = ugettext_lazy('XML text') EXTRA_FLAGS['dos-eol'] = ugettext_lazy('DOS line endings') EXTRA_FLAGS['url'] = ugettext_lazy('URL') EXTRA_FLAGS['auto-java-messageformat'] = ugettext_lazy( 'Automatically detect Java MessageFormat' ) IGNORE_CHECK_FLAGS = {CHECKS[x].ignore_string for x in CHECKS}
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _, ugettext_lazy from weblate.checks import CHECKS EXTRA_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.default_disabled } EXTRA_FLAGS['rst-text'] = ugettext_lazy('RST text') EXTRA_FLAGS['xml-text'] = ugettext_lazy('XML text') EXTRA_FLAGS['dos-eol'] = ugettext_lazy('DOS end of lines') EXTRA_FLAGS['auto-java-messageformat'] = ugettext_lazy( 'Automatically detect Java MessageFormat') IGNORE_CHECK_FLAGS = {CHECKS[x].ignore_string for x in CHECKS} def validate_filemask(val): """Validate file mask that it contains *.""" if '*' not in val: raise ValidationError(
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # import six from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from weblate.checks import CHECKS from weblate.fonts.utils import get_font_weight PLAIN_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.default_disabled and not v.param_type } TYPED_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.param_type } TYPED_FLAGS_ARGS = { v.enable_string: v.param_type for k, v in CHECKS.items() if v.param_type } PLAIN_FLAGS["rst-text"] = ugettext_lazy("RST text") PLAIN_FLAGS["md-text"] = ugettext_lazy("Markdown text") PLAIN_FLAGS["xml-text"] = ugettext_lazy("XML text") PLAIN_FLAGS["dos-eol"] = ugettext_lazy("DOS line endings") PLAIN_FLAGS["url"] = ugettext_lazy("URL")
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # import six from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from weblate.checks import CHECKS from weblate.fonts.utils import get_font_weight PLAIN_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.default_disabled and not v.param_type } TYPED_FLAGS = {v.enable_string: v.name for k, v in CHECKS.items() if v.param_type} TYPED_FLAGS_ARGS = { v.enable_string: v.param_type for k, v in CHECKS.items() if v.param_type } PLAIN_FLAGS["rst-text"] = ugettext_lazy("RST text") PLAIN_FLAGS["md-text"] = ugettext_lazy("Markdown text") PLAIN_FLAGS["xml-text"] = ugettext_lazy("XML text") PLAIN_FLAGS["dos-eol"] = ugettext_lazy("DOS line endings") PLAIN_FLAGS["url"] = ugettext_lazy("URL") PLAIN_FLAGS["auto-java-messageformat"] = ugettext_lazy( "Automatically detect Java MessageFormat" )
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _, ugettext_lazy from weblate.checks import CHECKS EXTRA_FLAGS = { v.enable_string: v.name for k, v in CHECKS.items() if v.default_disabled } EXTRA_FLAGS['rst-text'] = ugettext_lazy('RST text') EXTRA_FLAGS['md-text'] = ugettext_lazy('Mardown text') EXTRA_FLAGS['xml-text'] = ugettext_lazy('XML text') EXTRA_FLAGS['dos-eol'] = ugettext_lazy('DOS end of lines') EXTRA_FLAGS['url'] = ugettext_lazy('URL') EXTRA_FLAGS['auto-java-messageformat'] = ugettext_lazy( 'Automatically detect Java MessageFormat' ) IGNORE_CHECK_FLAGS = {CHECKS[x].ignore_string for x in CHECKS}