Exemplo n.º 1
0
def updated_from_version_control(sender, oldstats, remotestats, newstats,
                                 **kwargs):
    if sender.is_template_project:
        # add template news to project instead of translation project
        directory = sender.project.directory
    else:
        directory = sender.directory

    if oldstats == newstats:
        # nothing changed, no need to report
        return

    args = {
        'url': sender.get_absolute_url(),
        'sender': sender.fullname,
    }
    message = ('Updated <a href="%(url)s">%(sender)s</a> from version control'
               '<br />' % args)
    message += stats_message_raw("Before update", oldstats) + " <br />"

    if not remotestats == newstats:
        message += stats_message_raw("Remote copy", remotestats) + " <br />"

    message += stats_message_raw("After update", newstats)
    new_object(True, message, directory)
Exemplo n.º 2
0
def file_uploaded(sender, oldstats, user, newstats, archive, **kwargs):
    if sender.is_template_project:
        # add template news to project instead of translation project
        directory = sender.project.directory
    else:
        directory = sender.directory

    if oldstats == newstats:
        logging.debug("file uploaded but stats didn't change")
        return

    args = {
        'user_url': get_profile(user).get_absolute_url(),
        'user': get_profile(user),
        'sender_url': sender.get_absolute_url(),
        'sender': sender.fullname,
    }
    if archive:
        message = ('<a href="%(user_url)s">%(user)s</a> uploaded an archive '
                   'to <a href="%(sender_url)s">%(sender)s</a> <br />' % args)
    else:
        message = ('<a href="%(user_url)s">%(user)s</a> uploaded a file to '
                   '<a href="%(sender_url)s">%(sender)s</a> <br />' % args)

    message += stats_message_raw('Before upload', oldstats) + ' <br />'
    message += stats_message_raw('After upload', newstats) + ' <br />'
    new_object(True, message, directory)
Exemplo n.º 3
0
def file_uploaded(sender, oldstats, user, newstats, archive, **kwargs):
    if sender.is_template_project:
        # Add template news to project instead of translation project.
        directory = sender.project.directory
    else:
        directory = sender.directory

    if oldstats == newstats:
        logging.debug("file uploaded but stats didn't change")
        return

    args = {
        'user_url': get_profile(user).get_absolute_url(),
        'user': get_profile(user),
        'sender_url': sender.get_absolute_url(),
        'sender': sender.fullname,
    }
    if archive:
        message = ('<a href="%(user_url)s">%(user)s</a> uploaded an archive '
                   'to <a href="%(sender_url)s">%(sender)s</a> <br />' % args)
    else:
        message = ('<a href="%(user_url)s">%(user)s</a> uploaded a file to '
                   '<a href="%(sender_url)s">%(sender)s</a> <br />' % args)

    old_total = oldstats["total"]
    new_total = newstats["total"]
    old_translated = oldstats["translated"]
    new_translated = newstats["translated"]
    old_fuzzy = oldstats["fuzzy"]
    new_fuzzy = newstats["fuzzy"]
    message += stats_message_raw('Before upload', old_total, old_translated,
                                 old_fuzzy) + ' <br />'
    message += stats_message_raw('After upload', new_total, new_translated,
                                 new_fuzzy) + ' <br />'
    new_object(True, message, directory)
Exemplo n.º 4
0
def updated_from_template(sender, oldstats, newstats, **kwargs):
    if oldstats == newstats:
        # nothing changed, no need to report
        return

    message = 'Updated <a href="%s">%s</a> to latest template <br />' % (
        sender.get_absolute_url(), sender.fullname)
    message += stats_message_raw("Before update", oldstats) + " <br />"
    message += stats_message_raw("After update", newstats) + " <br />"
    new_object(True, message, sender.directory)
Exemplo n.º 5
0
def updated_from_template(sender, oldstats, newstats, **kwargs):
    if oldstats == newstats:
        # nothing changed, no need to report
        return

    message = 'Updated <a href="%s">%s</a> to latest template <br />' % (
        sender.get_absolute_url(), sender.fullname)
    message += stats_message_raw("Before update", oldstats) + " <br />"
    message += stats_message_raw("After update", newstats) + " <br />"
    new_object(True, message, sender.directory)
