コード例 #1
0
ファイル: models.py プロジェクト: DronRathore/pootle
    def commit_dir(self, user, directory, request=None):
        """Commits files under a directory to version control.

        This does not do permission checking.
        """
        self.sync()
        stats = self.getquickstats()
        author = user.username

        message = stats_message_raw("Commit from %s by user %s." %
                                    (settings.TITLE, author), stats)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        if directory.is_translationproject():
            stores = list(self.stores.exclude(file=""))
        else:
            stores = list(directory.stores.exclude(file=""))

        filestocommit = []

        from pootle.scripts import hooks
        for store in stores:
            try:
                filestocommit.extend(hooks.hook(self.project.code, "precommit",
                                                store.file.name, author=author,
                                                message=message)
                                    )
            except ImportError:
                # Failed to import the hook - we're going to assume there just
                # isn't a hook to import. That means we'll commit the original
                # file.
                filestocommit.append(store.file.name)

        success = True
        try:
            from pootle_misc import versioncontrol
            project_path = self.project.get_real_path()
            versioncontrol.add_files(project_path, filestocommit, message,
                                     author)
            if request is not None:
                msg = _("Committed all files under <em>%(path)s</em> to "
                        "version control", {'path': directory.pootle_path})
                messages.success(request, msg)
        except Exception, e:
            logging.error(u"Failed to commit: %s", e)

            if request is not None:
                msg = _("Failed to commit to version control: %(error)s",
                        {'error': e})
                messages.error(request, msg)

            success = False
コード例 #2
0
    def update_from_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
            .get_template_translationproject()

        if (template_translation_project is None
                or template_translation_project == self):
            return

        monolingual = self.project.is_monolingual()

        if not monolingual:
            self.sync()

        if pootle_path is None:
            oldstats = self.getquickstats()

        from pootle_app.project_tree import convert_template, \
            get_translated_name, get_translated_name_gnu

        for store in template_translation_project.stores.iterator():
            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(
                    self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

            if pootle_path is not None and new_pootle_path != pootle_path:
                continue

            convert_template(self, store, new_pootle_path, new_path,
                             monolingual)

        all_files, new_files = self.scan_files()
        #self.update(conservative=False)

        from pootle_misc import versioncontrol
        project_path = self.project.get_real_path()

        if new_files and versioncontrol.hasversioning(project_path):
            output = versioncontrol.add_files(project_path, \
                    [s.file.name for s in new_files],
                    "New files added from %s based on templates" % \
                            (settings.TITLE))

        if pootle_path is None:
            newstats = self.getquickstats()

            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self,
                                      oldstats=oldstats,
                                      newstats=newstats)
コード例 #3
0
ファイル: models.py プロジェクト: avivian/pootle
    def update_against_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
                                           .get_template_translationproject()

        if (template_translation_project is None or
            template_translation_project == self):
            return

        monolingual = self.project.is_monolingual()

        if not monolingual:
            self.sync()

        if pootle_path is None:
            oldstats = self.getquickstats()

        from pootle_app.project_tree import (convert_template,
                                             get_translated_name,
                                             get_translated_name_gnu)

        for store in template_translation_project.stores.iterator():
            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

            if pootle_path is not None and new_pootle_path != pootle_path:
                continue

            convert_template(self, store, new_pootle_path, new_path,
                             monolingual)

        all_files, new_files = self.scan_files(vcs_sync=False)
        #self.update(conservative=False)

        from pootle_misc import versioncontrol
        project_path = self.project.get_real_path()

        if new_files and versioncontrol.hasversioning(project_path):
            output = versioncontrol.add_files(project_path,
                    [s.file.name for s in new_files],
                    "New files added from %s based on templates" %
                            (settings.TITLE))

        if pootle_path is None:
            newstats = self.getquickstats()

            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self, oldstats=oldstats,
                                      newstats=newstats)
