Пример #1
0
def test_init_fs_project_cmd_nosync(settings, test_fs, tmpdir, revision):
    settings.POOTLE_FS_WORKING_PATH = str(tmpdir)
    fs_path = test_fs.path("data/fs/example_fs/non_gnu_style_minimal/")
    tr_path = "<language_code>/<filename>.<ext>"
    call_command(
        "init_fs_project",
        "foo",
        fs_path,
        tr_path,
        "--nosync",
        "--checkstyle=standard",
        "--filetypes=po",
        "--source-language=en",
        "--name=Foo"
    )

    project = Project.objects.get(code='foo')
    assert project is not None
    assert project.code == "foo"
    assert project.fullname == "Foo"
    assert "po" in project.filetypes.values_list("name", flat=True)
    assert project.checkstyle == "standard"
    assert project.source_language.code == "en"
    assert project.treestyle == 'pootle_fs'

    assert project.config.get('pootle_fs.fs_type') == 'localfs'
    assert project.config.get('pootle_fs.fs_url') == fs_path
    assert project.config.get(
        'pootle_fs.translation_mappings')['default'] == tr_path

    assert project.translationproject_set.all().count() == 0
    plugin = FSPlugin(project)
    plugin.fetch()
    state = plugin.state()
    assert "fs_untracked: 1" in str(state)
Пример #2
0
def __test_plugin_commit_message(hg_project):
    hg_plugin = FSPlugin(hg_project)
    NEW_COMMIT_MSG = "New commit message"
    hg_plugin.pull()
    assert not hg_plugin.config.get("pootle_fs.commit_message")

    # make some updates
    hg_plugin.push_translations()

    # check that commit message uses default when not set in config
    with tmp_hg(hg_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.hg.log('-1', '--pretty=%s')
        assert last_commit == DEFAULT_COMMIT_MSG

    # update the config
    hg_plugin.config["pootle_fs.commit_message"] = NEW_COMMIT_MSG

    # make further updates
    hg_plugin.add_translations()
    hg_plugin.sync_translations()

    # test that sync_translations committed with new commit message
    with tmp_hg(hg_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.hg.log('-1', '--pretty=%s')
        assert last_commit == NEW_COMMIT_MSG
Пример #3
0
def project_fs(tmpdir, settings):
    from pootle_project.models import Project
    from pootle_fs.utils import FSPlugin

    project = Project.objects.get(code="project0")
    new_url = os.path.join(str(tmpdir), "__src__")
    project.config["pootle_fs.fs_url"] = new_url
    plugin = FSPlugin(project)
    os.makedirs(new_url)
    settings.POOTLE_FS_WORKING_PATH = str(tmpdir)
    plugin.fetch()
    return plugin
Пример #4
0
    def _setup_project_fs(self, project):
        from pootle_fs.utils import FSPlugin
        from pytest_pootle.utils import add_store_fs

        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(
                store=store,
                fs_path=plugin.get_fs_path(store.pootle_path),
                synced=True)
Пример #5
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
Пример #6
0
def test_project_fs_instance():

    @provider(fs_plugins, sender=Project)
    def provide_fs_plugin(**kwargs):
        return dict(dummyfs=DummyFSPlugin)

    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    project.config["pootle_fs.fs_url"] = "/foo/bar"
    plugin = FSPlugin(project)
    assert str(plugin) == "<DummyFSPlugin(Project 0)>"
    assert plugin.project == project
    assert plugin.plugin_property == "Plugin property"
    assert plugin.plugin_method("bar") == "Plugin method called with: bar"
    assert plugin == FSPlugin(project)
Пример #7
0
def dummyfs_plugin_no_stores(settings, no_complex_po_, dummy_fs_getters):
    from pootle.core.plugin import provider
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project
    from pootle_store.models import Store

    settings.POOTLE_FS_WORKING_PATH = os.sep.join(['', 'tmp', 'foo'])
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    stores = Store.objects.filter(translation_project__project=project)
    pootle_paths = list(stores.values_list("pootle_path", flat=True))

    class NoStoresDummyPlugin(DummyPlugin):
        def find_translations(self, fs_path=None, pootle_path=None):
            for pp in pootle_paths:
                if pootle_path and not fnmatch(pp, pootle_path):
                    continue
                fp = self.get_fs_path(pp)
                if fs_path and not fnmatch(fp, fs_path):
                    continue
                yield pp, fp

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider_(**kwargs_):
        return dict(dummyfs=NoStoresDummyPlugin)

    plugin = FSPlugin(project)
    return plugin
Пример #8
0
def dummyfs_plugin_fs_changed(settings, dummy_fs_getters):
    from pootle.core.plugin import getter, provider
    from pootle_fs.delegate import fs_file, fs_plugins
    from pootle_fs.files import FSFile
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    class FSChangedFile(FSFile):
        @property
        def fs_changed(self):
            return True

    class PootleConflictDummyPlugin(DummyPlugin):

        pass

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider_(**kwargs_):
        return dict(dummyfs=PootleConflictDummyPlugin)

    @getter(fs_file, weak=False, sender=PootleConflictDummyPlugin)
    def fs_files_getter_(**kwargs_):
        return FSChangedFile

    project = Project.objects.get(code="project0")
    settings.POOTLE_FS_WORKING_PATH = os.sep.join(['', 'tmp', 'foo'])
    project.config["pootle_fs.fs_type"] = "dummyfs"
    return FSPlugin(project)
Пример #9
0
def test_plugin_instance_bad_args(hg_project):
    hg_plugin = FSPlugin(hg_project)

    with pytest.raises(TypeError):
        hg_plugin.plugin.__class__()

    with pytest.raises(TypeError):
        hg_plugin.plugin.__class__("FOO")
Пример #10
0
def test_plugin_instance(english):
    project = ProjectDBFactory(source_language=english)
    project.config["pootle_fs.fs_type"] = "hg"
    project.config["pootle_fs.fs_url"] = "bar"
    project.config["pootle_fs.translation_paths"] = DEFAULT_TRANSLATION_PATHS
    hg_plugin = FSPlugin(project)
    assert hg_plugin.project == hg_plugin.plugin.project == project
    assert hg_plugin.is_cloned is False
Пример #11
0
    def setup_fs(self):
        from pytest_pootle.utils import add_store_fs

        from pootle_project.models import Project
        from pootle_fs.utils import FSPlugin

        project = Project.objects.get(code="project0")
        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(store=store,
                         fs_path=plugin.get_fs_path(store.pootle_path),
                         synced=True)
Пример #12
0
def project0_dummy_plugin_no_stores(settings, request,
                                    no_fs_plugins, no_fs_files):
    from pytest_pootle.utils import add_store_fs

    from pootle.core.plugin import getter, provider
    from pootle_fs.delegate import fs_file, fs_plugins
    from pootle_fs.files import FSFile
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project
    from pootle_store.models import Store

    settings.POOTLE_FS_PATH = "/tmp/foo/"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    project.config["pootle_fs.fs_url"] = "/foo/bar"
    stores = Store.objects.filter(
        translation_project__project=project)
    pootle_paths = list(stores.values_list("pootle_path", flat=True))

    class NoStoresDummyPlugin(DummyPlugin):

        def find_translations(self, fs_path=None, pootle_path=None):
            for pp in pootle_paths:
                if pootle_path and not fnmatch(pp, pootle_path):
                    continue
                fp = self.get_fs_path(pp)
                if fs_path and not fnmatch(fp, fs_path):
                    continue
                yield pp, fp

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider(**kwargs):
        return dict(dummyfs=NoStoresDummyPlugin)

    @getter(fs_file, weak=False, sender=NoStoresDummyPlugin)
    def fs_files_getter(**kwargs):
        return FSFile

    plugin = FSPlugin(project)
    for store in stores:
        add_store_fs(
            store=store,
            fs_path=plugin.get_fs_path(store.pootle_path),
            synced=True)
    return plugin
Пример #13
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()
Пример #14
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")
Пример #15
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='none',
                checkstyle=options['checkstyle'],
                source_language=source_language)
            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.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()
Пример #16
0
def project_fs(tmpdir, settings):
    from pootle_project.models import Project
    from pootle_fs.utils import FSPlugin

    project = Project.objects.get(code="project0")
    new_url = os.path.join(str(tmpdir), "__src__")
    project.config["pootle_fs.fs_url"] = new_url
    plugin = FSPlugin(project)
    os.makedirs(new_url)
    settings.POOTLE_FS_PATH = str(tmpdir)
    return plugin
Пример #17
0
 def handle(self, *args, **kwargs):
     any_configured = False
     for project in Project.objects.order_by("pk"):
         try:
             plugin = FSPlugin(project)
             self.stdout.write("%s\t%s" % (project.code, plugin.fs_url))
             any_configured = True
         except (MissingPluginError, NotConfiguredError):
             pass
     if not any_configured:
         self.stdout.write("No projects configured")
Пример #18
0
def test_fs_cmd(project_fs, capsys):
    call_command("fs")
    out, err = capsys.readouterr()
    expected = []
    for project in Project.objects.order_by("pk"):
        try:
            plugin = FSPlugin(project)
            expected.append("%s\t%s" % (project.code, plugin.fs_url))
        except (MissingPluginError, NotConfiguredError):
            pass
    expected = ("%s\n" % '\n'.join(expected))
    assert out == expected
Пример #19
0
def test_project_fs_instance_bad():

    # needs a Project
    with pytest.raises(TypeError):
        FSPlugin()
    project = Project.objects.get(code="project0")
    # project is not configured
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = "foo"
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = None
    project.config["pootle_fs.fs_url"] = "bar"
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = "foo"
    with pytest.raises(MissingPluginError):
        FSPlugin(project)

    @provider(fs_plugins, sender=Project)
    def provide_fs_plugin(**kwargs):
        return dict(dummyfs=DummyFSPlugin)

    with pytest.raises(MissingPluginError):
        FSPlugin(project)
Пример #20
0
def test_project_fs_instance_bad(english):

    # needs a Project
    with pytest.raises(TypeError):
        FSPlugin()
    project = ProjectDBFactory(source_language=english)
    # project is not configured
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = "foo"
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = None
    project.config["pootle_fs.fs_url"] = "bar"
    with pytest.raises(NotConfiguredError):
        FSPlugin(project)
    project.config["pootle_fs.fs_type"] = "foo"
    with pytest.raises(MissingPluginError):
        FSPlugin(project)

    @provider(fs_plugins, sender=Project)
    def provide_fs_plugin(**kwargs):
        return dict(dummyfs=DummyFSPlugin)

    with pytest.raises(MissingPluginError):
        FSPlugin(project)
Пример #21
0
def __test_plugin_commit_committer(hg_project):
    plugin = FSPlugin(hg_project)

    NEW_COMMITTER_NAME = "New Committer"
    NEW_COMMITTER_EMAIL = "*****@*****.**"

    plugin.pull()
    assert not plugin.config.get("pootle_fs.committer_name")
    assert not plugin.config.get("pootle_fs.committer_email")

    # make some updates
    plugin.push_translations()

    # check that commit message uses system default when not set in config
    with tmp_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.hg.log('-1', '--pretty=%an')
        last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ae')
        hg_config = tmp_repo.config_reader()
        default_user = os.environ["USER"]
        default_email = ("%s@%s" %
                         (default_user, os.environ.get("HOSTNAME", "")))
        assert (last_committer_name == hg_config.get_value(
            "user", "name", default_user))
        assert (last_committer_email == hg_config.get_value(
            "user", "email", default_email))

    # update the committer name/email in config
    plugin.config["pootle_fs.committer_name"] = NEW_COMMITTER_NAME
    plugin.config["pootle_fs.committer_email"] = NEW_COMMITTER_EMAIL

    # make further updates
    plugin.add_translations()
    plugin.sync_translations()

    # test that sync_translations committed with new commit committer
    with tmp_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.hg.log('-1', '--pretty=%cn')
        last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ce')
        assert last_committer_name == NEW_COMMITTER_NAME
        assert last_committer_email == NEW_COMMITTER_EMAIL
Пример #22
0
def test_plugin_instance(project_fs_empty):
    project_fs = project_fs_empty
    assert project_fs.project == project_fs.plugin.project
    assert project_fs.project.local_fs_path.endswith(project_fs.project.code)
    assert project_fs.is_cloned is False
    assert project_fs.resources.stores.exists() is False
    assert project_fs.resources.tracked.exists() is False
    # any instance of the same plugin is equal
    new_plugin = FSPlugin(project_fs.project)
    assert project_fs == new_plugin
    assert project_fs is not new_plugin
    # but the plugin doesnt equate to a cabbage 8)
    assert not project_fs == "a cabbage"
Пример #23
0
def __test_plugin_commit_committer(hg_project):
    plugin = FSPlugin(hg_project)

    NEW_COMMITTER_NAME = "New Committer"
    NEW_COMMITTER_EMAIL = "*****@*****.**"

    plugin.pull()
    assert not plugin.config.get("pootle_fs.committer_name")
    assert not plugin.config.get("pootle_fs.committer_email")

    # make some updates
    plugin.push_translations()

    # check that commit message uses system default when not set in config
    with tmp_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.hg.log('-1', '--pretty=%an')
        last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ae')
        hg_config = tmp_repo.config_reader()
        default_user = os.environ["USER"]
        default_email = (
            "%s@%s"
            % (default_user, os.environ.get("HOSTNAME", "")))
        assert (
            last_committer_name
            == hg_config.get_value("user", "name", default_user))
        assert (
            last_committer_email
            == hg_config.get_value("user", "email", default_email))

    # update the committer name/email in config
    plugin.config["pootle_fs.committer_name"] = NEW_COMMITTER_NAME
    plugin.config["pootle_fs.committer_email"] = NEW_COMMITTER_EMAIL

    # make further updates
    plugin.add_translations()
    plugin.sync_translations()

    # test that sync_translations committed with new commit committer
    with tmp_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.hg.log('-1', '--pretty=%cn')
        last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ce')
        assert last_committer_name == NEW_COMMITTER_NAME
        assert last_committer_email == NEW_COMMITTER_EMAIL
Пример #24
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
Пример #25
0
    def setup_fs(self):
        from pytest_pootle.utils import add_store_fs

        from django.conf import settings

        from pootle_project.models import Project
        from pootle_fs.utils import FSPlugin

        settings.POOTLE_FS_PATH = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY, "__fs_working_dir__")
        os.mkdir(settings.POOTLE_FS_PATH)

        project = Project.objects.get(code="project0")
        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(
                store=store,
                fs_path=plugin.get_fs_path(store.pootle_path),
                synced=True)