Exemplo n.º 6
0
def updated_against_template(sender, oldstats, newstats, **kwargs):
    if oldstats == newstats:
        # nothing changed, no need to report
        return

    args = {
        'url': sender.get_absolute_url(),
        'sender': sender.fullname,
    }
    message = ('Updated <a href="%(url)s">%(sender)s</a> to latest template'
               '<br />' % args)
    message += stats_message_raw("Before update", oldstats) + " <br />"
    message += stats_message_raw("After update", newstats) + " <br />"
    new_object(True, message, sender.directory)
Exemplo n.º 7
0
def unit_updated(sender, instance, raw=False, **kwargs):
    if raw:
        return

    if instance.id is not None and instance.istranslated():
        dbcopy = Unit.objects.get(id=instance.id)
        if dbcopy.istranslated():
            # unit state didn't change, let's quit
            return

        store = instance.store
        stats = store.getquickstats()

        if stats['total'] - stats['translated'] == 1:
            # by the end of this we will be 100%
            translation_project = store.translation_project
            directory = translation_project.directory
            args = {
                'url': store.get_absolute_url(),
                'store': store.name,
            }
            message = ('<a href="%(url)s">%(store)s</a> fully translated</a>'
                       '<br />' % args)
            quickstats = translation_project.getquickstats()
            quickstats['translated'] += 1

            if dbcopy.isfuzzy():
                quickstats['fuzzy'] -= 1

            message += stats_message_raw("Project now at", quickstats)
            new_object(True, message, directory)
Exemplo n.º 8
0
def unit_updated(sender, instance, raw=False, **kwargs):
    if raw:
        return

    if instance.id is not None and instance.istranslated():
        dbcopy = Unit.objects.get(id=instance.id)
        if dbcopy.istranslated():
            # unit state didn't change, let's quit
            return

        store = instance.store
        stats = store.getquickstats()

        if stats['total'] - stats['translated'] == 1:
            # by the end of this we will be 100%
            translation_project = store.translation_project
            directory = translation_project.directory
            message = '<a href="%s">%s</a> fully translated</a> <br />' % (
                store.get_absolute_url(), store.name)
            quickstats = translation_project.getquickstats()
            quickstats['translated'] += 1

            if dbcopy.isfuzzy():
                quickstats['fuzzy'] -= 1

            message += stats_message_raw("Project now at", quickstats)
            new_object(True, message, directory)
Exemplo n.º 9
0
def unit_updated(sender, instance, raw=False, **kwargs):
    if raw:
        return

    if instance.id is not None and instance.istranslated():
        dbcopy = Unit.objects.get(id=instance.id)
        if dbcopy.istranslated():
            # Unit state didn't change, let's quit.
            return

        store = instance.store
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.get_fuzzy_wordcount()

        if total - translated == 1:
            # By the end of this we will be 100%.
            translation_project = store.translation_project
            directory = translation_project.directory
            args = {
                'url': store.get_absolute_url(),
                'store': store.name,
            }
            message = ('<a href="%(url)s">%(store)s</a> fully translated</a>'
                       '<br />' % args)
            tp_total = translation_project.get_total_wordcount()
            tp_translated = translation_project.get_translated_wordcount() + 1

            if dbcopy.isfuzzy():
                tp_fuzzy = translation_project.get_fuzzy_wordcount() - 1

            message += stats_message_raw("Project now at", tp_total,
                                         tp_translated, tp_fuzzy)
            new_object(True, message, directory)
Exemplo n.º 10
0
def committed_to_version_control(sender, store, stats, user, success,
                                 **kwargs):
    message = '<a href="%s">%s</a> committed <a href="%s">%s</a> to version control' % (
        user.get_absolute_url(), get_profile(user), store.get_absolute_url(),
        store.pootle_path)
    message = stats_message_raw(message, stats)
    new_object(success, message, sender.directory)