コード例 #4
0
ファイル: models.py プロジェクト: JMassapina/pootle
    def commit_dir(self, user, directory, request=None):
        """Commits files under a directory to version control.

        This does not do permission checking.
        """
        self.sync()
        total = directory.get_total_wordcount()
        translated = directory.get_translated_wordcount()
        fuzzy = directory.get_fuzzy_wordcount()
        author = user.username

        siteconfig = load_site_config()
        message = stats_message_raw("Commit from %s by user %s." %
                                    (siteconfig.get('TITLE'), author),
                                    total, translated, fuzzy)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        if directory.is_translationproject():
            stores = list(self.stores.exclude(file=""))
        else:
            stores = list(directory.stores.exclude(file=""))

        filestocommit = []

        from pootle.scripts import hooks
        for store in stores:
            try:
                filestocommit.extend(hooks.hook(self.project.code, "precommit",
                                                store.file.name, author=author,
                                                message=message)
                                    )
            except ImportError:
                # Failed to import the hook - we're going to assume there just
                # isn't a hook to import. That means we'll commit the original
                # file.
                filestocommit.append(store.file.name)

        success = True
        try:
            from pootle_misc import versioncontrol
            project_path = self.project.get_real_path()
            versioncontrol.add_files(project_path, filestocommit, message,
                                     author)
            # FIXME: This belongs to views
            if request is not None:
                msg = _("Committed all files under <em>%(path)s</em> to "
                        "version control", {'path': directory.pootle_path})
                messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit directory")

            # FIXME: This belongs to views
            if request is not None:
                msg = _("Failed to commit to version control: %(error)s",
                        {'error': e})
                messages.error(request, msg)

            success = False

        for store in stores:
            try:
                hooks.hook(self.project.code, "postcommit", store.file.name,
                           success=success)
            except:
                #FIXME: We should not hide the exception - makes development
                # impossible
                pass

        from pootle_app.models.signals import post_vc_commit
        post_vc_commit.send(sender=self, path_obj=directory,
                            user=user, success=success)

        return success
コード例 #5
0
ファイル: models.py プロジェクト: JMassapina/pootle
    def update_against_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
                                           .get_template_translationproject()

        if (template_translation_project is None or
            template_translation_project == self):
            return

        monolingual = self.project.is_monolingual

        if not monolingual:
            self.sync()

        from pootle_app.project_tree import (convert_template,
                                             get_translated_name,
                                             get_translated_name_gnu)

        for store in template_translation_project.stores.iterator():
            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

            if pootle_path is not None and new_pootle_path != pootle_path:
                continue

            try:
                from pootle.scripts import hooks
                relative_po_path = os.path.relpath(new_path,
                                                   settings.PODIRECTORY)
                if not hooks.hook(self.project.code, "pretemplateupdate",
                                  relative_po_path):
                    continue
            except:
                # Assume hook is not present.
                pass

            convert_template(self, store, new_pootle_path, new_path,
                             monolingual)

        all_files, new_files = self.scan_files(vcs_sync=False)

        from pootle_misc import versioncontrol
        project_path = self.project.get_real_path()

        if new_files and versioncontrol.hasversioning(project_path):
            from pootle.scripts import hooks
            siteconfig = load_site_config()
            message = ("New files added from %s based on templates" %
                       siteconfig.get('TITLE'))

            filestocommit = []
            for new_file in new_files:
                try:
                    hook_files = hooks.hook(self.project.code, "precommit",
                                            new_file.file.name, author=None,
                                            message=message)
                    filestocommit.extend(hook_files)
                except ImportError:
                    # Failed to import the hook - we're going to assume there
                    # just isn't a hook to import. That means we'll commit the
                    # original file.
                    filestocommit.append(new_file.file.name)

            success = True
            try:
                output = versioncontrol.add_files(project_path, filestocommit,
                                                  message)
            except Exception:
                logging.exception(u"Failed to add files")
                success = False

            for new_file in new_files:
                try:
                    hooks.hook(self.project.code, "postcommit",
                               new_file.file.name, success=success)
                except:
                    #FIXME: We should not hide the exception - makes
                    # development impossible
                    pass

        if pootle_path is None:
            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self)
コード例 #6
0
    def commit_dir(self, user, directory, request=None):
        """Commits files under a directory to version control.

        This does not do permission checking.
        """
        self.sync()
        stats = self.getquickstats()
        author = user.username

        message = stats_message_raw("Commit from %s by user %s." % \
                (settings.TITLE, author), stats)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        if directory.is_translationproject():
            stores = list(self.stores.exclude(file=""))
        else:
            stores = list(directory.stores.exclude(file=""))

        filestocommit = []

        from pootle.scripts import hooks
        for store in stores:
            try:
                filestocommit.extend(
                    hooks.hook(self.project.code,
                               "precommit",
                               store.file.name,
                               author=author,
                               message=message))
            except ImportError:
                # Failed to import the hook - we're going to assume there just
                # isn't a hook to import. That means we'll commit the original
                # file.
                filestocommit.append(store.file.name)

        success = True
        try:
            from pootle_misc import versioncontrol
            project_path = self.project.get_real_path()
            versioncontrol.add_files(
                project_path,
                filestocommit,
                message,
                author,
            )
            if request is not None:
                msg = _(
                    "Committed all files under <em>%(path)s</em> to "
                    "version control", {'path': directory.pootle_path})
                messages.success(request, msg)
        except Exception, e:
            logging.error(u"Failed to commit: %s", e)

            if request is not None:
                msg = _("Failed to commit to version control: %(error)s",
                        {'error': e})
                messages.error(request, msg)

            success = False
