예제 #1
0
def template(file):
    path = resource_filename(__name__, os.path.join('templates', file))

    if not os.path.isfile(path):
        raise error.Bug("Could not find template {}".format(path))
    content = util.file_read(path)
    return string.Template(content)
예제 #2
0
파일: entity.py 프로젝트: jloehel/xii
    def template(self, key):
        """get template
        Get a template which was added to the filesystem in the corresponding
        'templates/' directory.

        Example:
        ::

            # path: components/node/attributes/image/templates/disk.xml
            # in image attribute
            self.template("disk.xml")
            < Template('...') >

            # path: components/node/templates/qemu/simple.xml
            # in node component
            self.template("qemu/simple.xml")
            < Template('...') >

        Args:
            key: Key path to template

        Returns:
            The specified template

        Throws:
            error.Bug if template could not found
        """
        if key not in self._templates:
            raise error.Bug("Could not find template {}".format(key))

        content = util.file_read(self._templates[key])
        return string.Template(content)
예제 #3
0
파일: entity.py 프로젝트: xii/xii
    def template(self, key):
        """get template
        Get a template which was added to the filesystem in the corresponding
        'templates/' directory.

        Example:
        ::

            # path: components/node/attributes/image/templates/disk.xml
            # in image attribute
            self.template("disk.xml")
            < Template('...') >

            # path: components/node/templates/qemu/simple.xml
            # in node component
            self.template("qemu/simple.xml")
            < Template('...') >

        Args:
            key: Key path to template

        Returns:
            The specified template

        Throws:
            error.Bug if template could not found
        """
        if key not in self._templates:
            raise error.Bug("Could not find template {}".format(key))

        content = util.file_read(self._templates[key])
        return string.Template(content)
예제 #4
0
파일: test_util.py 프로젝트: jloehel/xii
def test_file_read_invalid(monkeypatch):
    monkeypatch.setattr("os.open", fake_invalid_open())

    with raises(error.NotFound):
        util.file_read("/invalid/directory/file")
예제 #5
0
파일: test_util.py 프로젝트: jloehel/xii
def test_file_read(monkeypatch):
    monkeypatch.setattr("__builtin__.open", fake_open(u"test stream", "/tmp/test", "r"))
    assert(util.file_read("/tmp/test") == "test stream")