Esempio n. 1
0
    def update_file_from_version_control(self, store):
        from pootle.scripts import hooks
        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
        oldstats = store.getquickstats()
        working_copy = store.file.store

        try:
            logging.debug(u"Updating %s from version control", store.file.name)
            from pootle_misc import versioncontrol
            versioncontrol.update_file(store.file.name)
            store.file._delete_store_cache()
            store.file._update_store_cache()
        except Exception, e:
            # Something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.error(
                u"Near fatal catastrophe, exception %s while updating "
                "%s from version control", e, store.file.name)
            working_copy.save()

            raise VersionControlError
Esempio n. 2
0
 def initialize(self):
     try:
         from pootle.scripts import hooks
         hooks.hook(self.project.code, "initialize", self.real_path,
                    self.language.code)
     except Exception:
         logging.exception(u"Failed to initialize (%s)", self.language.code)
Esempio n. 3
0
    def update_file_from_version_control(self, store):
        from pootle.scripts import hooks
        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
        oldstats = store.getquickstats()
        working_copy = store.file.store

        try:
            logging.debug(u"Updating %s from version control", store.file.name)
            from pootle_misc import versioncontrol
            versioncontrol.update_file(store.file.name)
            store.file._delete_store_cache()
            store.file._update_store_cache()
        except Exception, e:
            # Something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.error(u"Near fatal catastrophe, exception %s while "
                          u"updating %s from version control",
                          e, store.file.name)
            working_copy.save()

            raise VersionControlError
Esempio n. 4
0
 def initialize(self):
     try:
         from pootle.scripts import hooks
         hooks.hook(self.project.code, "initialize", self.real_path,
                 self.language.code)
     except Exception:
         logging.exception(u"Failed to initialize (%s)", self.language.code)
Esempio n. 5
0
    def update_file_from_version_control(self, store):
        try:
            hooks.hook(self.project.code, "preupdate", store.file.path)
        except:
            pass

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

        try:
            logging.debug(u"updating %s from version control", store.file.path)
            versioncontrol.updatefile(store.file.path)
            store.file._delete_store_cache()
            store.update(update_structure=True,
                         update_translation=True,
                         conservative=False)
            remotestats = store.getquickstats()
        except Exception, e:
            #something wrong, file potentially modified, bail out
            #and replace with working copy
            logging.error(
                u"near fatal catastrophe, exception %s while updating %s from version control",
                e, store.file.path)
            working_copy.save()
            raise VersionControlError
Esempio n. 6
0
 def initialize(self):
     try:
         hooks.hook(self.project.code, "initialize", self.real_path,
                    self.language.code)
     except Exception, e:
         logging.error(u"Failed to initialize (%s): %s", self.language.code,
                       e)
Esempio n. 7
0
    def update_file_from_version_control(self, store):
        from pootle.scripts import hooks
        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
        oldstats = store.getquickstats()
        working_copy = store.file.store

        try:
            logging.debug(u"Updating %s from version control", store.file.name)
            from pootle_misc import versioncontrol
            versioncontrol.update_file(filetoupdate)
            store.file._delete_store_cache()
            store.file._update_store_cache()
        except Exception as e:
            # Something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.error(u"Near fatal catastrophe, exception %s while "
                          u"updating %s from version control",
                          e, store.file.name)
            working_copy.save()

            raise VersionControlError

        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 "
                          u"%s with version control copy", e, store.file.name)
            working_copy.save()
            store.update(update_structure=True, update_translation=True)
            raise

        newstats = store.getquickstats()
        return oldstats, remotestats, newstats
Esempio n. 8
0
    def update_file_from_version_control(self, store):
        from pootle.scripts import hooks
        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

        try:
            logging.debug(u"Updating %s from version control", store.file.name)
            from pootle_misc import versioncontrol
            versioncontrol.update_file(filetoupdate)
            store.file._delete_store_cache()
            store.file._update_store_cache()
        except Exception:
            # Something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.exception(
                u"Near fatal catastrophe, while updating %s "
                u"from version control", store.file.name)
            working_copy.save()

            raise VersionControlError

        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)

            #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:
            logging.exception(
                u"Near fatal catastrophe, while merging %s with "
                u"version control copy", store.file.name)
            working_copy.save()
            store.update(update_structure=True, update_translation=True)
            raise