コード例 #7
0
    def update_against_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
                                           .get_template_translationproject()

        if (template_translation_project is None
                or template_translation_project == self):
            return

        monolingual = self.project.is_monolingual()

        if not monolingual:
            self.sync()

        if pootle_path is None:
            oldstats = self.getquickstats()

        from pootle_app.project_tree import (convert_template,
                                             get_translated_name,
                                             get_translated_name_gnu)

        for store in template_translation_project.stores.iterator():
            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(
                    self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

            if pootle_path is not None and new_pootle_path != pootle_path:
                continue

            relative_po_path = os.path.relpath(new_path, settings.PODIRECTORY)
            try:
                from pootle.scripts import hooks
                if not hooks.hook(self.project.code, "pretemplateupdate",
                                  relative_po_path):
                    continue
            except:
                # Assume hook is not present.
                pass

            convert_template(self, store, new_pootle_path, new_path,
                             monolingual)

        all_files, new_files = self.scan_files(vcs_sync=False)

        from pootle_misc import versioncontrol
        project_path = self.project.get_real_path()

        if new_files and versioncontrol.hasversioning(project_path):
            from pootle.scripts import hooks
            message = "New files added from %s based on templates" % \
                      (settings.TITLE)

            filestocommit = []
            for new_file in new_files:
                try:
                    filestocommit.extend(
                        hooks.hook(self.project.code,
                                   "precommit",
                                   new_file.file.name,
                                   author=None,
                                   message=message))
                except ImportError:
                    # Failed to import the hook - we're going to assume there
                    # just isn't a hook to import. That means we'll commit the
                    # original file.
                    filestocommit.append(new_file.file.name)

            success = True
            try:
                output = versioncontrol.add_files(project_path, filestocommit,
                                                  message)
            except Exception, e:
                logging.error(u"Failed to add files: %s", e)
                success = False

            for new_file in new_files:
                try:
                    hooks.hook(self.project.code,
                               "postcommit",
                               new_file.file.name,
                               success=success)
                except:
                    #FIXME: We should not hide the exception - makes
                    # development impossible
                    pass
コード例 #8
0
ファイル: models.py プロジェクト: JeroenKnoops/pootle
    def commit_dir(self, user, directory, request=None):
        """Commits files under a directory to version control.

        This does not do permission checking.
        """
        self.sync()
        total = directory.get_total_wordcount()
        translated = directory.get_translated_wordcount()
        fuzzy = directory.get_fuzzy_wordcount()
        author = user.username

        message = stats_message_raw(
            "Commit from %s by user %s." % (get_site_title(), author), total,
            translated, fuzzy)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        if directory.is_translationproject():
            stores = list(self.stores.exclude(file=""))
        else:
            stores = list(directory.stores.exclude(file=""))

        filestocommit = []

        from pootle.scripts import hooks
        for store in stores:
            try:
                filestocommit.extend(
                    hooks.hook(self.project.code,
                               "precommit",
                               store.file.name,
                               author=author,
                               message=message))
            except ImportError:
                # Failed to import the hook - we're going to assume there just
                # isn't a hook to import. That means we'll commit the original
                # file.
                filestocommit.append(store.file.name)

        success = True
        try:
            from pootle_misc import versioncontrol
            project_path = self.project.get_real_path()
            versioncontrol.add_files(project_path, filestocommit, message,
                                     author)
            # FIXME: This belongs to views
            if request is not None:
                msg = _(
                    "Committed all files under <em>%(path)s</em> to "
                    "version control", {'path': directory.pootle_path})
                messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit directory")

            # FIXME: This belongs to views
            if request is not None:
                msg = _("Failed to commit to version control: %(error)s",
                        {'error': e})
                messages.error(request, msg)

            success = False

        for store in stores:
            try:
                hooks.hook(self.project.code,
                           "postcommit",
                           store.file.name,
                           success=success)
            except:
                #FIXME: We should not hide the exception - makes development
                # impossible
                pass

        from pootle_app.models.signals import post_vc_commit
        post_vc_commit.send(sender=self,
                            path_obj=directory,
                            user=user,
                            success=success)

        return success