Skip to content

Commit

Permalink
Merge pull request #212 from CiscoUcs/fix-overwritten-files
Browse files Browse the repository at this point in the history
Revert "ucs* files 421a"
  • Loading branch information
vvb committed Aug 30, 2021
2 parents 75e3a59 + 7653e57 commit 2336d82
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 151 deletions.
151 changes: 130 additions & 21 deletions ucsmsdk/ucscoremeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,119 @@ def __init__(self, version):
return None

self.__version = version
self.__major = None
self.__minor = None
self.__mr = None
self.__patch = None
self.__spin = None
self.__build = None

match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))\."
"(?P<patch>(([0-9])|([1-9][0-9]{0,4})))\)$")
match_obj = re.match(match_pattern, version)
if match_obj:
self.__major = match_obj.group("major")
self.__minor = match_obj.group("minor")
self.__mr = match_obj.group("mr")
self.__patch = match_obj.group("patch")
if self._set_versions(match_obj):
return

match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))"
"(?P<patch>[a-z])\)$")
match_obj = re.match(match_pattern, version)
if match_obj:
self.__major = match_obj.group("major")
self.__minor = match_obj.group("minor")
self.__mr = match_obj.group("mr")
self.__patch = match_obj.group("patch")
if self._set_versions(match_obj):
return

match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))\)$")
match_obj = re.match(match_pattern, version)
if match_obj:
self.__major = match_obj.group("major")
self.__minor = match_obj.group("minor")
self.__mr = match_obj.group("mr")
if self._set_versions(match_obj):
return

# handle spin builds "2.0(13aS1))"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))"
"(?P<patch>[a-z])"
"(?P<spin>S[1-9][0-9]{0,2})\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

# handle spin builds "3.0(1S10))"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))"
"(?P<spin>S[1-9][0-9]{0,2})\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

# handle de special builds "66.77(67.1582251418)"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,2})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))\."
"(?P<patch>(([0-9])|([1-9][0-9]{0,})))\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

# handle engineering builds "4.2(0.175a)"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,2})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))\."
"(?P<build>(([0-9])|([1-9][0-9]{0,})))"
"(?P<patch>[a-z])\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

# handle spin builds "4.2(1.2021052301)"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))\."
"(?P<spin>\d{0,4}\d{0,2}\d{0,2}\d{0,2})\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

# handle patch spin builds "4.2(1a.2021052301)"
match_pattern = re.compile("^(?P<major>[1-9][0-9]{0,2})\."
"(?P<minor>(([0-9])|([1-9][0-9]{0,1})))\("
"(?P<mr>(([0-9])|([1-9][0-9]{0,2})))"
"(?P<patch>[a-z])\."
"(?P<spin>\d{0,4}\d{0,2}\d{0,2}\d{0,2})\)$")
match_obj = re.match(match_pattern, version)
if self._set_versions(match_obj):
return

def _set_versions(self, match_obj):
if not match_obj:
return False

match_dict = match_obj.groupdict()
self.__major = match_dict.get("major")
self.__minor = match_dict.get("minor")
self.__mr = match_dict.get("mr")
self.__patch = match_dict.get("patch")
self.__spin = match_dict.get("spin")
self.__build = match_dict.get("build")

# for spin builds 4.0(1S52), the patch version will be None
# In this scenario assume the version to be highest patch z
if self.__patch is None:
self.__patch = 'z'
elif self.__patch.isdigit() and self.__mr.isdigit():
log.debug("Interim version encountered: %s. MR version has been bumped up." % self.version)
self.__mr = str(int(self.__mr) + 1)
self.__patch = 'a'
elif self.__patch.isalpha() and self.__spin:
log.debug("Interim version encountered: %s. patch version has been bumped up." % self.version)
self.__patch = str(chr(ord(self.__patch) + 1))

return True

@property
def major(self):
"""Getter Method of UcsVersion Class"""
Expand All @@ -97,23 +175,48 @@ def patch(self):
"""Getter Method of UcsVersion Class"""
return self.__patch

@property
def spin(self):
"""Getter Method of UcsVersion Class"""
return self.__spin

@property
def build(self):
"""Getter Method of UcsVersion Class"""
return self.__build

@property
def version(self):
"""Getter Method of UcsVersion Class"""
return self.__version

def _compare(self, version1, version2):
if version1 == version2:
return 0
if not version1:
return -1
if not version2:
return 1

func = (ord, int)[version1.isdigit() and version2.isdigit()]
return func(version1) - func(version2)

def compare_to(self, version):
"""Method to compare UcsVersion."""
if version is None or not isinstance(version, UcsVersion):
return 1

if self.__major != version.major:
return ord(self.__major) - ord(version.major)
if self.__minor != version.minor:
return ord(self.__minor) - ord(version.major)
if self.__mr != version.mr:
return ord(self.__mr) - ord(version.mr)
return ord(self.__patch) - ord(version.patch)
ret = 0
versions = [(self.__major, version.major),
(self.__minor, version.minor),
(self.__mr, version.mr),
(self.__build, version.build),
(self.__patch, version.patch)]
for item in versions:
ret = self._compare(item[0], item[1])
if ret:
return ret
return ret