Пример #26
0
    def setup_fs(self):
        from pytest_pootle.utils import add_store_fs

        from django.conf import settings

        from pootle_project.models import Project
        from pootle_fs.utils import FSPlugin

        settings.POOTLE_FS_PATH = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY, "__fs_working_dir__")
        os.mkdir(settings.POOTLE_FS_PATH)

        project = Project.objects.get(code="project0")
        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(store=store,
                         fs_path=plugin.get_fs_path(store.pootle_path),
                         synced=True)
Пример #27
0
def dummy_cmd_state():
    from pootle.core.plugin import provider
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    DummyState, DummyCommandPlugin = _get_dummy_state_plugin()

    @provider(fs_plugins, sender=Project, weak=False)
    def plugins_provider_(**kwargs_):
        return dict(dummy_state_cmd=DummyCommandPlugin)

    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummy_state_cmd"
    return FSPlugin(project), DummyState
Пример #28
0
def dummyfs(settings, dummy_fs_getters):
    from pootle.core.plugin import provider
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    @provider(fs_plugins, weak=False)
    def plugin_provider_(**kwargs_):
        return dict(dummyfs=DummyPlugin)

    project = Project.objects.get(code="project0")
    settings.POOTLE_FS_WORKING_PATH = os.sep.join(['', 'tmp', 'foo'])
    project.config["pootle_fs.fs_type"] = "dummyfs"

    return FSPlugin(project)
