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

Code changes to upgrade code having deprecation warning in latest python #1062

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions INSTALL-FEDORA-CENTOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ Operating Systems

#### Step 1: Install Python and PIP

##### For Python 2.x:
###### For Fedora:
sudo yum install python-pip python-devel
###### For CentOS:
sudo yum install python-devel
wget https://bootstrap.pypa.io/get-pip.py -O - | sudo python

##### For Python 3.x:
###### For Fedora:
sudo yum install python3-devel
Expand All @@ -32,9 +25,6 @@ Operating Systems

#### Step 2: Install Junos PyEZ

##### For Python 2.x:
sudo pip install junos-eznc

##### For Python 3.x:
sudo pip3 install junos-eznc

Expand All @@ -57,11 +47,6 @@ Development code can be installed directly from GitHub based on any branch, comm

#### Step 4b: Install Junos PyEZ from GitHub

##### For Python 2.x:
sudo pip install git+https://github.com/Juniper/py-junos-eznc.git
or
sudo pip install git+https://github.com/Juniper/py-junos-eznc.git@<branch,tag,commit>

##### For Python 3.x:
sudo pip3 install git+https://github.com/Juniper/py-junos-eznc.git
or
Expand Down
6 changes: 0 additions & 6 deletions INSTALL-FREEBSD.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ FreeBSD contains py-junos-eznc in its official repositories. It could be install

## Installing from binary packages.

##### For Python 2.7
sudo pkg install py27-junos-eznc

##### For Python 3.6
sudo pkg install py36-junos-eznc

## Installing from ports collection

#### For Python 2.7
sudo make -C /usr/ports/net-mgmt/py-junos-eznc install clean FLAVOR=py27

#### For Python 3.6
sudo make -C /usr/ports/net-mgmt/py-junos-eznc install clean FLAVOR=py36

Expand Down
13 changes: 6 additions & 7 deletions lib/jnpr/junos/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print("unable to find command, tried {}".format(commands))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -186,11 +186,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
refs = {r.strip() for r in refnames.strip("()").split(",")}
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
Expand All @@ -199,7 +199,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r"\d", r)])
tags = {r for r in refs if re.search(r"\d", r)}
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
Expand Down Expand Up @@ -302,9 +302,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
full_tag,
tag_prefix,
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
full_tag, tag_prefix,
)
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
Expand Down
2 changes: 1 addition & 1 deletion lib/jnpr/junos/cfg/user_ssh_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def _r_list(self):

