Exemplo n.º 1
0
    def _calc_wordcount_stats(self):
        result = self._get_wordcount_stats()
        self.initialize_children()
        for item in self.children:
            result = dictsum(result, item.get_cached(CachedMethods.WORDCOUNT_STATS))

        return result
Exemplo n.º 2
0
 def getcompletestats(self):
     if self.is_template_project:
         return empty_completestats
     file_result = completestatssum(self.child_stores.iterator())
     dir_result = completestatssum(self.child_dirs.iterator())
     stats = dictsum(file_result, dir_result)
     return stats
Exemplo n.º 3
0
 def getcompletestats(self):
     if self.is_template_project:
         return empty_completestats
     file_result = completestatssum(self.child_stores.iterator())
     dir_result  = completestatssum(self.child_dirs.iterator())
     stats = dictsum(file_result, dir_result)
     return stats
Exemplo n.º 4
0
    def update_project(self, request):
        """updates project translation files from version control,
        retaining uncommitted translations"""

        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to update from version control here"))

        old_stats = self.getquickstats()
        remote_stats = {}

        for store in self.stores.exclude(file="").iterator():
            try:
                oldstats, remotestats, newstats = self.update_file_from_version_control(store)
                remote_stats = dictsum(remote_stats, remotestats)
            except VersionControlError:
                pass

        self.scan_files()
        new_stats = self.getquickstats()

        request.user.message_set.create(message=unicode(_('Updated project "%s" from version control', self.fullname)))
        request.user.message_set.create(message=stats_message("working copy", old_stats))
        request.user.message_set.create(message=stats_message("remote copy", remote_stats))
        request.user.message_set.create(message=stats_message("merged copy", new_stats))

        post_vc_update.send(sender=self, oldstats=old_stats, remotestats=remote_stats, newstats=new_stats)
Exemplo n.º 5
0
    def _calc_wordcount_stats(self):
        result = self._get_wordcount_stats()
        self.initialize_children()
        for item in self.children:
            result = dictsum(result,
                             item.get_cached(CachedMethods.WORDCOUNT_STATS))

        return result
Exemplo n.º 6
0
def statssum(queryset, empty_stats=empty_quickstats):
    totals = empty_stats
    for item in queryset:
        try:
            totals = dictsum(totals, item.getquickstats())
        except:
            totals['errors'] += 1
    return totals
Exemplo n.º 7
0
def statssum(queryset, empty_stats=empty_quickstats):
    totals = empty_stats
    for item in queryset:
        try:
            totals = dictsum(totals, item.getquickstats())
        except:
            totals['errors'] += 1
    return totals
Exemplo n.º 8
0
    def get_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_res = item.get_checks()
            result['checks'] = dictsum(result['checks'], item_res['checks'])
            result['unit_count'] += item_res['unit_count']

        return result
Exemplo n.º 9
0
    def _calc_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_res = item.get_cached(CachedMethods.CHECKS)
            result['checks'] = dictsum(result['checks'], item_res['checks'])
            result['unit_critical_error_count'] += item_res['unit_critical_error_count']

        return result
Exemplo n.º 10
0
    def get_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_res = item.get_checks()
            result["checks"] = dictsum(result["checks"], item_res["checks"])
            result["unit_count"] += item_res["unit_count"]

        return result
Exemplo n.º 11
0
    def get_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_res = item.get_checks()
            result['checks'] = dictsum(result['checks'], item_res['checks'])
            result['unit_count'] += item_res['unit_count']

        return result
Exemplo n.º 12
0
    def get_checks(self, only_critical=False):
        result = self._get_checks(only_critical=only_critical)
        self.initialize_children()
        for item in self.children:
            item_res = item.get_checks(only_critical=only_critical)
            result['checks'] = dictsum(result['checks'], item_res['checks'])
            result['unit_count'] += item_res['unit_count']

        return result
Exemplo n.º 13
0
    def _calc_wordcount_stats(self):
        result = self._get_wordcount_stats()
        self.initialize_children()
        for item in self.children:
            if getattr(item, "disabled", False):
                continue
            result = dictsum(result,
                             item.get_cached(CachedMethods.WORDCOUNT_STATS))

        return result
Exemplo n.º 14
0
    def get_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_checks = item.get_checks()
            for cat in set(item_checks) | set(result):
                result[cat] = dictsum(result.get(cat, {}),
                                      item_checks.get(cat, {}))

        return result
Exemplo n.º 15
0
    def get_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            item_checks = item.get_checks()
            for cat in set(item_checks) | set(result):
                result[cat] = dictsum(result.get(cat, {}),
                                      item_checks.get(cat, {}))

        return result
Exemplo n.º 16
0
 def getquickstats(self):
     """calculate aggregate stats for all directory based on stats
     of all descenging stores and dirs"""
     if self.is_template_project:
         #FIXME: Hackish return empty_stats to avoid messing up
         # with project and language stats
         return empty_quickstats
     #FIXME: can we replace this with a quicker path query?
     file_result = statssum(self.child_stores.iterator())
     dir_result  = statssum(self.child_dirs.iterator())
     stats = dictsum(file_result, dir_result)
     return stats
Exemplo n.º 17
0
    def _calc_checks(self):
        result = self._get_checks()
        self.initialize_children()
        for item in self.children:
            if getattr(item, "disabled", False):
                continue
            item_res = item.get_cached(CachedMethods.CHECKS)
            result["checks"] = dictsum(result["checks"], item_res["checks"])
            result["unit_critical_error_count"] += item_res[
                "unit_critical_error_count"]

        return result
Exemplo n.º 18
0
def completestatssum(queryset, empty_stats=empty_completestats):
    totals = copy.deepcopy(empty_stats)

    for item in queryset:
        try:
            item_totals = item.getcompletestats()

            for cat in set(item_totals) | set(totals):
                totals[cat] = dictsum(totals.get(cat, {}),
                                      item_totals.get(cat, {}))
        except:
            totals[0]['errors'] += 1
    return totals
Exemplo n.º 19
0
    def getcompletestats(self):
        if self.is_template_project:
            return empty_completestats

        file_result = completestatssum(self.child_stores.iterator())
        dir_result = completestatssum(self.child_dirs.iterator())

        stats = {}
        for cat in set(file_result)|set(dir_result):
            stats[cat] = dictsum(file_result.get(cat, {}),
                                 dir_result.get(cat, {}))

        return stats
Exemplo n.º 20
0
def completestatssum(queryset, empty_stats=empty_completestats):
    totals = copy.deepcopy(empty_stats)

    for item in queryset:
        try:
            item_totals = item.getcompletestats()

            for cat in set(item_totals) | set(totals):
                totals[cat] = dictsum(totals.get(cat, {}),
                                      item_totals.get(cat, {}))
        except:
            totals[0]['errors'] += 1
    return totals
Exemplo n.º 21
0
    def update_project(self, request):
        """updates project translation files from version control,
        retaining uncommitted translations"""

        if not check_permission("commit", request):
            raise PermissionDenied(
                _("You do not have rights to update from version control here")
            )

        old_stats = self.getquickstats()
        remote_stats = {}

        for store in self.stores.exclude(file="").iterator():
            try:
                oldstats, remotestats, newstats = self.update_file_from_version_control(
                    store)
                remote_stats = dictsum(remote_stats, remotestats)
            except VersionControlError:
                pass

        self.scan_files()
        new_stats = self.getquickstats()

        request.user.message_set.create(message=unicode(
            _('Updated project "%s" from version control', self.fullname)))
        request.user.message_set.create(
            message=stats_message("working copy", old_stats))
        request.user.message_set.create(
            message=stats_message("remote copy", remote_stats))
        request.user.message_set.create(
            message=stats_message("merged copy", new_stats))

        from pootle_app.models.signals import post_vc_update
        post_vc_update.send(sender=self,
                            oldstats=old_stats,
                            remotestats=remote_stats,
                            newstats=new_stats)
