Пример #1
0
    def create_terminology_project(self):
        """Create the terminology project.

        The terminology project is used to display terminology suggestions
        while translating.
        """
        criteria = {
            'code': "terminology",
            'fullname': u"Terminology",
            'source_language': self.require_english(),
            'checkstyle': "terminology",
        }
        po = Format.objects.get(name="po")
        terminology = self._create_object(Project, **criteria)[0]
        terminology.filetypes.add(po)
        terminology.config["pootle_fs.fs_url"] = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY,
            terminology.code)
        terminology.config["pootle_fs.fs_type"] = "localfs"
        terminology.config["pootle_fs.translation_mappings"] = dict(
            default="/<language_code>/<dir_path>/<filename>.<ext>")
        plugin = FSPlugin(terminology)
        plugin.fetch()
        plugin.add()
        plugin.sync()
Пример #2
0
 def handle_translation_project(self, translation_project, **options):
     """
     """
     path_glob = "%s*" % translation_project.pootle_path
     plugin = FSPlugin(translation_project.project)
     plugin.add(pootle_path=path_glob, update="pootle")
     plugin.rm(pootle_path=path_glob, update="pootle")
     plugin.resolve(pootle_path=path_glob, merge=not options["overwrite"])
     plugin.sync(pootle_path=path_glob, update="pootle")
Пример #3
0
 def handle_all_stores(self, translation_project, **options):
     path_glob = "%s*" % translation_project.pootle_path
     plugin = FSPlugin(translation_project.project)
     plugin.fetch()
     if translation_project.project.pk not in self.warn_on_conflict:
         state = plugin.state()
         if any(k in state for k in ["conflict", "conflict_untracked"]):
             logger.warn(
                 "The project '%s' has conflicting changes in the database "
                 "and translation files. Use `pootle fs resolve` to tell "
                 "pootle how to merge", translation_project.project.code)
             self.warn_on_conflict.append(translation_project.project.pk)
     if not options["skip_missing"]:
         plugin.add(pootle_path=path_glob, update="fs")
     plugin.sync(pootle_path=path_glob, update="fs")
Пример #4
0
def tutorial(english, settings):
    """Require `tutorial` test project."""
    import pytest_pootle

    from pootle_fs.utils import FSPlugin

    shutil.copytree(
        os.path.join(os.path.dirname(pytest_pootle.__file__), "data", "po",
                     "tutorial"),
        os.path.join(settings.POOTLE_TRANSLATION_DIRECTORY, "tutorial"))
    project = _require_project('tutorial', 'Tutorial', english, settings)
    plugin = FSPlugin(project)
    plugin.fetch()
    plugin.add()
    plugin.sync()
    return project
Пример #5
0
 def handle_all_stores(self, translation_project, **options):
     path_glob = "%s*" % translation_project.pootle_path
     plugin = FSPlugin(translation_project.project)
     plugin.fetch()
     if translation_project.project.pk not in self.warn_on_conflict:
         state = plugin.state()
         if any(k in state for k in ["conflict", "conflict_untracked"]):
             logger.warn(
                 "The project '%s' has conflicting changes in the database "
                 "and translation files. Use `pootle fs resolve` to tell "
                 "pootle how to merge",
                 translation_project.project.code)
             self.warn_on_conflict.append(
                 translation_project.project.pk)
     if not options["skip_missing"]:
         plugin.add(pootle_path=path_glob, update="fs")
     plugin.sync(pootle_path=path_glob, update="fs")
Пример #6
0
    def handle(self, **options):
        source_language_code = options['source_language']
        try:
            source_language = Language.objects.get(code=source_language_code)
        except Language.DoesNotExist as e:
            self.stdout.write('%s: Unknown language code.' %
                              source_language_code)
            raise CommandError(e)

        fs_type, fs_url = parse_fs_url(options['fs'])
        code = options['code']
        name = options['name'] or code.capitalize()

        try:
            project = Project.objects.create(
                code=code,
                fullname=name,
                treestyle='pootle_fs',
                checkstyle=options['checkstyle'],
                source_language=source_language)
        except ValidationError as e:
            raise CommandError(e)

        for filetype in options["filetypes"] or ["po"]:
            try:
                filetype = Format.objects.get(name=filetype)
                project.filetypes.add(filetype)
            except Format.DoesNotExist as e:
                raise CommandError(e)

        project.config['pootle_fs.fs_type'] = fs_type
        project.config['pootle_fs.fs_url'] = fs_url
        project.config['pootle_fs.translation_mappings'] = {
            'default': options['translation_mapping']
        }
        if options['sync']:
            try:
                plugin = FSPlugin(project)
                plugin.fetch()
                plugin.add()
                plugin.sync()
            except FSFetchError as e:
                project.delete()
                raise CommandError(e)
Пример #7
0
def tutorial(english, settings):
    """Require `tutorial` test project."""
    import pytest_pootle

    from pootle_fs.utils import FSPlugin

    shutil.copytree(
        os.path.join(
            os.path.dirname(pytest_pootle.__file__),
            "data", "po", "tutorial"),
        os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY,
            "tutorial"))
    project = _require_project('tutorial', 'Tutorial', english, settings)
    plugin = FSPlugin(project)
    plugin.fetch()
    plugin.add()
    plugin.sync()
    return project