def __gt__(self, version):
return self.compare_to(version) > 0
Expand All @@ -127,6 +230,12 @@ def __ge__(self, version):
def __le__(self, version):
return self.compare_to(version) <= 0

def __eq__(self, version):
return self.compare_to(version) == 0

def __ne__(self, version):
return self.compare_to(version) != 0

def __str__(self):
return self.__version

Expand Down
2 changes: 0 additions & 2 deletions ucsmsdk/ucscoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def find_class_id_in_mo_meta_ignore_case(class_id):
return None
if class_id in MO_CLASS_ID:
return class_id
# print class_id
l_class_id = class_id.lower()
for key in MO_CLASS_ID:
if key.lower() == l_class_id:
Expand Down Expand Up @@ -373,7 +372,6 @@ def write_mo_tree(mo, level=0, depth=None, show_level=[],
else:
tree_dict[key_all_mo][mo.class_id].append(mo)

# print tree_dict

if print_tree:
if not show_level:
Expand Down
34 changes: 16 additions & 18 deletions ucsmsdk/ucsdriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Cisco Systems, Inc.
# Copyright 2017 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,22 +18,20 @@
import socket
import ssl

try:
import urllib2
import httplib
from urllib2 import HTTPError
except:
import urllib.request as urllib2
import http.client as httplib
from urllib.error import HTTPError
from six.moves import urllib as urllib2
from six.moves import http_client as httplib
from six.moves.urllib import request as Request
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import HTTPRedirectHandler, HTTPSHandler



import logging

log = logging.getLogger('ucs')


class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
class SmartRedirectHandler(HTTPRedirectHandler):
"""This class is to handle redirection error."""

def http_error_301(self, req, fp, code, msg, headers):
Expand All @@ -47,11 +45,11 @@ def http_error_302(self, req, fp, code, msg, headers):
return resp_status


class TLSHandler(urllib2.HTTPSHandler):
class TLSHandler(HTTPSHandler):
"""Like HTTPSHandler but more specific"""

def __init__(self):
urllib2.HTTPSHandler.__init__(self)
HTTPSHandler.__init__(self)

def https_open(self, req):
return self.do_open(TLSConnection, req)
Expand Down Expand Up @@ -96,11 +94,11 @@ def connect(self):
ssl_version=ssl.PROTOCOL_TLSv1)


class TLS1Handler(urllib2.HTTPSHandler):
class TLS1Handler(HTTPSHandler):
"""Like HTTPSHandler but more specific"""

def __init__(self):
urllib2.HTTPSHandler.__init__(self)
HTTPSHandler.__init__(self)

def https_open(self, req):
return self.do_open(TLS1Connection, req)
Expand Down Expand Up @@ -225,7 +223,7 @@ def __create_request(self, uri, data=None):
web request object
"""

request_ = urllib2.Request(url=uri, data=data)
request_ = Request.Request(url=uri, data=data)
headers = self.__headers
for header in headers:
request_.add_header(header, headers[header])
Expand Down Expand Up @@ -259,7 +257,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):
if dump_xml:
log.debug('%s ====> %s' % (uri, data))

opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
try:
response = opener.open(request, timeout=timeout)
except Exception as e:
Expand All @@ -268,7 +266,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):

# Fallback to TLSv1 for this server
self.update_handlers(tls_proto="tlsv1")
opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
response = opener.open(request, timeout=timeout)

if type(response) is list:
Expand All @@ -281,7 +279,7 @@ def post(self, uri, data=None, dump_xml=False, read=True, timeout=None):
if dump_xml:
log.debug('%s <==== %s' % (uri, data))

opener = urllib2.build_opener(*self.__handlers)
opener = Request.build_opener(*self.__handlers)
response = opener.open(request, timeout=timeout)
# response = urllib2.urlopen(request)
if read:
Expand Down
8 changes: 3 additions & 5 deletions ucsmsdk/ucseventhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

from __future__ import print_function

try:
from Queue import Queue
except:
from queue import Queue
from six.moves import queue


from threading import Condition, Lock, Thread
import datetime
Expand Down Expand Up @@ -64,7 +62,7 @@ def __init__(self, params, fmce, capacity, callback):
self.params = params
self.overflow = False
self.error_code = 0
self.event_q = Queue() # infinite size Queue
self.event_q = queue.Queue() # infinite size Queue

def dequeue(self, miliseconds_timeout):
"""Internal method to dequeue the events."""
Expand Down
4 changes: 0 additions & 4 deletions ucsmsdk/ucsfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ def and_operator(toks):
method to support logical 'and' operator expression
"""

# print str, loc, toks
# print toks[0][0::2]
and_filter = AndFilter()
for op_filter in toks[0][0::2]:
and_filter.child_add(op_filter)
Expand All @@ -102,8 +100,6 @@ def or_operator(toks):
method to support logical 'or' operator expression
"""

# print str, loc, toks
# print toks[0][0::2]
or_filter = OrFilter()
for op_filter in toks[0][0::2]:
or_filter.child_add(op_filter)
Expand Down
Loading

0 comments on commit 2336d82

Please sign in to comment.