Пример #1
0
    def update_from_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
            .get_template_translationproject()

        if template_translation_project is None or \
           template_translation_project == self:
            return

        monolingual = self.project.is_monolingual()

        if not monolingual:
            self.sync()

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

        from pootle_app.project_tree import convert_template, \
            get_translated_name, get_translated_name_gnu

        for store in template_translation_project.stores.iterator():

            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(
                    self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

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

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

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

        from pootle_misc.versioncontrol import hasversioning
        project_path = self.project.get_real_path()
        if new_files and hasversioning(project_path):
            from translate.storage import versioncontrol
            vcs = versioncontrol.get_versioned_object(project_path)
            output = vcs.add([s.abs_real_path for s in new_files],
                             "New files added from %s based on templates" %
                             (settings.TITLE))

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

            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self,
                                      oldstats=oldstats,
                                      newstats=newstats)
Пример #2
0
def update_link(request, path_obj):
    if path_obj.abs_real_path and check_permission('commit', request) and hasversioning(path_obj.abs_real_path):
        link = dispatch.update(request, path_obj)
        text = _('Update from VCS')
        return {
            'class': 'vcs update',
            'href': link,
            'text': text,
            'link': link,
        }
Пример #3
0
def commit_link(request, path_obj):
    if path_obj.abs_real_path and check_permission('commit', request) and hasversioning(path_obj.abs_real_path):
        link = dispatch.commit(request, path_obj)
        text = _('Commit to VCS')
        return {
            'class': 'vcs commit',
            'href': link,
            'text': text,
            'link': link,
        }
Пример #4
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

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

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

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

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

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

            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self, oldstats=oldstats,
                                      newstats=newstats)
Пример #5
0
def update_from_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request) and
        hasversioning(path_obj.abs_real_path)):
        link = dispatch.update(path_obj)
        text = _('Update from VCS')

        return {
            'icon': 'icon-vcs-update',
            'href': link,
            'text': text,
        }
Пример #6
0
def update_all_link(request, path_obj):
    # Directory.get_real_path() doesn't give an absolute path :-(
    if check_permission('commit', request) and hasversioning(path_obj.get_real_path()):
        link = 'javascript:alert("Not implemented")' #FIXME: provide actual link
        text = _('Update from VCS')
        return {
            'class': 'vcs update',
            'href': link,
            'text': text,
            'link': link,
        }
Пример #7
0
def commit_to_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request) and
        hasversioning(path_obj.abs_real_path)):
        link = dispatch.commit(path_obj)
        text = _('Commit to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #8
0
def commit_to_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request)
            and hasversioning(path_obj.abs_real_path)):
        link = dispatch.commit(path_obj)
        text = _('Commit to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #9
0
def update_from_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request)
            and hasversioning(path_obj.abs_real_path)):
        link = dispatch.update(path_obj)
        text = _('Update from VCS')

        return {
            'icon': 'icon-vcs-update',
            'href': link,
            'text': text,
        }
Пример #10
0
def commit_to_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request)
            and hasversioning(path_obj.abs_real_path)):
        link = reverse('pootle-vcs-commit',
                       args=split_pootle_path(path_obj.pootle_path))
        text = _('Commit to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #11
0
    def update_from_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project.get_template_translationproject()

        if template_translation_project is None or template_translation_project == self:
            return

        monolingual = self.project.is_monolingual()

        if not monolingual:
            self.sync()

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

        from pootle_app.project_tree import convert_template, get_translated_name, get_translated_name_gnu

        for store in template_translation_project.stores.iterator():

            if self.file_style == "gnu":
                new_pootle_path, new_path = get_translated_name_gnu(self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

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

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

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

        from pootle_misc.versioncontrol import hasversioning

        project_path = self.project.get_real_path()
        if new_files and hasversioning(project_path):
            from translate.storage import versioncontrol

            vcs = versioncontrol.get_versioned_object(project_path)
            output = vcs.add(
                [s.abs_real_path for s in new_files], "New files added from %s based on templates" % (settings.TITLE)
            )

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

            from pootle_app.models.signals import post_template_update

            post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
Пример #12
0
def commit_dir_to_vcs(request, path_obj, **kwargs):
    if (path_obj.get_real_path() and check_permission('commit', request) and
            hasversioning(path_obj.get_real_path())):
        link = dispatch.commit_all(path_obj)
        # Translators: "all" here refers to all files and sub directories in a directory/project.
        text = _('Commit all to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #13
0
def commit_to_vcs(request, path_obj, **kwargs):
    if (path_obj.abs_real_path and check_permission('commit', request) and
        hasversioning(path_obj.abs_real_path)):
        link = reverse('pootle-vcs-commit',
                       args=split_pootle_path(path_obj.pootle_path))
        text = _('Commit to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #14
0
def commit_dir_to_vcs(request, path_obj, **kwargs):
    if (path_obj.get_real_path() and check_permission('commit', request) and
            hasversioning(path_obj.get_real_path())):
        link = dispatch.commit_all(path_obj)
        # Translators: "all" here refers to all files and sub directories in a directory/project.
        text = _('Commit all to VCS')

        return {
            'icon': 'icon-vcs-commit',
            'href': link,
            'text': text,
        }
Пример #15
0
def update_dir_from_vcs(request, path_obj, **kwargs):
    if (path_obj.get_real_path() and check_permission('commit', request)
            and hasversioning(path_obj.get_real_path())):
        link = reverse('pootle-vcs-update',
                       args=split_pootle_path(path_obj.pootle_path))
        # Translators: "all" here refers to all files and sub directories in a directory/project.
        text = _('Update all from VCS')

        return {
            'icon': 'icon-vcs-update',
            'href': link,
            'text': text,
        }
Пример #16
0
def update_dir_from_vcs(request, path_obj, **kwargs):
    if (path_obj.get_real_path() and check_permission('commit', request) and
            hasversioning(path_obj.get_real_path())):
        link = reverse('pootle-vcs-update',
                       args=split_pootle_path(path_obj.pootle_path))
        # Translators: "all" here refers to all files and sub directories in a directory/project.
        text = _('Update all from VCS')

        return {
            'icon': 'icon-vcs-update',
            'href': link,
            'text': text,
        }
Пример #17
0
def sync_from_vcs(ignored_files, ext, relative_dir,
                  file_filter=lambda _x: True):
    """Recursively synchronise the PO directory from the VCS directory.

    This brings over files from VCS, and removes files in PO directory that
    were removed in VCS.
    """
    if not versioncontrol.hasversioning(relative_dir):
        return

    podir_path = versioncontrol.to_podir_path(relative_dir)
    vcs_path = versioncontrol.to_vcs_path(relative_dir)
    vcs_files, vcs_dirs = recursive_files_and_dirs(ignored_files, ext,
                                                   vcs_path, file_filter)
    files, dirs = recursive_files_and_dirs(ignored_files, ext, podir_path,
                                           file_filter)
Пример #18
0
def sync_from_vcs(ignored_files,
                  ext,
                  relative_dir,
                  file_filter=lambda _x: True):
    """Recursively synchronise the PO directory from the VCS directory.

    This brings over files from VCS, and removes files in PO directory that
    were removed in VCS.
    """
    from pootle_misc import versioncontrol
    if not versioncontrol.hasversioning(relative_dir):
        return

    podir_path = versioncontrol.to_podir_path(relative_dir)
    vcs_path = versioncontrol.to_vcs_path(relative_dir)
    vcs_files, vcs_dirs = recursive_files_and_dirs(ignored_files, ext,
                                                   vcs_path, file_filter)
    files, dirs = recursive_files_and_dirs(ignored_files, ext, podir_path,
                                           file_filter)

    vcs_file_set = set(vcs_files)
    vcs_dir_set = set(vcs_dirs)
    file_set = set(files)
    dir_set = set(dirs)

    for d in vcs_dir_set - dir_set:
        new_path = os.path.join(podir_path, d)
        os.makedirs(new_path)

    # copy into podir
    for f in vcs_file_set - file_set:
        vcs_f = os.path.join(vcs_path, f)
        new_path = os.path.join(podir_path, f)
        shutil.copy2(vcs_f, new_path)

    # remove from podir
    #TODO: review this carefully, as we are now deleting stuff
    for f in file_set - vcs_file_set:
        remove_path = os.path.join(podir_path, f)
        os.remove(remove_path)

    for d in dir_set - vcs_dir_set:
        remove_path = os.path.join(podir_path, d)
        shutil.rmtree(remove_path)
Пример #19
0
def sync_from_vcs(ignored_files, ext, relative_dir,
                  file_filter=lambda _x: True):
    """Recursively synchronise the PO directory from the VCS directory.

    This brings over files from VCS, and removes files in PO directory that
    were removed in VCS.
    """
    from pootle_misc import versioncontrol
    if not versioncontrol.hasversioning(relative_dir):
        return

    podir_path = versioncontrol.to_podir_path(relative_dir)
    vcs_path = versioncontrol.to_vcs_path(relative_dir)
    vcs_files, vcs_dirs = recursive_files_and_dirs(ignored_files, ext,
                                                   vcs_path, file_filter)
    files, dirs = recursive_files_and_dirs(ignored_files, ext, podir_path,
                                           file_filter)

    vcs_file_set = set(vcs_files)
    vcs_dir_set = set(vcs_dirs)
    file_set = set(files)
    dir_set = set(dirs)

    for d in vcs_dir_set - dir_set:
        new_path = os.path.join(podir_path, d)
        os.makedirs(new_path)

    # copy into podir
    for f in vcs_file_set - file_set:
        vcs_f = os.path.join(vcs_path, f)
        new_path = os.path.join(podir_path, f)
        shutil.copy2(vcs_f, new_path)

    # remove from podir
    #TODO: review this carefully, as we are now deleting stuff
    for f in file_set - vcs_file_set:
        remove_path = os.path.join(podir_path, f)
        os.remove(remove_path)

    for d in dir_set - vcs_dir_set:
        remove_path = os.path.join(podir_path, d)
        shutil.rmtree(remove_path)
Пример #20
0
 def must_display(cls, request, *args, **kwargs):
     return check_permission('commit', request) and \
         hasversioning(request.translation_project.abs_real_path)
Пример #21
0
def add_files(translation_project, ignored_files, ext, relative_dir, db_dir,
              file_filter=lambda _x: True):
    from pootle_misc import versioncontrol
    has_versioning = versioncontrol.hasversioning(relative_dir)
    podir_path = versioncontrol.to_podir_path(relative_dir)
    vcs_path = versioncontrol.to_vcs_path(relative_dir)

    if has_versioning:
        # Bring the tree in the podirectory up to date with the tree in the VCS
        vcs_files, vcs_dirs = split_files_and_dirs(ignored_files, ext,
                                                   vcs_path, file_filter)
        files, dirs = split_files_and_dirs(ignored_files, ext, podir_path,
                                           file_filter)

        vcs_file_set = set(vcs_files)
        vcs_dir_set = set(vcs_dirs)
        file_set = set(files)
        dir_set = set(dirs)

        # copy into podir
        for f in vcs_file_set - file_set:
            vcs_f = os.path.join(vcs_path, f)
            new_path = os.path.join(podir_path, f)
            shutil.copy2(vcs_f, new_path)

        for d in vcs_dir_set - dir_set:
            new_path = os.path.join(podir_path, d)
            os.makedirs(new_path)

        # remove from podir
        #TODO: review this carefully, as we are now deleting stuff
        for f in file_set - vcs_file_set:
            remove_path = os.path.join(podir_path, f)
            os.remove(remove_path)

        for d in dir_set - vcs_dir_set:
            remove_path = os.path.join(podir_path, d)
            shutil.rmtree(remove_path)

        file_set = vcs_file_set
        dir_set = vcs_dir_set
    else:
        files, dirs = split_files_and_dirs(ignored_files, ext, podir_path,
                                           file_filter)
        file_set = set(files)
        dir_set = set(dirs)

    existing_stores = dict((store.name, store) for store in db_dir.child_stores.exclude(file='').iterator())
    existing_dirs = dict((dir.name, dir) for dir in db_dir.child_dirs.iterator())
    files, new_files = add_items(file_set, existing_stores,
              lambda name: Store(file=os.path.join(relative_dir, name),
                                 parent=db_dir,
                                 name=name,
                                 translation_project=translation_project))

    db_subdirs, new_db_subdirs = add_items(dir_set, existing_dirs,
                           lambda name: Directory(name=name, parent=db_dir))

    for db_subdir in db_subdirs:
        fs_subdir = os.path.join(relative_dir, db_subdir.name)
        _files, _new_files = add_files(translation_project, ignored_files, ext,
                                       fs_subdir, db_subdir, file_filter)
        files += _files
        new_files += _new_files

    return files, new_files
Пример #22
0
def add_files(translation_project, ignored_files, ext, relative_dir, db_dir, file_filter=lambda _x: True):
    from pootle_misc import versioncontrol

    has_versioning = versioncontrol.hasversioning(relative_dir)
    podir_path = versioncontrol.to_podir_path(relative_dir)
    vcs_path = versioncontrol.to_vcs_path(relative_dir)

    if has_versioning:
        # bring the tree in the podirectory up to date with the tree in the VCS
        vcs_files, vcs_dirs = split_files_and_dirs(ignored_files, ext, vcs_path, file_filter)
        files, dirs = split_files_and_dirs(ignored_files, ext, podir_path, file_filter)

        vcs_file_set = set(vcs_files)
        vcs_dir_set = set(vcs_dirs)
        file_set = set(files)
        dir_set = set(dirs)

        # copy into podir
        for f in vcs_file_set - file_set:
            vcs_f = os.path.join(vcs_path, f)
            new_path = os.path.join(podir_path, f)
            shutil.copy2(vcs_f, new_path)

        for d in vcs_dir_set - dir_set:
            new_path = os.path.join(podir_path, d)
            os.makedirs(new_path)

        # remove from podir
        # TODO: review this carefully, as we are now deleting stuff
        for f in file_set - vcs_file_set:
            remove_path = os.path.join(podir_path, f)
            os.remove(remove_path)

        for d in dir_set - vcs_dir_set:
            remove_path = os.path.join(podir_path, d)
            shutil.rmtree(remove_path)

        file_set = vcs_file_set
        dir_set = vcs_dir_set

    else:
        files, dirs = split_files_and_dirs(ignored_files, ext, podir_path, file_filter)
        file_set = set(files)
        dir_set = set(dirs)

    existing_stores = dict((store.name, store) for store in db_dir.child_stores.exclude(file="").iterator())
    existing_dirs = dict((dir.name, dir) for dir in db_dir.child_dirs.iterator())
    files, new_files = add_items(
        file_set,
        existing_stores,
        lambda name: Store(
            file=os.path.join(relative_dir, name), parent=db_dir, name=name, translation_project=translation_project
        ),
    )

    db_subdirs, new_db_subdirs = add_items(dir_set, existing_dirs, lambda name: Directory(name=name, parent=db_dir))

    for db_subdir in db_subdirs:
        fs_subdir = os.path.join(relative_dir, db_subdir.name)
        _files, _new_files = add_files(translation_project, ignored_files, ext, fs_subdir, db_subdir, file_filter)
        files += _files
        new_files += _new_files
    return files, new_files
Пример #23
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)
Пример #24
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
Пример #25
0
 def must_display(cls, request, *args, **kwargs):
     return check_permission('commit', request) and \
         hasversioning(request.translation_project.abs_real_path)