Ejemplo n.º 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()
Ejemplo n.º 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")
Ejemplo n.º 3
0
def _sync_translations(db_unit):
    store = db_unit.store
    tp = store.translation_project
    project = tp.project
    language = tp.language
    plugin = FSPlugin(project)
    plugin.fetch()
    plugin.sync()
    file_store = db_unit.store.deserialize(
        open(os.path.join(plugin.fs_url, language.code, store.name)).read())
    file_unit = file_store.findid(db_unit.getid())
    return file_store, file_unit
Ejemplo n.º 4
0
Archivo: unit.py Proyecto: arky/pootle
def _sync_translations(db_unit):
    store = db_unit.store
    tp = store.translation_project
    project = tp.project
    language = tp.language
    plugin = FSPlugin(project)
    plugin.fetch()
    plugin.sync()
    file_store = db_unit.store.deserialize(
        open(os.path.join(
            plugin.fs_url,
            language.code,
            store.name)).read())
    file_unit = file_store.findid(db_unit.getid())
    return file_store, file_unit
Ejemplo n.º 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")
Ejemplo n.º 6
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
Ejemplo n.º 7
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")
Ejemplo n.º 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,
                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)
Ejemplo n.º 9
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
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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,
                localfiletype=options['file_type'],
                treestyle='none',
                checkstyle=options['checkstyle'],
                source_language=source_language
            )
            project.update_all_cache()
        except IntegrityError as e:
            self.stdout.write('Project code "%s" already exists.'
                              % options['code'])
            raise CommandError(e)

        project.config['pootle_fs.fs_type'] = fs_type
        project.config['pootle_fs.fs_url'] = fs_url
        project.config['pootle_fs.translation_paths'] = {
            'default': options['translation_path']
        }

        if options['sync']:
            plugin = FSPlugin(project)
            plugin.fetch()
            plugin.sync()
Ejemplo n.º 14
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()
Ejemplo n.º 15
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>"
        }
Ejemplo n.º 16
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>"
        }
Ejemplo n.º 17
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>"}