Exemplo n.º 1
0
    def commit_changes(self, db_project, vcs_project, changeset):
        """Commit the changes we've made back to the VCS."""
        for locale in db_project.locales.all():
            authors = changeset.commit_authors_per_locale.get(locale.code, [])

            # Use the top translator for this batch as commit author, or
            # the fake Pontoon user if there are no authors.
            if len(authors) > 0:
                commit_author = Counter(authors).most_common(1)[0][0]
            else:
                commit_author = User(first_name="Pontoon",
                                     email="*****@*****.**")

            commit_message = render_to_string('commit_message.jinja', {
                'locale': locale,
                'project': db_project,
                'authors': authors
            })

            try:
                result = commit_to_vcs(
                    db_project.repository_type,
                    vcs_project.locale_directory_path(locale.code),
                    commit_message, commit_author, db_project.repository_url)
            except CommitToRepositoryException as err:
                result = {'message': unicode(err)}

            if result is not None:
                self.log(
                    u'Committing project {project.name} for {locale.name} '
                    u'({locale.code}) failed: {reason}',
                    project=db_project,
                    locale=locale,
                    reason=result['message'])
Exemplo n.º 2
0
    def commit_changes(self, db_project, vcs_project, changeset):
        """Commit the changes we've made back to the VCS."""
        for locale in db_project.locales.all():
            authors = changeset.commit_authors_per_locale.get(locale.code, [])

            # Use the top translator for this batch as commit author, or
            # the fake Pontoon user if there are no authors.
            if len(authors) > 0:
                commit_author = Counter(authors).most_common(1)[0][0]
            else:
                commit_author = User(first_name="Pontoon", email="*****@*****.**")

            commit_message = render_to_string(
                "commit_message.jinja", {"locale": locale, "project": db_project, "authors": authors}
            )

            try:
                result = commit_to_vcs(
                    db_project.repository_type,
                    vcs_project.locale_directory_path(locale.code),
                    commit_message,
                    commit_author,
                    db_project.repository_url,
                )
            except CommitToRepositoryException as err:
                result = {"message": unicode(err)}

            if result is not None:
                self.log(
                    u"Committing project {project.name} for {locale.name} " u"({locale.code}) failed: {reason}",
                    project=db_project,
                    locale=locale,
                    reason=result["message"],
                )
Exemplo n.º 3
0
    def handle(self, *args, **options):
        def output(text):
            now = datetime.datetime.now()
            self.stdout.write('[%s]: %s\n' % (now, text.encode('utf8')))

        output('COMMIT PROJECTS: start')

        projects = Project.objects.filter(disabled=False)
        if args:
            projects = projects.filter(pk__in=args)

        for project in projects:
            repo_type = project.repository_type

            if repo_type not in ('git', 'hg', 'svn'):
                output('Committing project %s failed: Not a VCS project' %
                       (project))
                continue

            for locale in project.locales.all():

                # Dump files from database
                path = dump_from_database(project, locale)
                if not path:
                    error = 'Repository path not found'
                    output('Committing project %s for %s (%s) failed: %s' %
                           (project, locale.name, locale.code, error))
                    continue

                message = 'Pontoon: Update %s (%s) localization of %s.' \
                    % (locale.name, locale.code, project.name)

                # Set latest translation author as commit author if available
                user = User.objects.filter(is_superuser=True)[0]
                translations = Translation.objects.exclude(user=None).filter(
                    locale=locale,
                    entity__obsolete=False,
                    entity__resource__project=project) \
                    .order_by('-date')
                if translations:
                    user = translations[0].user

                # Commit files to VCS
                try:
                    r = commit_to_vcs(repo_type, path, message, user)
                except Exception as e:
                    output('Committing project %s for %s (%s) failed: %s' %
                           (project, locale.name, locale.code, unicode(e)))
                    continue
                if r is not None:
                    output('Committing project %s for %s (%s) failed: %s' %
                           (project, locale.name, locale.code, r["message"]))
                    continue

                output('Commited project %s for %s (%s)' %
                       (project, locale.name, locale.code))

        output('COMMIT PROJECTS: done')
Exemplo n.º 4
0
    def commit(self, message, author, path):
        """Commit changes to VCS."""
        # For multi-locale repos, figure out which sub-repo corresponds
        # to the given path.
        url = self.url
        if self.multi_locale:
            url = self.url_for_path(path)

        return commit_to_vcs(self.type, path, message, author, url)
Exemplo n.º 5
0
    def commit(self, message, author, path):
        """Commit changes to VCS."""
        # For multi-locale repos, figure out which sub-repo corresponds
        # to the given path.
        url = self.url
        if self.multi_locale:
            url = self.url_for_path(path)

        return commit_to_vcs(self.type, path, message, author, url)
Exemplo n.º 6
0
    def commit_changes(self, db_project, changeset):
        """Commit the changes we've made back to the VCS."""
        if self.no_commit:
            return

        for locale in db_project.locales.all():
            authors = changeset.commit_authors_per_locale.get(locale.code, [])
            author_list = "\n".join("- " + author.display_name for author in set(authors))

            # Use the top translator for this batch as commit author, or
            # the first admin we can find if there are no authors.
            if len(authors) > 0:
                commit_author = Counter(authors).most_common(1)[0][0]
            else:
                commit_author = User.objects.filter(is_superuser=True).first()

            commit_message = (
                dedent(
                    """
                Pontoon: Updated {locale.name} ({locale.code}) localization of {project.name}

                Translation authors:
                {author_list}
            """
                )
                .strip()
                .format(locale=locale, project=db_project, author_list=author_list)
            )

            try:
                result = commit_to_vcs(
                    db_project.repository_type,
                    db_project.locale_directory_path(locale.code),
                    commit_message,
                    commit_author,
                    db_project.repository_url,
                )
            except CommitToRepositoryException as err:
                result = {"message": unicode(err)}

            if result is not None:
                self.log(
                    "Committing project {project.name} for {locale.name} " "({locale.code}) failed: {reason}",
                    project=db_project,
                    locale=locale,
                    reason=result["message"],
                )