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

Textfsm to be manually installed by the user #1085

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -16,6 +16,8 @@ matrix:
python: 3.7
before_install:
- choco install python3 --version=3.7.4
- pip install ntc_templates==1.4.1
- pip install textfsm==0.4.1
env:
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- TRAVIS_PYTHON_VERSION=3.7
Expand Down
1 change: 1 addition & 0 deletions development.txt
Expand Up @@ -6,3 +6,4 @@ nose # http://nose.readthedocs.org/en/latest/
pep8 # https://github.com/jcrocholl/pep8
pyflakes # https://launchpad.net/pyflakes
coveralls # https://coveralls.io/
ntc_templates # user needs to explicitly install this
5 changes: 3 additions & 2 deletions lib/jnpr/junos/device.py
Expand Up @@ -103,8 +103,9 @@ class _Connection(object):
model_dict = {}
with open("/etc/product.conf") as f:
for line in f:
(key, val) = line.strip().split("=")
model_dict[key] = val
if "=" in line:
(key, val) = line.strip().split("=")
model_dict[key] = val

if "model" in model_dict and model_dict["model"] in [
"crpd",
Expand Down
20 changes: 16 additions & 4 deletions lib/jnpr/junos/factory/cmdtable.py
Expand Up @@ -16,7 +16,14 @@
from jnpr.junos.factory.to_json import TableJSONEncoder

from jinja2 import Template
from ntc_templates import parse as ntc_parse

HAS_NTC_TEMPLATE = False
try:
from ntc_templates import parse as ntc_parse

HAS_NTC_TEMPLATE = True
except:
pass

import logging

Expand Down Expand Up @@ -153,9 +160,14 @@ def get(self, *vargs, **kvargs):
self.data = self.xml.text

if self.USE_TEXTFSM:
self.output = self._parse_textfsm(
platform=self.PLATFORM, command=self.GET_CMD, raw=self.data
)
if HAS_NTC_TEMPLATE:
self.output = self._parse_textfsm(
platform=self.PLATFORM, command=self.GET_CMD, raw=self.data
)
else:
raise ImportError(
"ntc_template is missing. Need to be installed explicitly."
)
else:
# state machine
sm = StateMachine(self)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Expand Up @@ -10,4 +10,3 @@ pyserial
yamlordereddictloader
pyparsing
transitions
ntc_templates
10 changes: 1 addition & 9 deletions setup.py
@@ -1,19 +1,10 @@
from setuptools import setup, find_packages
import sys
import versioneer

# parse requirements
req_lines = [line.strip() for line in open("requirements.txt").readlines()]
install_reqs = list(filter(None, req_lines))

# refer: https://github.com/Juniper/py-junos-eznc/issues/1015
# should be removed when textfsm releases >=1.1.1
if sys.platform == "win32":
if "ntc_templates" in install_reqs:
install_reqs.remove("ntc_templates")
install_reqs.append("ntc_templates==1.4.1")
install_reqs.append("textfsm==0.4.1")

setup(
name="junos-eznc",
namespace_packages=["jnpr"],
Expand Down Expand Up @@ -51,6 +42,7 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down