Exemplo n.º 11
0
def unit_updated(sender, instance, raw=False, **kwargs):
    if raw:
        return

    if instance.id is not None and instance.istranslated():
        dbcopy = Unit.objects.get(id=instance.id)
        if dbcopy.istranslated():
            # Unit state didn't change, let's quit.
            return

        store = instance.store
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.get_fuzzy_wordcount()

        if total - translated == 1:
            # By the end of this we will be 100%.
            translation_project = store.translation_project
            directory = translation_project.directory
            args = {
                'url': store.get_absolute_url(),
                'store': store.name,
            }
            message = ('<a href="%(url)s">%(store)s</a> fully translated</a>'
                       '<br />' % args)
            tp_total = translation_project.get_total_wordcount()
            tp_translated = translation_project.get_translated_wordcount() + 1

            if dbcopy.isfuzzy():
                tp_fuzzy = translation_project.get_fuzzy_wordcount() - 1

            message += stats_message_raw("Project now at", tp_total,
                                         tp_translated, tp_fuzzy)
            new_object(True, message, directory)
Exemplo n.º 12
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        store.sync(update_structure=False,
                   update_translation=True,
                   conservative=True)
        stats = store.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

        from pootle.scripts import hooks
        try:
            filestocommit = 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 = [store.file.name]

        success = True
        try:
            from pootle_misc import versioncontrol
            for file in filestocommit:
                versioncontrol.commit_file(file,
                                           message=message,
                                           author=author)

                if request is not None:
                    msg = _(
                        "Committed file <em>%(filename)s</em> to version "
                        "control", {'filename': file})
                    messages.success(request, msg)
        except Exception, e:
            logging.error(u"Failed to commit file: %s", e)

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

            success = False
Exemplo n.º 13
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
Exemplo n.º 14
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        store.sync(update_structure=False, update_translation=True,
                   conservative=True)
        stats = store.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

        from pootle.scripts import hooks
        try:
            filestocommit = 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 = [store.file.name]

        success = True
        try:
            from pootle_misc import versioncontrol
            for file in filestocommit:
                versioncontrol.commit_file(file, message=message, author=author)

                if request is not None:
                    msg = _("Committed file <em>%(filename)s</em> to version "
                            "control",
                            {'filename': file})
                    messages.success(request, msg)
        except Exception, e:
            logging.error(u"Failed to commit file: %s", e)

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

            success = False
Exemplo n.º 15
0
def updated_from_version_control(sender, oldstats, remotestats, newstats,
                                 **kwargs):
    if sender.is_template_project:
        # add template news to project instead of translation project
        directory = sender.project.directory
    else:
        directory = sender.directory

    if oldstats == newstats:
        # nothing changed, no need to report
        return

    message = 'Updated <a href="%s">%s</a> from version control <br />' % (
        sender.get_absolute_url(), sender.fullname)
    message += stats_message_raw("Before update", oldstats) + " <br />"

    if not remotestats == newstats:
        message += stats_message_raw("Remote copy", remotestats) + " <br />"

    message += stats_message_raw("After update", newstats)
    new_object(True, message, directory)
Exemplo n.º 16
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        from pootle_app.signals import post_vc_commit

        store.sync(update_structure=False, update_translation=True,
                   conservative=True)
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.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

        filestocommit = [store.file.name]

        success = True
        for file in filestocommit:
            try:
                versioncontrol.commit_file(file, message=message,
                                           author=author)

                # FIXME: This belongs to views
                if request is not None:
                    msg = _("Committed file <em>%(filename)s</em> to version "
                            "control", {'filename': file})
                    messages.success(request, msg)
            except Exception as e:
                logging.exception(u"Failed to commit file")

                # FIXME: This belongs to views
                if request is not None:
                    msg_params = {
                        "filename": file,
                        "error": e,
                    }
                    msg = _("Failed to commit <em>%(filename)s</em> to version "
                            "control: %(error)s", msg_params)
                    messages.error(request, msg)
                success = False

        post_vc_commit.send(sender=self, path_obj=store,
                            user=user, success=success)

        return success
Exemplo n.º 17
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()
        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 = [store.file.name for store in stores]
        success = True
        try:
            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

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

        return success
Exemplo n.º 18
0
def committed_to_version_control(sender, path_obj, stats, user, success,
                                 **kwargs):
    args = {
        'user_url': user.get_absolute_url(),
        'user': get_profile(user),
        'path_obj_url': path_obj.get_absolute_url(),
        'path_obj': path_obj.pootle_path,
    }
    message = ('<a href="%(user_url)s">%(user)s</a> committed <a '
               'href="%(path_obj_url)s">%(path_obj)s</a> to version control' %
               args)
    message = stats_message_raw(message, stats)
    new_object(success, message, sender.directory)
