示例#1
0
    def test_load_basic(self, tmpdir):
        tracker_obj = Tracker(nodecreator=FakeNodeCreator(),
                skeleton=False)
        f = tmpdir.join('life')
        with f.open("wb") as w:
            w.write((
                "firstchild: \u2028args\n"
                "    secondchild: \u2028other args\n"
                "        @option: \u2028data\n"
                "        thirdchild: \u2028herp derp\n"
                "    fourthchild: \u2028ark dark\n"
            ).encode("utf-8"))
        tracker_obj.load(str(tmpdir))

        root = tracker_obj.root
        root_child0 = root.children.next_neighbor
        assert root_child0.id in root.ids
        assert len(root_child0.id) == 5
        assert root_child0.text == "\u2028args"
        assert root_child0.node_type == "firstchild"

        root_child0_child0 = root_child0.children.next_neighbor
        assert root_child0_child0.id in root.ids
        assert len(root_child0_child0.id) == 5
        assert root_child0_child0.text == "\u2028other args"
        assert root_child0_child0.node_type == "secondchild"
        assert root_child0_child0.metadata["option"] == "\u2028data"

        root_child0_child0_child0 = root_child0_child0.children.next_neighbor
        assert root_child0_child0_child0.text == "\u2028herp derp"
        assert root_child0_child0_child0.node_type == "thirdchild"

        root_child0_child1 = root_child0_child0.next_neighbor
        assert root_child0_child1.text == "\u2028ark dark"
        assert root_child0_child1.node_type == "fourthchild"
示例#2
0
def main(filename):
    tracker = Tracker()
    try:
        reader = open(filename, "r")
    except IOError:
        pass
    else:
        tracker.load(reader)

    commandline = CommandLineInterface(tracker)

    while True:
        try:
            line = raw_input(commandline.prompt()).strip()

            commandline.command(None, line)
        except (KeyboardInterrupt, EOFError, ExitMainloop) as e:
            print
            break
        except Exception:
            print xtraceback.XTraceback(*sys.exc_info(), color=False)

    tracker.save(open(filename, "w"))