Skip to main content

Create nodes as specified in the tree text.

Project description

ja

TexTree

Create nodes as specified in the tree text.

Features

  • Compatible with python2,3
  • Data can be assigned to nodes
  • Convert between text and node objects

Requirement

  • 2019-12-26
  • Raspbierry Pi 4 Model B Rev 1.2
  • Raspbian buster 10.0 2019-09-26 setup
  • bash 5.0.3(1)-release
  • Python 2.7.16
  • Python 3.7.3

Installation

pip install textree

Usage

Foundations

Convert from text to node object.

import textree
tree_text = """
A
	A1
		A11
			A111
			A112
	A2
B
"""
tree = TexTree()
root = tree.to_node(tree_text)
print(root, root.Name)
for node in tree.Nodes:
    print(node.Line)
print(tree.to_text())

Reference

Convert between text and objects.

root = tree.to_node(tree_text)
       tree.to_text()

Reference and assignment.

node.Name
node.Parent
node.Children
node.Name = 'NewName'
node.Parent = Node('Parent')
node.Children.append(Node('Child'))

Move.

node.to_first()
node.to_last()
node.to_next()
node.to_prev()

Get.

Node.Path.select(root, 'A/A1/A11')
Node.Path.select(A, 'A1/A11')

Insertion / deletion.

node.insert_first(Node('new'))
node.insert_last(Node('new'))
node.insert_next(Node('new'))
node.insert_prev(Node('new'))
node.delete()

Update.

node = Node.Path.select(root, 'A/A1/A11')
node.Name = 'UpdateName'

There are many others. Refer to the code or API list for details.

Attribute of Node

Attributes can be assigned to the same line.

import textree
tree_text = """
A	attrA
	A1	attrA1
		A11	attrA11
			A111	attrA111
			A112	attrA112
	A2	attrA2
B	attrB
"""
tree = TexTree()
root = tree.to_node(tree_text)
print(root, root.Name)
for node in tree.Nodes:
    print(node.Name, node,Attr)

Attribute of RootNode

Attributes can be assigned to RootNode.

import textree
tree_text = """
<ROOT>	root_attr
A	attrA
	A1	attrA1
		A11	attrA11
			A111	attrA111
			A112	attrA112
	A2	attrA2
B	attrB
"""
tree = TexTree()
root = tree.to_node(tree_text)
print(root, root.Name, root.Attr)
for node in tree.Nodes:
    print(node.Name, node,Attr)

Deserialization of attributes

The user can embed the attribute analysis code freely. Of course you can also write code to serialize to text.

The following code gives the node my_name.

class MyNodeDeserializer(NodeDeserializer):
    def deserialize(self, ana, parent, parents=Node):
        node = Node(ana.Line, parent=parent)
        node.my_name = 'My name is ' + node.Name
        return node
tree = TexTree(node_deserializer=MyNodeDeserializer())
root = tree.to_node(tree_text)
for node in tree.Nodes:
    print(node.my_name)
class MyNodeAttributeSerializer(NodeAttributeSerializer):
    def serialize(self, attr): return 'my_name=' + attr
tree = TexTree(node_deserializer=MyNodeDeserializer(), node_serializer=NodeSerializer(MyNodeAttributeSerializer()))
root = tree.to_node(tree_text)
for node in tree.Nodes:
    print(node.my_name)
print(tree.to_text())

Note

  • Alpha version. Checking installation

Author

 ytyaru

  • github
  • hatena
  • mastodon

License

This software is AGPLv3 licensed. (GNU Affero General Public License v3) agpl-3.0

agpl-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textree-0.0.1.tar.gz (41.9 kB view details)

Uploaded Source

Built Distributions

textree-0.0.1-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

textree-0.0.1-py2-none-any.whl (41.9 kB view details)

Uploaded Python 2

File details

Details for the file textree-0.0.1.tar.gz.

File metadata

  • Download URL: textree-0.0.1.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3

File hashes

Hashes for textree-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e7f5678aded8d91ac7939f73535bda2c0e516936bdc2889c1fb525aab47afcc8
MD5 2260f9ddc4390096f532d8d769f8c987
BLAKE2b-256 1a877b4e0afcf2ac8434c180df713d8de30bb4c28a390ed0445bd197b9bab00c

See more details on using hashes here.

File details

Details for the file textree-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: textree-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3

File hashes

Hashes for textree-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 429b8597ff6a9235fa31c18db572c697885383f5ed46f53f693b9cd6e995081c
MD5 5db195f8edf3cb49118dc357d8bf1a65
BLAKE2b-256 a459abe690a331aa3a85e60a8838e3cc2e11ae73e5913b553787d5657c79296b

See more details on using hashes here.

File details

Details for the file textree-0.0.1-py2-none-any.whl.

File metadata

  • Download URL: textree-0.0.1-py2-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3

File hashes

Hashes for textree-0.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 e0759862aff56b6ea1656ce1b10d26188250767e340d31892da0903120632c03
MD5 a51c7accf9c13f5f9b93c7f22d07e85d
BLAKE2b-256 e65f95fe9a70fdc6ba177654490815dc2a0c574806ac413f48f5ef71d5bf88b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page