def _r_catalog(self):
# no catalog but the keys
self._rcatalog = dict((k, None) for k in self.list)
self._rcatalog = {k: None for k in self.list}
10 changes: 5 additions & 5 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def re_name(self):
if re_name is None:
# Still haven't figured it out. Is this a bsys?
for re_state in self.facts["current_re"]:
match = re.search("^re\d+$", re_state)
match = re.search(r"^re\d+$", re_state)
if match:
re_string = "bsys-" + match.group(0)
if re_string in self.facts["hostname_info"].keys():
Expand Down Expand Up @@ -671,7 +671,7 @@ def cli_to_rpc_string(self, command):
value = "'" + child.text + "'"
else:
value = "True"
arguments.append("%s=%s" % (key, value))
arguments.append("{}={}".format(key, value))
if arguments:
rpc_string += ", ".join(arguments)
rpc_string += ")"
Expand Down Expand Up @@ -879,7 +879,7 @@ def execute(self, rpc_cmd, ignore_warning=False, **kvargs):
except ValueError as ex:
# when data is {}{.*} types
if str(ex).startswith("Extra data"):
return json.loads(re.sub("\s?{\s?}\s?", "", rpc_rsp_e.text))
return json.loads(re.sub(r"\s?{\s?}\s?", "", rpc_rsp_e.text))
else:
raise JSONLoadError(ex, rpc_rsp_e.text)
else:
Expand All @@ -906,7 +906,7 @@ def execute(self, rpc_cmd, ignore_warning=False, **kvargs):
# protocol: operation-failed
# error: device asdf not found
# </rpc-reply>
if rpc_rsp_e.text is not None and rpc_rsp_e.text.strip() is not "":
if rpc_rsp_e.text is not None and rpc_rsp_e.text.strip() != "":
return rpc_rsp_e
# no children, so assume it means we are OK
return True
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def open(self, *vargs, **kvargs):
"""

auto_probe = kvargs.get("auto_probe", self._auto_probe)
if auto_probe is not 0:
if auto_probe != 0:
if not self.probe(auto_probe):
raise EzErrors.ProbeError(self)

Expand Down
6 changes: 3 additions & 3 deletions lib/jnpr/junos/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=Non
self.message = (
"\n".join(
[
"%s: %s" % (err["severity"].strip(), err["message"].strip())
"{}: {}".format(err["severity"].strip(), err["message"].strip())
for err in errs
if err["message"] is not None and err["severity"] is not None
]
Expand Down Expand Up @@ -329,12 +329,12 @@ def __init__(self, exception, rpc_content):
self.ex_msg = str(exception)
self.rpc_content = rpc_content
self.offending_line = ""
obj = re.search("line (\d+)", self.ex_msg)
obj = re.search(r"line (\d+)", self.ex_msg)
if obj:
line_no = int(obj.group(1))
rpc_lines = rpc_content.splitlines()
for line in range(line_no - 3, line_no + 2):
self.offending_line += "%s: %s\n" % (line + 1, rpc_lines[line])
self.offending_line += "{}: {}\n".format(line + 1, rpc_lines[line])

def __repr__(self):
if self.offending_line:
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/junos/factcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __getitem__(self, key):
if key not in self._callbacks:
# Not a fact that we know how to provide.
raise KeyError(
"%s: There is no function to gather the %s fact" % (key, key)
"{}: There is no function to gather the {} fact".format(key, key)
)
if key not in self._cache:
# A known fact, but not yet cached. Go get it and cache it.
Expand Down Expand Up @@ -215,7 +215,7 @@ def __str__(self):
string = ""
for key in sorted(self):
if not key.startswith("_"):
current = "'%s': %s" % (key, repr(self.get(key)))
current = "'{}': {}".format(key, repr(self.get(key)))
if string:
string = ", ".join([string, current])
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/jnpr/junos/factory/cfgtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _validate_min_max_value(field_name, value, opt):
# <unit operation="delete"/>
pass
elif isinstance(value, (list, tuple, dict, set)):
raise ValueError("%s value is invalid %s\n" % (field_name, value))
raise ValueError("{} value is invalid {}\n".format(field_name, value))
else:
if "type" in opt:
_validate_type(field_name, value, opt)
Expand Down
10 changes: 5 additions & 5 deletions lib/jnpr/junos/factory/cmdtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, dev=None, raw=None, path=None, template_dir=None):
# -------------------------------------------------------------------------

def get(self, *vargs, **kvargs):
"""
r"""
Retrieve the XML (string blob under <output> tag of table data from the
Device instance and returns back the Table instance - for call-chaining
purposes.
Expand Down Expand Up @@ -151,7 +151,7 @@ def get(self, *vargs, **kvargs):
except RpcError:
with StartShell(self.D) as ss:
ret = ss.run(
'cprod -A %s -c "%s"' % (self.TARGET, self.GET_CMD)
'cprod -A {} -c "{}"'.format(self.TARGET, self.GET_CMD)
)
if ret[0]:
self.data = ret[1]
Expand Down Expand Up @@ -289,10 +289,10 @@ def __repr__(self):
source = self.D.hostname if self.D is not None else self._path

if self.data is None:
return "%s:%s - Table empty" % (cls_name, source)
return "{}:{} - Table empty".format(cls_name, source)
else:
n_items = len(self.keys())
return "%s:%s: %s items" % (cls_name, source, n_items)
return "{}:{}: {} items".format(cls_name, source, n_items)

def __len__(self):
self._assert_data()
Expand Down Expand Up @@ -366,7 +366,7 @@ def _parse_textfsm(self, platform=None, command=None, raw=None):
cli_table.ParseCmd(raw, attrs, template)
except ntc_parse.clitable.CliTableError as ex:
logger.error(
'Unable to parse command "%s" on platform %s' % (command, platform)
'Unable to parse command "{}" on platform {}'.format(command, platform)
)
raise ex
return self._filter_output(cli_table)
Expand Down
2 changes: 1 addition & 1 deletion lib/jnpr/junos/factory/optable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OpTable(Table):

@checkSAXParserDecorator
def get(self, *vargs, **kvargs):
"""
r"""
Retrieve the XML table data from the Device instance and
returns back the Table instance - for call-chaining purposes.

Expand Down
Loading