Пример #8
0
    def handle(self, **options):
        source_language_code = options['source_language']
        try:
            source_language = Language.objects.get(code=source_language_code)
        except Language.DoesNotExist as e:
            self.stdout.write('%s: Unknown language code.' %
                              source_language_code)
            raise CommandError(e)

        fs_type, fs_url = parse_fs_url(options['fs'])
        code = options['code']
        name = options['name'] or code.capitalize()

        try:
            project = Project.objects.create(
                code=code,
                fullname=name,
                checkstyle=options['checkstyle'],
                source_language=source_language)
        except ValidationError as e:
            raise CommandError(e)

        for filetype in options["filetypes"] or ["po"]:
            try:
                filetype = Format.objects.get(name=filetype)
                project.filetypes.add(filetype)
            except Format.DoesNotExist as e:
                raise CommandError(e)

        project.config['pootle_fs.fs_type'] = fs_type
        project.config['pootle_fs.fs_url'] = fs_url
        project.config['pootle_fs.translation_mappings'] = {
            'default': options['translation_mapping']
        }
        if options['sync']:
            try:
                plugin = FSPlugin(project)
                plugin.fetch()
                plugin.add()
                plugin.sync()
            except FSFetchError as e:
                project.delete()
                raise CommandError(e)
Пример #9
0
    def create_default_projects(self):
        """Create the default projects that we host.

        You might want to add your projects here, although you can also add
        things through the web interface later.
        """
        en = self.require_english()
        po = Format.objects.get(name="po")

        criteria = {
            'code': u"tutorial",
            'source_language': en,
            'fullname': u"Tutorial",
            'checkstyle': "standard"
        }
        tutorial = self._create_object(Project, **criteria)[0]
        tutorial.filetypes.add(po)
        tutorial.config["pootle_fs.fs_type"] = "localfs"
        tutorial.config["pootle_fs.fs_url"] = (
            "{POOTLE_TRANSLATION_DIRECTORY}%s" % tutorial.code)
        tutorial.config["pootle_fs.translation_mappings"] = dict(
            default="/<language_code>/<dir_path>/<filename>.<ext>")
        plugin = FSPlugin(tutorial)
        plugin.fetch()
        plugin.add()
        plugin.sync()
        criteria = {
            'active':
            True,
            'title':
            "Project instructions",
            'body':
            ('Tutorial project where users can play with Pootle and learn '
             'more about translation and localisation.\n'
             '\n'
             'For more help on localisation, visit the [localization '
             'guide](http://docs.translatehouse.org/projects/'
             'localization-guide/en/latest/guide/start.html).'),
            'virtual_path':
            "announcements/projects/" + tutorial.code,
        }
        self._create_object(Announcement, **criteria)
Пример #10
0
    def create_default_projects(self):
        """Create the default projects that we host.

        You might want to add your projects here, although you can also add
        things through the web interface later.
        """
        en = self.require_english()
        po = Format.objects.get(name="po")

        criteria = {
            'code': u"tutorial",
            'source_language': en,
            'fullname': u"Tutorial",
            'checkstyle': "standard"}
        tutorial = self._create_object(Project, **criteria)[0]
        tutorial.filetypes.add(po)
        tutorial.config["pootle_fs.fs_url"] = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY,
            tutorial.code)
        tutorial.config["pootle_fs.fs_type"] = "localfs"
        tutorial.config["pootle_fs.translation_mappings"] = dict(
            default="/<language_code>/<dir_path>/<filename>.<ext>")
        plugin = FSPlugin(tutorial)
        plugin.fetch()
        plugin.add()
        plugin.sync()
        criteria = {
            'active': True,
            'title': "Project instructions",
            'body': (
                'Tutorial project where users can play with Pootle and learn '
                'more about translation and localisation.\n'
                '\n'
                'For more help on localisation, visit the [localization '
                'guide](http://docs.translatehouse.org/projects/'
                'localization-guide/en/latest/guide/start.html).'),
            'virtual_path': "announcements/projects/"+tutorial.code,
        }
        self._create_object(Announcement, **criteria)
Пример #11
0
    def create_terminology_project(self):
        """Create the terminology project.

        The terminology project is used to display terminology suggestions
        while translating.
        """
        criteria = {
            'code': "terminology",
            'fullname': u"Terminology",
            'source_language': self.require_english(),
            'checkstyle': "terminology",
        }
        po = Format.objects.get(name="po")
        terminology = self._create_object(Project, **criteria)[0]
        terminology.filetypes.add(po)
        terminology.config["pootle_fs.fs_type"] = "localfs"
        terminology.config["pootle_fs.fs_url"] = (
            "{POOTLE_TRANSLATION_DIRECTORY}%s" % terminology.code)
        terminology.config["pootle_fs.translation_mappings"] = dict(
            default="/<language_code>/<dir_path>/<filename>.<ext>")
        plugin = FSPlugin(terminology)
        plugin.fetch()
        plugin.add()
        plugin.sync()