Exemplo n.º 22
0
        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        if directory.is_translationproject():
            stores = self.stores.exclude(file="")
        else:
            stores = directory.stores.exclude(file="")

        for store in stores.iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            filetoupdate = store.file.name
            try:
                filetoupdate = hooks.hook(self.project.code, "preupdate",
                                          store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            versioncontrol.copy_to_podir(filetoupdate)
            store.file._delete_store_cache()
Exemplo n.º 23
0
        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        if directory.is_translationproject():
            stores = self.stores.exclude(file="")
        else:
            stores = directory.stores.exclude(file="")

        for store in stores.iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            try:
                hooks.hook(self.project.code, "preupdate", store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            versioncontrol.copy_to_podir(store.file.name)
            store.file._delete_store_cache()
            store.file._update_store_cache()
Exemplo n.º 24
0
    def update_dir(self, request=None, directory=None):
        """Updates translation project's files from version control, retaining
        uncommitted translations.
        """
        old_stats = self.getquickstats()
        remote_stats = {}

        from pootle_misc import versioncontrol
        try:
            versioncontrol.update_dir(self.real_path)
        except IOError as e:
            logging.error(u"Error during update of %(path)s:\n%(error)s", {
                "path": self.real_path,
                "error": e,
            })
            if request:
                msg = _("Failed to update from version control: %(error)s",
                        {"error": e})
                messages.error(request, msg)
            return

        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        if directory.is_translationproject():
            stores = self.stores.exclude(file="")
        else:
            stores = directory.stores.exclude(file="")

        for store in stores.iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            filetoupdate = store.file.name
            try:
                filetoupdate = hooks.hook(self.project.code, "preupdate",
                                          store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            versioncontrol.copy_to_podir(filetoupdate)
            store.file._delete_store_cache()
            store.file._update_store_cache()

            try:
                hooks.hook(self.project.code, "postupdate", store.file.name)
            except:
                pass

            try:
                logging.debug(u"Parsing version control copy of %s into db",
                              store.file.name)
                store.update(update_structure=True, update_translation=True)
                remotestats = store.getquickstats()

                #FIXME: Try to avoid merging if file was not updated
                logging.debug(u"Merging %s with version control update",
                              store.file.name)
                store.mergefile(working_copy,
                                None,
                                allownewstrings=False,
                                suggestions=True,
                                notranslate=False,
                                obsoletemissing=False)
            except Exception as e:
                logging.error(
                    u"Near fatal catastrophe, exception %s while "
                    "merging %s with version control copy", e, store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True)
                raise

            remote_stats = dictsum(remote_stats, remotestats)

        new_stats = self.getquickstats()

        if request:
            msg = [
                _(u'Updated project <em>%(project)s</em> from version control',
                  {'project': self.fullname}),
                stats_message(_(u"Working copy"), old_stats),
                stats_message(_(u"Remote copy"), remote_stats),
                stats_message(_(u"Merged copy"), new_stats)
            ]
            msg = u"<br/>".join([force_unicode(m) for m in msg])
            messages.info(request, msg)

        from pootle_app.models.signals import post_vc_update
        post_vc_update.send(sender=self,
                            oldstats=old_stats,
                            remotestats=remote_stats,
                            newstats=new_stats)
Exemplo n.º 25
0
    def update_dir(self, request=None, directory=None):
        """Updates translation project's files from version control, retaining
        uncommitted translations.
        """
        old_stats = self.getquickstats()
        remote_stats = {}

        from pootle_misc import versioncontrol
        try:
            versioncontrol.update_dir(self.real_path)
        except IOError as e:
            logging.error(u"Error during update of %(path)s:\n%(error)s",
                    {
                     "path": self.real_path,
                     "error": e,
                    }
            )
            if request:
                msg = _("Failed to update from version control: %(error)s",
                        {"error": e})
                messages.error(request, msg)
            return

        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        if directory.is_translationproject():
            stores = self.stores.exclude(file="")
        else:
            stores = directory.stores.exclude(file="")

        for store in stores.iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            filetoupdate = store.file.name
            try:
                filetoupdate = hooks.hook(self.project.code, "preupdate",
                                          store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            versioncontrol.copy_to_podir(filetoupdate)
            store.file._delete_store_cache()
            store.file._update_store_cache()

            try:
                hooks.hook(self.project.code, "postupdate",
                           store.file.name)
            except:
                pass

            try:
                logging.debug(u"Parsing version control copy of %s into db",
                              store.file.name)
                store.update(update_structure=True, update_translation=True)
                remotestats = store.getquickstats()

                #FIXME: Try to avoid merging if file was not updated
                logging.debug(u"Merging %s with version control update",
                              store.file.name)
                store.mergefile(working_copy, None, allownewstrings=False,
                                suggestions=True, notranslate=False,
                                obsoletemissing=False)
            except Exception as e:
                logging.error(u"Near fatal catastrophe, exception %s while "
                              "merging %s with version control copy",
                              e, store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True)
                raise

            remote_stats = dictsum(remote_stats, remotestats)

        new_stats = self.getquickstats()

        if request:
            msg = [
                _(u'Updated project <em>%(project)s</em> from version control',
                  {'project': self.fullname}),
                stats_message(_(u"Working copy"), old_stats),
                stats_message(_(u"Remote copy"), remote_stats),
                stats_message(_(u"Merged copy"), new_stats)
            ]
            msg = u"<br/>".join([force_unicode(m) for m in msg])
            messages.info(request, msg)

        from pootle_app.models.signals import post_vc_update
        post_vc_update.send(sender=self, oldstats=old_stats,
                remotestats=remote_stats, newstats=new_stats)
Exemplo n.º 26
0
    def update_project(self, request):
        """Updates project translation files from version control,
        retaining uncommitted translations"""

        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to update from "\
                    "version control here"))

        old_stats = self.getquickstats()
        remote_stats = {}

        from pootle_misc import versioncontrol
        versioncontrol.update_dir(self.real_path)
        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        for store in self.stores.exclude(file="").iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            try:
                hooks.hook(self.project.code, "preupdate", store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            store.file._delete_store_cache()
            store.file._update_store_cache()

            try:
                logging.debug(u"Parsing version control copy of %s into db",
                              store.file.name)
                store.update(update_structure=True, update_translation=True, \
                        conservative=False)
                remotestats = store.getquickstats()

                #FIXME: Try to avoid merging if file was not updated
                logging.debug(u"Merging %s with version control update",
                              store.file.name)
                store.mergefile(working_copy,
                                None,
                                allownewstrings=False,
                                suggestions=True,
                                notranslate=False,
                                obsoletemissing=False)
            except Exception, e:
                logging.error(
                    u"Near fatal catastrophe, exception %s while "
                    "merging %s with version control copy", e, store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True, \
                        conservative=False)
                raise
            try:
                hooks.hook(self.project.code, "postupdate", store.file.name)
            except:
                pass

            remote_stats = dictsum(remote_stats, remotestats)
Exemplo n.º 27
0
    def update_project(self, request):
        """Updates project translation files from version control,
        retaining uncommitted translations"""

        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to update from "\
                    "version control here"))

        old_stats = self.getquickstats()
        remote_stats = {}

        from pootle_misc import versioncontrol
        versioncontrol.update_dir(self.real_path)
        all_files, new_files = self.scan_files()
        new_file_set = set(new_files)

        from pootle.scripts import hooks

        # Go through all stores except any pootle-terminology.* ones
        for store in self.stores.exclude(file="").iterator():
            if store in new_file_set:
                # these won't have to be merged, since they are new
                remotestats = store.getquickstats()
                remote_stats = dictsum(remote_stats, remotestats)
                continue

            store.sync(update_translation=True)
            try:
                hooks.hook(self.project.code, "preupdate", store.file.name)
            except:
                pass

            # keep a copy of working files in memory before updating
            working_copy = store.file.store

            store.file._delete_store_cache()
            store.file._update_store_cache()

            try:
                logging.debug(u"Parsing version control copy of %s into db",
                              store.file.name)
                store.update(update_structure=True, update_translation=True, \
                        conservative=False)
                remotestats = store.getquickstats()

                #FIXME: Try to avoid merging if file was not updated
                logging.debug(u"Merging %s with version control update",
                              store.file.name)
                store.mergefile(working_copy, None, allownewstrings=False,
                                suggestions=True, notranslate=False,
                                obsoletemissing=False)
            except Exception, e:
                logging.error(u"Near fatal catastrophe, exception %s while "
                              "merging %s with version control copy",
                              e, store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True, \
                        conservative=False)
                raise
            try:
                hooks.hook(self.project.code, "postupdate", store.file.name)
            except:
                pass

            remote_stats = dictsum(remote_stats, remotestats)