Example #1
0
def update_from_repository(request, template=None):
    """Update all project locales from repository."""
    log.debug("Update all project locales from repository.")

    if not request.user.has_perm('base.can_manage'):
        return render(request, '403.html', status=403)

    if request.method != 'POST':
        log.error("Non-POST request")
        raise Http404

    try:
        pk = request.POST['pk']
    except MultiValueDictKeyError as e:
        log.error(str(e))
        return HttpResponse(json.dumps({
            'type':
            'error',
            'message':
            'Project primary key not provided.',
        }),
                            mimetype='application/json')

    try:
        project = Project.objects.get(pk=pk)
    except Project.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }),
                            mimetype='application/json')

    try:
        files.update_from_repository(project)
        files.extract_to_database(project)

    except Exception as e:
        log.error("Exception: " + str(e))
        log.debug(traceback.format_exc())
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }),
                            mimetype='application/json')

    except IOError as e:
        log.error("IOError: " + str(e))
        log.debug(traceback.format_exc())
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }),
                            mimetype='application/json')

    return HttpResponse("200")
Example #2
0
def update_from_repository(request, template=None):
    """Update all project locales from repository."""
    log.debug("Update all project locales from repository.")

    if not request.user.has_perm('base.can_manage'):
        return render(request, '403.html', status=403)

    if request.method != 'POST':
        log.error("Non-POST request")
        raise Http404

    try:
        pk = request.POST['pk']
    except MultiValueDictKeyError as e:
        log.error(str(e))
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': 'Project primary key not provided.',
        }), content_type='application/json')

    try:
        project = Project.objects.get(pk=pk)
    except Project.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }), content_type='application/json')

    try:
        files.update_from_repository(project)
        files.extract_to_database(project)

    except Exception as e:
        log.error("Exception: " + str(e))
        log.debug(traceback.format_exc())
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }), content_type='application/json')

    except IOError as e:
        log.error("IOError: " + str(e))
        log.debug(traceback.format_exc())
        return HttpResponse(json.dumps({
            'type': 'error',
            'message': str(e),
        }), content_type='application/json')

    return HttpResponse("200")
Example #3
0
    def handle(self, *args, **options):
        def output(text):
            self.stdout.write(text.encode('utf8') + u'\n')

        output('UPDATE PROJECTS: start')

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

        for project in projects:
            try:
                update_from_repository(project)
                extract_to_database(project)
                output('Updated project %s' % project)
            except Exception as e:
                raise CommandError(u'Update error: %s\n' % unicode(e))

        output('UPDATE PROJECTS: done')
Example #4
0
    def handle(self, *args, **options):
        def output(text):
            now = datetime.datetime.now()
            self.stdout.write('[%s]: %s\n' % (now, text.encode('utf8')))

        output('UPDATE PROJECTS: start')

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

        for project in projects:
            try:
                update_from_repository(project)
                extract_to_database(project)
                output('Updated project %s' % project)
            except Exception as e:
                now = datetime.datetime.now()
                raise CommandError(
                    '[%s]: Update error: %s\n' % (now, unicode(e)))

        output('UPDATE PROJECTS: done')
Example #5
0
    def handle(self, *args, **options):
        def output(text):
            self.stdout.write(text + u'\n')

        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

            # Update project from VCS to ensure the directory exists.
            try:
                update_from_repository(project)
                extract_to_database(project)
                output('Updated project %s' % project)
            except Exception as e:
                raise CommandError(u'Update error: %s\n' % unicode(e))

            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,
                                      project.repository_url)
                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')
Example #6
0
    def handle(self, *args, **options):
        def output(text):
            self.stdout.write(text + u'\n')

        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

            # Update project from VCS to ensure the directory exists.
            try:
                update_from_repository(project)
                extract_to_database(project)
                output('Updated project %s' % project)
            except Exception as e:
                raise CommandError(u'Update error: %s\n' % unicode(e))

            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, project.repository_url)
                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')