Пример #12
0
def hg_env(post_db_setup, _django_cursor_wrapper):
    from django.conf import settings

    import pytest_pootle

    from pytest_pootle.factories import (ProjectDBFactory,
                                         TranslationProjectFactory)

    from pootle_fs.utils import FSPlugin
    from pootle_language.models import Language

    import tempfile

    with _django_cursor_wrapper:
        project0 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="hg_project_0")

        language0 = Language.objects.get(code="language0")
        TranslationProjectFactory(project=project0, language=language0)

        initial_src_path = os.path.abspath(
            os.path.join(os.path.dirname(pytest_pootle.__file__),
                         "data/fs/example_fs"))
        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__hg_src_project_0__")
        hglib.init(repo_path)

        with tmp_hg(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.add()
            tmp_repo.commit("Initial commit")
            tmp_repo.push()

        project0.config["pootle_fs.fs_type"] = "hg"
        project0.config["pootle_fs.fs_url"] = repo_path
        project0.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }

        plugin = FSPlugin(project0)
        plugin.add()
        plugin.fetch()
        plugin.sync()

        # create_test_suite(plugin)

        project1 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="hg_project_1")

        TranslationProjectFactory(project=project1, language=language0)

        repo_path = os.path.join(fs_dir, "__hg_src_project_1__")
        hglib.init(repo_path)

        with tmp_hg(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.add()
            tmp_repo.commit("Initial commit")
            tmp_repo.push()

        project1.config["pootle_fs.fs_type"] = "hg"
        project1.config["pootle_fs.fs_url"] = repo_path
        project1.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
Пример #13
0
def test_fs_plugin_fetch_bad(project0):
    plugin = FSPlugin(project0)
    plugin.clear_repo()

    with pytest.raises(FSStateError):
        plugin.add()
Пример #14
0
def hg_env(post_db_setup, _django_cursor_wrapper):
    from django.conf import settings

    import pytest_pootle

    from pytest_pootle.factories import (
        ProjectDBFactory, TranslationProjectFactory)

    from pootle_fs.utils import FSPlugin
    from pootle_language.models import Language

    import tempfile

    with _django_cursor_wrapper:
        project0 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="hg_project_0")

        language0 = Language.objects.get(code="language0")
        TranslationProjectFactory(project=project0, language=language0)

        initial_src_path = os.path.abspath(
            os.path.join(
                os.path.dirname(pytest_pootle.__file__),
                "data/fs/example_fs"))
        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__hg_src_project_0__")
        hglib.init(repo_path)

        with tmp_hg(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.add()
            tmp_repo.commit("Initial commit")
            tmp_repo.push()

        project0.config["pootle_fs.fs_type"] = "hg"
        project0.config["pootle_fs.fs_url"] = repo_path
        project0.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}

        plugin = FSPlugin(project0)
        plugin.add()
        plugin.fetch()
        plugin.sync()

        # create_test_suite(plugin)

        project1 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="hg_project_1")

        TranslationProjectFactory(project=project1, language=language0)

        repo_path = os.path.join(fs_dir, "__hg_src_project_1__")
        hglib.init(repo_path)

        with tmp_hg(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.add()
            tmp_repo.commit("Initial commit")
            tmp_repo.push()

        project1.config["pootle_fs.fs_type"] = "hg"
        project1.config["pootle_fs.fs_url"] = repo_path
        project1.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}
Пример #15
0
def test_fs_plugin_fetch_bad(project0):
    plugin = FSPlugin(project0)
    plugin.clear_repo()

    with pytest.raises(FSStateError):
        plugin.add()
Пример #16
0
def setup_git_env(django_db_setup, django_db_blocker):
    """Sets up the site DB only if tests requested to use the DB (autouse)."""
    from django.conf import settings

    import pytest_pootle

    from pytest_pootle.factories import (ProjectDBFactory,
                                         TranslationProjectFactory)

    from pootle_fs.utils import FSPlugin
    from pootle_language.models import Language

    import tempfile

    with django_db_blocker.unblock():
        project0 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_0")

        language0 = Language.objects.get(code="language0")
        TranslationProjectFactory(project=project0, language=language0)

        initial_src_path = os.path.abspath(
            os.path.join(os.path.dirname(pytest_pootle.__file__),
                         "data/fs/example_fs"))
        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__git_src_project_0__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")

        project0.config["pootle_fs.fs_type"] = "git"
        project0.config["pootle_fs.fs_url"] = repo_path
        project0.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        plugin = FSPlugin(project0)
        plugin.fetch()
        plugin.add()
        plugin.sync()

        # create_test_suite(plugin)

        project1 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_1")

        TranslationProjectFactory(project=project1, language=language0)

        repo_path = os.path.join(fs_dir, "__git_src_project_1__")
        Repo.init(repo_path, bare=True)
        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.add(["*"])
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")
        project1.config["pootle_fs.fs_type"] = "git"
        project1.config["pootle_fs.fs_url"] = repo_path
        project1.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }