Exemple #1
0
    def process_lines(self, haml_lines):
        root = RootNode()
        line_iter = iter(haml_lines)

        haml_node=None
        for line_number, line in enumerate(line_iter):
            node_lines = line

            # Check for multi-line string when parent is not a FilterNode
            if not isinstance(root.parent( HamlNode(line) ), FilterNode):
                if line.count('{') - line.count('}') == 1:
                    start_multiline=line_number # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                        except StopIteration:
                            raise Exception('No closing brace found for multi-line HAML beginning at line %s' % (start_multiline+1))
                        node_lines += line

            # Blank lines
            if haml_node is not None and len(node_lines.strip()) == 0:
                haml_node.newlines += 1
            else:
                haml_node = create_node(node_lines)
                root.add_node(haml_node)
        return root.render()
Exemple #2
0
 def process_lines(self, haml_lines):
     root = RootNode()
     line_iter = iter(haml_lines)
     for line in line_iter:
         node_lines = line
         if MULTILINE_ATTR_ELEMENT_REGEX.match(line.strip()):
             while "}" not in line:
                 line = line_iter.next()
                 node_lines += line
         haml_node = create_node(node_lines)
         root.add_node(haml_node)
     return root.render()
Exemple #3
0
    def process_lines(self, haml_lines, options=None):
        root = RootNode()
        line_iter = iter(haml_lines)

        haml_node = None
        for line_number, line in enumerate(line_iter):
            node_lines = line

            if not root.parent_of(HamlNode(line)).inside_filter_node():
                if line.count('{') - line.count('}') == 1:
                    start_multiline = line_number  # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                        except StopIteration:
                            raise Exception(
                                'No closing brace found for multi-line HAML beginning at line %s'
                                % (start_multiline + 1))
                        node_lines += line

            # Blank lines
            if haml_node is not None and len(node_lines.strip()) == 0:
                haml_node.newlines += 1
            else:
                haml_node = create_node(node_lines)
                if haml_node:
                    root.add_node(haml_node)

        if options and options.debug_tree:
            return root.debug_tree()
        else:
            return root.render()
Exemple #4
0
class Parser():
    def __init__(self, md, template, mdFilename):
        self._md = md
        self._template = template
        self.tree = RootNode(mdFilename, template)

        self._parseMD()

    def _parseMD(self, ):
        root = self.tree
        parent = root
        level = 0
        for b in self._md.children:
            typeB = type(b)
            if typeB == Heading:
                if b.level == level:
                    parent = RootNode.createFromToken(b, parent.parent)
                elif b.level > level:
                    # Here, we take the assumption that the level heading is good,
                    # like 1, 1.1, 1.1.1, 1.2, 2, 2.1, 2.2, 2.2.1, 2.2.2, 2.2.2.1, 2.3, not like 1, 1.1.1, 1.2.
                    level = b.level
                    parent = RootNode.createFromToken(b, parent)
                elif b.level < level:
                    for _ in range(0, level - b.level + 1):
                        parent = parent.parent
                    level = b.level
                    parent = RootNode.createFromToken(b, parent)
            else:
                e = RootNode.createFromToken(b, parent)

    def generateDocx(self):
        return self.tree.generate()

    def finalize(self, tpl):
        self.tree.finalizeImages(tpl)

    def __str__(self):
        res = ""
        for pre, _, node in RenderTree(self.tree):
            treestr = u"%s%s" % (pre, node)
            res += treestr.ljust(8) + "\n"
        return res
Exemple #5
0
 def _parseMD(self, ):
     root = self.tree
     parent = root
     level = 0
     for b in self._md.children:
         typeB = type(b)
         if typeB == Heading:
             if b.level == level:
                 parent = RootNode.createFromToken(b, parent.parent)
             elif b.level > level:
                 # Here, we take the assumption that the level heading is good,
                 # like 1, 1.1, 1.1.1, 1.2, 2, 2.1, 2.2, 2.2.1, 2.2.2, 2.2.2.1, 2.3, not like 1, 1.1.1, 1.2.
                 level = b.level
                 parent = RootNode.createFromToken(b, parent)
             elif b.level < level:
                 for _ in range(0, level - b.level + 1):
                     parent = parent.parent
                 level = b.level
                 parent = RootNode.createFromToken(b, parent)
         else:
             e = RootNode.createFromToken(b, parent)
Exemple #6
0
    def process_lines(self, haml_lines):
        root = RootNode()
        line_iter = iter(haml_lines)

        for line_number, line in enumerate(line_iter):
            node_lines = line

            # Check for multi-line only when last node isn't FilterNode or when last node isn't parent of this node
            if (not(len(root.internal_nodes)>0 and isinstance(root.internal_nodes[-1], FilterNode))) or not root._should_go_inside_last_node(HamlNode(line)):
                if line.count('{') - line.count('}') == 1:
                    start_multiline=line_number # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                        except StopIteration:
                            raise Exception('No closing brace found for multi-line HAML beginning at line %s' % (start_multiline+1))
                        node_lines += line
            haml_node = create_node(node_lines)
            root.add_node(haml_node)
        return root.render()
