Example #1
0
def _register_plugin(name="example", plugin=None, clear=True):
    if clear:
        _clear_plugins()

    from pootle_fs import Plugin, plugins, FSFile

    class ExampleFSFile(FSFile):
        @property
        def latest_hash(self):
            if self.exists:
                return md5(str(os.stat(self.file_path).st_mtime)).hexdigest()

    class ExamplePlugin(Plugin):

        file_class = ExampleFSFile
        _pulled = False

        def get_latest_hash(self):
            return md5(str(datetime.now())).hexdigest()

        def push(self, response):
            if os.path.exists(self.fs.url):
                shutil.rmtree(self.fs.url)
            shutil.copytree(self.local_fs_path, self.fs.url)
            return response

        def pull(self):
            if os.path.exists(self.local_fs_path):
                shutil.rmtree(self.local_fs_path)
            shutil.copytree(self.fs.url, self.local_fs_path)

    ExamplePlugin.name = name
    plugins.register(plugin or ExamplePlugin)
    return ExamplePlugin
Example #2
0
def test_register_plugin():
    _clear_plugins()

    class ExamplePlugin(Plugin):
        name = "example"

    plugins.register(ExamplePlugin)

    assert "example" in plugins
    assert plugins["example"] == ExamplePlugin
Example #3
0
def _register_plugin(name="example", plugin=None, clear=True):
    if clear:
        _clear_plugins()

    from pootle_fs import Plugin, plugins, FSFile

    class ExampleFSFile(FSFile):

        @property
        def latest_hash(self):
            if self.exists:
                return md5(str(os.stat(self.file_path).st_mtime)).hexdigest()

    class ExamplePlugin(Plugin):

        file_class = ExampleFSFile
        _pulled = False

        def get_latest_hash(self):
            return md5(str(datetime.now())).hexdigest()

        def push(self, response):
            if os.path.exists(self.fs.url):
                shutil.rmtree(self.fs.url)
            shutil.copytree(
                self.local_fs_path,
                self.fs.url)
            return response

        def pull(self):
            if os.path.exists(self.local_fs_path):
                shutil.rmtree(self.local_fs_path)
            shutil.copytree(
                self.fs.url,
                self.local_fs_path)

    ExamplePlugin.name = name
    plugins.register(plugin or ExamplePlugin)
    return ExamplePlugin