Пример #29
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")
Пример #30
0
def test_init_fs_project_cmd(capsys, settings, test_fs, tmpdir):
    settings.POOTLE_FS_WORKING_PATH = str(tmpdir)
    fs_path = test_fs.path("data/fs/example_fs/non_gnu_style_minimal/")
    tr_path = "<language_code>/<filename>.<ext>"
    call_command("init_fs_project", "foo", fs_path, tr_path)

    project = Project.objects.get(code='foo')
    assert project is not None

    assert project.config.get('pootle_fs.fs_type') == 'localfs'
    assert project.config.get('pootle_fs.fs_url') == fs_path
    assert project.config.get('pootle_fs.translation_paths')['default'] == tr_path

    assert project.translationproject_set.all().count() > 0
    state = FSPlugin(project).state()
    assert "Nothing to report" in str(state)
Пример #31
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)
Пример #32
0
def project_fs_empty(english, tmpdir, settings):
    from pytest_pootle.factories import ProjectDBFactory

    from pootle_fs.utils import FSPlugin

    project = ProjectDBFactory(source_language=english,
                               code="project_fs_empty")
    settings.POOTLE_FS_WORKING_PATH = str(tmpdir)
    repo_path = os.path.join(str(tmpdir), "__src__")
    if not os.path.exists(repo_path):
        os.mkdir(repo_path)
    project.config["pootle_fs.fs_type"] = "localfs"
    project.config["pootle_fs.fs_url"] = repo_path
    project.config["pootle_fs.translation_mappings"] = {
        "default": "/<language_code>/<dir_path>/<filename>.<ext>"
    }
    return FSPlugin(project)