Exemple #7
0
    def process_lines(self, haml_lines):
        root = RootNode(**self.options_dict)
        line_iter = iter(haml_lines)

        haml_node=None
        for line_number, line in enumerate(line_iter):
            node_lines = line

            if not root.parent_of(HamlNode(line)).inside_filter_node():
                if line.count('{') - line.count('}') == 1:
                    start_multiline=line_number # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                        except StopIteration:
                            raise Exception('No closing brace found for multi-line HAML beginning at line %s' % (start_multiline+1))
                        node_lines += line

            # Blank lines
            if haml_node is not None and len(node_lines.strip()) == 0:
                haml_node.newlines += 1
            else:
                haml_node = create_node(node_lines)
                if haml_node:
                    root.add_node(haml_node)

        if self.options_dict and self.options_dict.get('debug_tree'):
            return root.debug_tree()
        else:
            return root.render()
Exemple #8
0
    def process_lines(self, haml_lines):
        root = RootNode()
        line_iter = iter(haml_lines)

        haml_node = None
        for line_number, line in enumerate(line_iter):
            node_lines = line

            # Check for multi-line string when parent is not a FilterNode
            if not isinstance(root.parent(HamlNode(line)), FilterNode):
                if line.count('{') - line.count('}') == 1:
                    start_multiline = line_number  # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                        except StopIteration:
                            raise Exception(
                                'No closing brace found for multi-line HAML beginning at line %s'
                                % (start_multiline + 1))
                        node_lines += line

            # Blank lines
            if haml_node is not None and len(node_lines.strip()) == 0:
                haml_node.newlines += 1
            else:
                haml_node = create_node(node_lines)
                root.add_node(haml_node)
        return root.render()
Exemple #9
0
def createRestApi():
    """Create the REST API URL hierarchy"""
    siteRoot = RootNode()

    jobWrapper = guard.HTTPAuthSessionWrapper(Portal(JobRealm(), [JobDBChecker(db)]), [guard.BasicCredentialFactory("thundercloud job management")])
    siteRoot.putChild("job", jobWrapper)
  
    # slave tree needs specific authentication
    slaveWrapper = guard.HTTPAuthSessionWrapper(Portal(SlaveRealm(), [SlaveDBChecker(db)]), [guard.BasicCredentialFactory("thundercloud slave management")])
    siteRoot.putChild("slave", slaveWrapper)

    return server.Site(siteRoot)
Exemple #10
0
    def process_lines(self, haml_lines):
        root = RootNode(**self.options_dict)
        line_iter = iter(haml_lines)

        haml_node=None
        for line_number, line in enumerate(line_iter):
            node_lines = line

            # support for line breaks ("\" symbol at the end of line)
            while node_lines.rstrip().endswith("\\"):
                node_lines = node_lines.rstrip()[:-1]
                try:
                    line = line_iter.next()
                except StopIteration:
                    raise Exception(
                        "Line break symbol '\\' found at the last line %s" \
                        % line_number
                    )
                node_lines += line

            if not root.parent_of(HamlNode(line)).inside_filter_node():
                if line.count('{') - line.count('}') == 1:
                    start_multiline=line_number # For exception handling

                    while line.count('{') - line.count('}') != -1:
                        try:
                            line = line_iter.next()
                            # support for line breaks inside Node parameters
                            if line.rstrip().endswith("\\"):
                                line = line.rstrip()[:-1]
                        except StopIteration:
                            raise Exception('No closing brace found for multi-line HAML beginning at line %s' % (start_multiline+1))
                        node_lines += line

            # Blank lines
            if haml_node is not None and len(node_lines.strip()) == 0:
                haml_node.newlines += 1
            else:
                haml_node = create_node(node_lines)
                if haml_node:
                    root.add_node(haml_node)

        if self.options_dict and self.options_dict.get('debug_tree'):
            return root.debug_tree()
        else:
            return root.render()
Exemple #11
0
 def process_lines(self, haml_lines):
     root = RootNode()
     for line in haml_lines:
         haml_node = create_node(line)
         root.add_node(haml_node)
     return root.render()
Exemple #12
0
from status import StatusApiTree
from job import JobApiTree

from twisted.web.resource import Resource

from nodes import RootNode, LeafNode


class Die(LeafNode):
    def GET(self, request):
        from twisted.internet import reactor

        reactor.stop()


siteRoot = RootNode()
siteRoot.putChild("", RootNode())
siteRoot.putChild("status", StatusApiTree)
siteRoot.putChild("job", JobApiTree)
siteRoot.putChild("die", Die())
Exemple #13
0
    def __init__(self, md, template, mdFilename):
        self._md = md
        self._template = template
        self.tree = RootNode(mdFilename, template)

        self._parseMD()
Exemple #14
0
 def process_lines(self, haml_lines):
     root = RootNode()
     for line in haml_lines:
         haml_node = create_node(line)
         root.add_node(haml_node)
     return root.render()
Exemple #15
0
from nodes import RootNode
from nodes import LeafNode

from twisted.web.resource import Resource

class HeartBeat(LeafNode):
    def GET(self, request):
        return True
    
class Jobs(LeafNode):
    def GET(self, request):
        return {"jobs": 0}
    


StatusApiTree = RootNode()
StatusApiTree.putChild("", RootNode())
StatusApiTree.putChild("heartbeat", HeartBeat())
StatusApiTree.putChild("jobs", Jobs())
Exemple #16
0
from status import StatusApiTree
from job import JobApiTree

from twisted.web.resource import Resource

from nodes import RootNode, LeafNode


class Die(LeafNode):
    def GET(self, request):
        from twisted.internet import reactor
        reactor.stop()


siteRoot = RootNode()
siteRoot.putChild("", RootNode())
siteRoot.putChild("status", StatusApiTree)
siteRoot.putChild("job", JobApiTree)
siteRoot.putChild("die", Die())