Esempio n. 9
0
    def commitpofile(self, request, store):
        """commits an individual PO file to version control"""
        if not check_permission("commit", request):
            raise PermissionDenied(_("You do not have rights to commit files here"))

        store.sync(update_structure=True, update_translation=True, conservative=False)
        stats = store.getquickstats()
        author = request.user.username
        message = stats_message("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 request.user.is_authenticated() and len(request.user.email):
            author += " <%s>" % request.user.email

        try:
            filestocommit = hooks.hook(self.project.code, "precommit", store.file.path, 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.path]

        success = True
        try:
            for file in filestocommit:
                versioncontrol.commitfile(file, message=message, author=author)
                request.user.message_set.create(message="Committed file: <em>%s</em>" % file)
        except Exception, e:
            logging.error("Failed to commit files: %s", e)
            request.user.message_set.create(message="Failed to commit file: %s" % e)
            success = False
Esempio n. 10
0
    def commitpofile(self, user, store):
        """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("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.path, 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.path]

        success = True
        try:
            from translate.storage import versioncontrol

            for file in filestocommit:
                versioncontrol.commitfile(file, message=message, author=author)
                user.message_set.create(message="Committed file: <em>%s</em>" % file)
        except Exception, e:
            logging.error(u"Failed to commit files: %s", e)
            user.message_set.create(message="Failed to commit file: %s" % e)
            success = False
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
0
    def update_file_from_version_control(self, store):
        try:
            hooks.hook(self.project.code, "preupdate", store.file.path)
        except:
            pass

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

        try:
            logging.debug("updating %s from version control", store.file.path)
            versioncontrol.updatefile(store.file.path)
            store.file._delete_store_cache()
            store.update(update_structure=True, update_translation=True, conservative=False)
            remotestats = store.getquickstats()
        except Exception, e:
            #something wrong, file potentially modified, bail out
            #and replace with working copy
            logging.error("near fatal catastrophe, exception %s while updating %s from version control", e, store.file.path)
            working_copy.save()
            raise VersionControlError
Esempio n. 15
0
    def commitpofile(self, request, store):
        """commits an individual PO file to version control"""
        #FIXME: this is a view what is it doing here
        if not check_permission("commit", request):
            raise PermissionDenied(
                _("You do not have rights to commit files here"))

        store.sync(update_structure=False,
                   update_translation=True,
                   conservative=True)
        stats = store.getquickstats()
        author = request.user.username
        message = stats_message(
            "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 request.user.is_authenticated() and len(request.user.email):
            author += " <%s>" % request.user.email

        try:
            filestocommit = hooks.hook(self.project.code,
                                       "precommit",
                                       store.file.path,
                                       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.path]

        success = True
        try:
            for file in filestocommit:
                versioncontrol.commitfile(file, message=message, author=author)
                request.user.message_set.create(
                    message="Committed file: <em>%s</em>" % file)
        except Exception, e:
            logging.error(u"Failed to commit files: %s", e)
            request.user.message_set.create(
                message="Failed to commit file: %s" % e)
            success = False
Esempio n. 16
0
    def commitpofile(self, user, store):
        """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(
            "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.path,
                                       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.path]

        success = True
        try:
            from translate.storage import versioncontrol
            for file in filestocommit:
                versioncontrol.commitfile(file, message=message, author=author)
                user.message_set.create(message="Committed file: <em>%s</em>" %
                                        file)
        except Exception, e:
            logging.error(u"Failed to commit files: %s", e)
            user.message_set.create(message="Failed to commit file: %s" % e)
            success = False
Esempio n. 17
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
Esempio n. 18
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
Esempio n. 19
0
    def update_dir(self, request=None, directory=None):
        """Updates translation project's files from version control, retaining
        uncommitted translations.
        """
        remote_stats = {}

        from pootle_misc import versioncontrol
        try:
            versioncontrol.update_dir(self.real_path)
        except IOError as e:
            logging.exception(u"Error during update of %s", self.real_path)
            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:
                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)

                #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:
                logging.exception(u"Near fatal catastrophe, while merging %s "
                                  "with version control copy", store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True)
                raise

        if request:
            msg = \
                _(u'Updated project <em>%(project)s</em> from version control',
                  {'project': self.fullname})
            messages.info(request, msg)

        from pootle_app.models.signals import post_vc_update
        post_vc_update.send(sender=self)
Esempio n. 20
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()

        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)
Esempio n. 21
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
Esempio n. 22
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
Esempio n. 23
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)
Esempio n. 24
0
 def initialize(self):
     try:
         hooks.hook(self.project.code, "initialize", self.real_path, self.language.code)
     except Exception, e:
         logging.error("Failed to initialize (%s): %s", self.language.code, e)
Esempio n. 25
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)
Esempio n. 26
0
            # something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.error(
                "near fatal catastrophe, exception %s while updating %s from version control", e, store.file.path
            )
            working_copy.save()
            raise VersionControlError

        # FIXME: try to avoid merging if file was not updated
        logging.debug("merging %s with version control update", store.file.path)
        store.mergefile(
            working_copy, None, allownewstrings=False, suggestions=True, notranslate=False, obsoletemissing=False
        )

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

        newstats = store.getquickstats()
        return oldstats, remotestats, newstats

    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 = {}
Esempio n. 27
0
            from pootle_misc import versioncontrol
            versioncontrol.update_file(filetoupdate)
            store.file._delete_store_cache()
            store.file._update_store_cache()
        except Exception, e:
            # Something wrong, file potentially modified, bail out
            # and replace with working copy
            logging.error(
                u"Near fatal catastrophe, exception %s while "
                u"updating %s from version control", e, store.file.name)
            working_copy.save()

            raise VersionControlError

        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,
Esempio n. 28
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
Esempio n. 29
0
            #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 "
                          u"%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

        newstats = store.getquickstats()
        return oldstats, remotestats, newstats

    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:
Esempio n. 30
0
                e, store.file.path)
            working_copy.save()
            raise VersionControlError

        #FIXME: try to avoid merging if file was not updated
        logging.debug(u"merging %s with version control update",
                      store.file.path)
        store.mergefile(working_copy,
                        None,
                        allownewstrings=False,
                        suggestions=True,
                        notranslate=False,
                        obsoletemissing=False)

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

        newstats = store.getquickstats()
        return oldstats, remotestats, newstats

    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")
            )
Esempio n. 31
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)
Esempio n. 32
0
    def update_dir(self, request=None, directory=None):
        """Updates translation project's files from version control, retaining
        uncommitted translations.
        """
        remote_stats = {}

        from pootle_misc import versioncontrol
        try:
            versioncontrol.update_dir(self.real_path)
        except IOError as e:
            logging.exception(u"Error during update of %s", self.real_path)
            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:
                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)

                #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:
                logging.exception(
                    u"Near fatal catastrophe, while merging %s "
                    "with version control copy", store.file.name)
                working_copy.save()
                store.update(update_structure=True, update_translation=True)
                raise

        if request:
            msg = \
                _(u'Updated project <em>%(project)s</em> from version control',
                  {'project': self.fullname})
            messages.info(request, msg)

        from pootle_app.signals import post_vc_update
        post_vc_update.send(sender=self)
Esempio n. 33
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