コード例 #1
0
    def load_backup(self) -> Optional[str]:
        if config.local_copy_dir is None:
            return None

        try:
            res = resource_string(self.local_copy_fn)
            if isinstance(res, bytes):
                return res.decode('utf-8')
            return res
        except IOError as ex:
            log.warning(
                "Caught an exception trying to load local backup for {} via {}: {}"
                .format(self.url, self.local_copy_fn, ex))
            return None
コード例 #2
0
def plumbing(fn: str) -> Plumbing:
    """
    Create a new plumbing instance by parsing yaml from the filename.

    :param fn: A filename containing the pipeline.
    :return: A plumbing object

    This uses the resource framework to locate the yaml file which means that pipelines can be shipped as plugins.
    """
    pid = os.path.splitext(fn)[0]
    ystr = resource_string(fn)
    if ystr is None:
        raise PipeException("Plumbing not found: %s" % fn)
    pipeline = yaml.safe_load(ystr)

    return Plumbing(pipeline=pipeline, pid=pid)
コード例 #3
0
ファイル: __init__.py プロジェクト: johanlundberg/pyFF
def plumbing(fn):
    """
Create a new plumbing instance by parsing yaml from the filename.

:param fn: A filename containing the pipeline.
:return: A plumbing object

This uses the resource framework to locate the yaml file which means that pipelines can be shipped as plugins.
    """
    id = os.path.splitext(fn)[0]
    ystr = resource_string(fn)
    if ystr is None:
        raise PipeException("Plumbing not found: %s" % fn)
    pipeline = yaml.safe_load(ystr)

    return Plumbing(pipeline=pipeline, id=id)
コード例 #4
0
    def test_resource_string(self):
        assert(resource_string("missing") is None)
        assert(resource_string("missing", "gone") is None)
        assert(resource_string('test/data/empty.txt') == 'empty')
        assert(resource_string('empty.txt', 'test/data') == 'empty')
        tmp = tempfile.NamedTemporaryFile('w').name
        with open(tmp, "w") as fd:
            fd.write("test")

        try:
            assert(resource_string(tmp) == "test")
            (d, fn) = os.path.split(tmp)
            assert(resource_string(fn, d) == "test")
        except IOError, ex:
            raise ex
コード例 #5
0
    def test_resource_string(self):
        assert(resource_string("missing") is None)
        assert(resource_string("missing", "gone") is None)
        assert(resource_string('test/data/empty.txt') == six.b('empty'))
        assert(resource_string('empty.txt', 'test/data') == six.b('empty'))
        tmp = tempfile.NamedTemporaryFile('w').name
        with open(tmp, "w") as fd:
            fd.write("test")

        try:
            print(resource_string(tmp))
            assert(resource_string(tmp) == 'test')
            (d, fn) = os.path.split(tmp)
            assert(resource_string(fn, d) == 'test')
        except IOError as ex:
            raise ex
        finally:
            try:
                os.unlink(tmp)
            except Exception:
                pass
コード例 #6
0
ファイル: test_utils.py プロジェクト: leifj/pyFF
    def test_resource_string(self):
        assert(resource_string("missing") is None)
        assert(resource_string("missing", "gone") is None)
        assert(resource_string('test/data/empty.txt') == six.b('empty'))
        assert(resource_string('empty.txt', 'test/data') == six.b('empty'))
        tmp = tempfile.NamedTemporaryFile('w').name
        with open(tmp, "w") as fd:
            fd.write("test")

        try:
            print(resource_string(tmp))
            assert(resource_string(tmp) == 'test')
            (d, fn) = os.path.split(tmp)
            assert(resource_string(fn, d) == 'test')
        except IOError as ex:
            raise ex
        finally:
            try:
                os.unlink(tmp)
            except Exception:
                pass
コード例 #7
0
ファイル: mdx.py プロジェクト: salaun-renater/pyFF
 def favicon_ico(self):
     cherrypy.response.headers['Content-Type'] = 'image/x-icon'
     return resource_string('favicon.ico', "site/static/icons")
コード例 #8
0
 def favicon_ico(self):
     """Returns the pyff icon (the alchemic symbol for sublimation).
     """
     cherrypy.response.headers['Content-Type'] = 'image/x-icon'
     return resource_string('favicon.ico', "site/static/icons")
コード例 #9
0
ファイル: mdx.py プロジェクト: lhoekenga/pyFF
 def favicon_ico(self):
     """Returns the pyff icon (the alchemic symbol for sublimation).
     """
     cherrypy.response.headers['Content-Type'] = 'image/x-icon'
     return resource_string('favicon.ico', "site/static/icons")