Пример #33
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
Пример #34
0
def dummy_cmd_response():
    from pootle.core.plugin import provider
    from pootle.core.state import State
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    DummyResponse, DummyCommandPlugin = _get_dummy_api_plugin()

    @provider(fs_plugins, sender=Project, weak=False)
    def plugins_provider_(**kwargs_):
        return dict(dummy_cmd=DummyCommandPlugin)

    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummy_cmd"
    plugin = FSPlugin(project)
    dummy_response = DummyResponse(State(plugin))
    return dummy_response, add_dummy_api_call
Пример #35
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)
Пример #36
0
def dummyfs(settings, no_fs_plugins, no_fs_files):
    from pootle.core.plugin import getter, provider
    from pootle_fs.delegate import fs_file, fs_plugins
    from pootle_fs.files import FSFile
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    @provider(fs_plugins, weak=False)
    def plugin_provider_(**kwargs_):
        return dict(dummyfs=DummyPlugin)

    @getter(fs_file, weak=False, sender=DummyPlugin)
    def fs_files_getter_(**kwargs_):
        return FSFile

    project = Project.objects.get(code="project0")
    settings.POOTLE_FS_WORKING_PATH = "/tmp/foo/"
    project.config["pootle_fs.fs_type"] = "dummyfs"
    return FSPlugin(project)
Пример #37
0
def dummyfs_plugin_no_files(settings, no_fs_plugins, no_fs_files):
    from pootle.core.plugin import provider
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    settings.POOTLE_FS_PATH = "/tmp/foo/"

    class NoFilesDummyPlugin(DummyPlugin):
        def find_translations(self, fs_path=None, pootle_path=None):
            return []

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider(**kwargs):
        return dict(dummyfs=NoFilesDummyPlugin)

    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    plugin = FSPlugin(project)
    return plugin
Пример #38
0
def dummyfs_plugin_no_files(settings, no_complex_po_, dummy_fs_getters):
    from pootle.core.plugin import provider
    from pootle_fs.delegate import fs_plugins
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    settings.POOTLE_FS_WORKING_PATH = os.sep.join(['', 'tmp', 'foo'])

    class NoFilesDummyPlugin(DummyPlugin):
        def find_translations(self, fs_path=None, pootle_path=None):
            return []

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider_(**kwargs_):
        return dict(dummyfs=NoFilesDummyPlugin)

    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    plugin = FSPlugin(project)
    return plugin
Пример #39
0
def project_fs_empty(english, tmpdir, settings):
    from pytest_pootle.factories import ProjectDBFactory

    from pootle.core.delegate import config
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    project = ProjectDBFactory(source_language=english,
                               code="project_fs_empty",
                               treestyle="none")
    settings.POOTLE_FS_PATH = str(tmpdir)
    repo_path = os.path.join(str(tmpdir), "__src__")
    if not os.path.exists(repo_path):
        os.mkdir(repo_path)
    conf = config.get(Project, instance=project)
    conf.set_config("pootle_fs.fs_type", "localfs")
    conf.set_config("pootle_fs.fs_url", repo_path)
    conf.set_config(
        "pootle_fs.translation_paths",
        {"default": "/<language_code>/<dir_path>/<filename>.<ext>"})
    return FSPlugin(project)
Пример #40
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
Пример #41
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()
Пример #42
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)
Пример #43
0
def git_plugin_base(tmpdir, settings):
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project

    with get_dir_util() as dir_util:
        dir_util.copy_tree(settings.POOTLE_FS_PATH, str(tmpdir))
    settings.POOTLE_FS_WORKING_PATH = str(tmpdir)
    for project_code in ["project_0", "project_1"]:
        project = Project.objects.get(code="git_%s" % project_code)
        repo_path = os.path.join(settings.POOTLE_FS_PATH,
                                 "__git_src_%s__" % project_code)

        project.config["pootle_fs.fs_type"] = "git"
        project.config["pootle_fs.fs_url"] = repo_path
        project.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }

        plugin = FSPlugin(project)
        if os.path.exists(project.local_fs_path):
            origin = plugin.repo.remotes.origin
            cw = origin.config_writer
            cw.set("url", plugin.fs_url)
            cw.release()
Пример #44
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>"}
Пример #45
0
def test_fs_plugin_fetch_bad(project0):
    plugin = FSPlugin(project0)
    plugin.clear_repo()

    with pytest.raises(FSStateError):
        plugin.add()
Пример #46
0
def __test_plugin_pull(hg_project_1):
    hg_plugin = FSPlugin(hg_project_1)
    assert hg_plugin.is_cloned is False
    hg_plugin.pull()
    assert hg_plugin.is_cloned is True