Exemplo n.º 19
0
def file_uploaded(sender, oldstats, user, newstats, archive, **kwargs):
    if sender.is_template_project:
        # add template news to project instead of translation project
        directory = sender.project.directory
    else:
        directory = sender.directory

    if oldstats == newstats:
        logging.debug("file uploaded but stats didn't change")
        return

    if archive:
        message = '<a href="%s">%s</a> uploaded an archive to <a href="%s">%s</a> <br />' % (
            get_profile(user).get_absolute_url(), get_profile(user),
            sender.get_absolute_url(), sender.fullname)
    else:
        message = '<a href="%s">%s</a> uploaded a file to <a href="%s">%s</a> <br />' % (
            get_profile(user).get_absolute_url(), get_profile(user),
            sender.get_absolute_url(), sender.fullname)

    message += stats_message_raw('Before upload', oldstats) + ' <br />'
    message += stats_message_raw('After upload', newstats) + ' <br />'
    new_object(True, message, directory)
Exemplo n.º 20
0
def committed_to_version_control(sender, path_obj, user, success, **kwargs):
    args = {
        'user_url': user.get_absolute_url(),
        'user': user,
        'path_obj_url': path_obj.get_absolute_url(),
        'path_obj': path_obj.pootle_path,
    }
    message = ('<a href="%(user_url)s">%(user)s</a> committed <a '
               'href="%(path_obj_url)s">%(path_obj)s</a> to version control' %
               args)

    total = path_obj.get_total_wordcount()
    translated = path_obj.get_translated_wordcount()
    fuzzy = path_obj.get_fuzzy_wordcount()
    message = stats_message_raw(message, total, translated, fuzzy)
    new_object(success, message, sender.directory)
Exemplo n.º 21
0
def committed_to_version_control(sender, path_obj, user, success, **kwargs):
    args = {
        'user_url': user.get_absolute_url(),
        'user': get_profile(user),
        'path_obj_url': path_obj.get_absolute_url(),
        'path_obj': path_obj.pootle_path,
    }
    message = ('<a href="%(user_url)s">%(user)s</a> committed <a '
               'href="%(path_obj_url)s">%(path_obj)s</a> to version control' %
               args)

    total = path_obj.get_total_wordcount()
    translated = path_obj.get_translated_wordcount()
    fuzzy = path_obj.get_fuzzy_wordcount()
    message = stats_message_raw(message, total, translated, fuzzy)
    new_object(success, message, sender.directory)
Exemplo n.º 22
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        store.sync(update_structure=False, update_translation=True,
                   conservative=True)
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.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

        from pootle.scripts import hooks
        try:
            filestocommit = 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 = [store.file.name]

        success = True
        try:
            from pootle_misc import versioncontrol
            for file in filestocommit:
                versioncontrol.commit_file(file, message=message,
                                           author=author)

                # FIXME: This belongs to views
                if request is not None:
                    msg = _("Committed file <em>%(filename)s</em> to version "
                            "control", {'filename': file})
                    messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit file")

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

            success = False

        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=store,
                            user=user, success=success)

        return success
Exemplo n.º 23
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()
        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
Exemplo n.º 24
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
Exemplo n.º 25
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        store.sync(update_structure=False,
                   update_translation=True,
                   conservative=True)
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.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

        from pootle.scripts import hooks
        try:
            filestocommit = 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 = [store.file.name]

        success = True
        try:
            from pootle_misc import versioncontrol
            for file in filestocommit:
                versioncontrol.commit_file(file,
                                           message=message,
                                           author=author)

                # FIXME: This belongs to views
                if request is not None:
                    msg = _(
                        "Committed file <em>%(filename)s</em> to version "
                        "control", {'filename': file})
                    messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit file")

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

            success = False

        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=store,
                            user=user,
                            success=success)

        return success
Exemplo n.º 26
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()
        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
Exemplo n.º 27
0
def committed_to_version_control(sender, store, stats, user, success, **kwargs):
    message = '<a href="%s">%s</a> committed <a href="%s">%s</a> to version control' % (
        user.get_absolute_url(), get_profile(user),
        store.get_absolute_url(), store.pootle_path)
    message = stats_message_raw(message, stats)
    new_object(success, message, sender.directory)