Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: linenumber match function #96

Open
Yoyasp opened this issue Jan 20, 2023 · 0 comments
Open

Request: linenumber match function #96

Yoyasp opened this issue Jan 20, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Yoyasp
Copy link

Yoyasp commented Jan 20, 2023

First of all thank you soo much for creating and maintaining this repo.

I am looking for a match function/indicator that saves the linenumber of a matching variable.

My usecase is compliancy checking where i would like to highlight configuration lines in the original data.

from ttp import ttp

data_to_parse = """
interface Loopback0
 description Router-id-loopback
 ip address 192.168.0.113/24
!
interface Vlan778
 description CPE_Acces_Vlan
 ip address 2002::fd37/124
 ip vrf CPE1
!
"""

ttp_template = """
interface {{ interface | linenumber('INTERFACE_LINENUMBER')}}
 ip address {{ ip }}/{{ mask }}
 description {{ description }}
 ip vrf {{ vrf | linenumber('VRF_LINENUMBER') }}
"""

# create parser object and parse data using template:
parser = ttp(data=data_to_parse, template=ttp_template)
parser.parse()

would result in:

[
    [
        {
            "description": "Router-id-loopback",
            "interface": "Loopback0",
            "INTERFACE_LINENUMBER": 1,
            "ip": "192.168.0.113",
            "mask": "24"
        },
        {
            "description": "CPE_Acces_Vlan",
            "interface": "Vlan778",
            "ip": "2002::fd37",
            "mask": "124",
            "vrf": "CPE1",
            "VRF_LINENUMBER": 8,
            "INTERFACE_LINENUMBER": 5
        }
    ]
]
@dmulyalin dmulyalin added the enhancement New feature or request label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants