python3: Fix compatibility issues
- use absolute path imports to compat python3
- Replace dict.keys() with list(dict.keys()) to get a list on Python
3. On Python 3, dict.keys() now returns a view.
- Fix iteritems to use items for python3.
Testing:
1. Built packaging with new python3 packaging.
2. Built resulting ISO with new python-fmclient package.
3. Ran "fm" under python3. Verifified that no tracebacks
happened because it could not find common_wrappers.py.
4. Ran fm alarm-list to verify that output was displayed.
5. Ran fm event-list to display the events.
6. Ran fm alarm-show to show an active alarm.
Story: 2006796
Task: 42257
Signed-off-by: Charles Short <charles.short@windriver.com>
Change-Id: I5081d0685c7ad200076a76b7709cbe4f39c7b456
(cherry picked from commit 5d2dfab5f9
)
This commit is contained in:
parent
2ca9238894
commit
24efa2b9aa
|
@ -102,7 +102,7 @@ class Resource(object):
|
||||||
self._loaded = loaded
|
self._loaded = loaded
|
||||||
|
|
||||||
def _add_details(self, info):
|
def _add_details(self, info):
|
||||||
for (k, v) in info.iteritems():
|
for (k, v) in info.items():
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
def __getattr__(self, k):
|
def __getattr__(self, k):
|
||||||
|
@ -117,7 +117,7 @@ class Resource(object):
|
||||||
return self.__dict__[k]
|
return self.__dict__[k]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
|
reprkeys = sorted(k for k in list(self.__dict__.keys()) if k[0] != '_' and
|
||||||
k != 'manager')
|
k != 'manager')
|
||||||
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
||||||
return "<%s %s>" % (self.__class__.__name__, info)
|
return "<%s %s>" % (self.__class__.__name__, info)
|
||||||
|
|
|
@ -28,7 +28,7 @@ OP_LOOKUP = {'!=': 'ne',
|
||||||
'<': 'lt',
|
'<': 'lt',
|
||||||
'=': 'eq'}
|
'=': 'eq'}
|
||||||
|
|
||||||
OP_LOOKUP_KEYS = '|'.join(sorted(OP_LOOKUP.keys(), key=len, reverse=True))
|
OP_LOOKUP_KEYS = '|'.join(sorted(list(OP_LOOKUP.keys()), key=len, reverse=True))
|
||||||
OP_SPLIT_RE = re.compile(r'(%s)' % OP_LOOKUP_KEYS)
|
OP_SPLIT_RE = re.compile(r'(%s)' % OP_LOOKUP_KEYS)
|
||||||
|
|
||||||
DATA_TYPE_RE = re.compile(r'^(string|integer|float|datetime|boolean)(::)(.+)$')
|
DATA_TYPE_RE = re.compile(r'^(string|integer|float|datetime|boolean)(::)(.+)$')
|
||||||
|
|
|
@ -39,8 +39,9 @@ from dateutil import parser
|
||||||
from prettytable import ALL
|
from prettytable import ALL
|
||||||
from prettytable import FRAME
|
from prettytable import FRAME
|
||||||
from prettytable import NONE
|
from prettytable import NONE
|
||||||
|
from six.moves import zip
|
||||||
|
|
||||||
import wrapping_formatters
|
from fmclient.common import wrapping_formatters
|
||||||
|
|
||||||
|
|
||||||
SENSITIVE_HEADERS = ('X-Auth-Token', )
|
SENSITIVE_HEADERS = ('X-Auth-Token', )
|
||||||
|
@ -531,7 +532,7 @@ def print_dict(d, dict_property="Property", wrap=0):
|
||||||
pt = prettytable.PrettyTable([dict_property, 'Value'],
|
pt = prettytable.PrettyTable([dict_property, 'Value'],
|
||||||
caching=False, print_empty=False)
|
caching=False, print_empty=False)
|
||||||
pt.align = 'l'
|
pt.align = 'l'
|
||||||
for k, v in sorted(d.iteritems()):
|
for k, v in sorted(d.items()):
|
||||||
v = parse_date(v)
|
v = parse_date(v)
|
||||||
# convert dict to str to check length
|
# convert dict to str to check length
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
|
|
|
@ -25,9 +25,10 @@ import re
|
||||||
import six
|
import six
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from cli_no_wrap import is_nowrap_set
|
from fmclient.common.cli_no_wrap import is_nowrap_set
|
||||||
from cli_no_wrap import set_no_wrap
|
from fmclient.common.cli_no_wrap import set_no_wrap
|
||||||
from prettytable import _get_size
|
from prettytable import _get_size
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
UUID_MIN_LENGTH = 36
|
UUID_MIN_LENGTH = 36
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ def get_width(value):
|
||||||
|
|
||||||
|
|
||||||
def _get_terminal_width():
|
def _get_terminal_width():
|
||||||
from utils import get_terminal_size
|
from fmclient.common.utils import get_terminal_size
|
||||||
result = get_terminal_size()[0]
|
result = get_terminal_size()[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -669,7 +670,7 @@ def build_wrapping_formatters(objs, fields, field_labels, format_spec, add_blank
|
||||||
else:
|
else:
|
||||||
format_spec = build_best_guess_formatters_using_average_widths(objs, fields, field_labels)
|
format_spec = build_best_guess_formatters_using_average_widths(objs, fields, field_labels)
|
||||||
|
|
||||||
for k in format_spec.keys():
|
for k in list(format_spec.keys()):
|
||||||
if k not in fields:
|
if k not in fields:
|
||||||
raise Exception("Error in buildWrappingFormatters: format_spec "
|
raise Exception("Error in buildWrappingFormatters: format_spec "
|
||||||
"specifies a field {} that is not specified "
|
"specifies a field {} that is not specified "
|
||||||
|
@ -717,7 +718,7 @@ def set_no_wrap_on_formatters(no_wrap, formatters):
|
||||||
global_orig_no_wrap = is_nowrap_set()
|
global_orig_no_wrap = is_nowrap_set()
|
||||||
set_no_wrap(no_wrap)
|
set_no_wrap(no_wrap)
|
||||||
|
|
||||||
for k, f in formatters.iteritems():
|
for k, f in formatters.items():
|
||||||
if WrapperFormatter.is_wrapper_formatter(f):
|
if WrapperFormatter.is_wrapper_formatter(f):
|
||||||
formatter_no_wrap_settings[k] = (f.wrapper_formatter.no_wrap, f.wrapper_formatter)
|
formatter_no_wrap_settings[k] = (f.wrapper_formatter.no_wrap, f.wrapper_formatter)
|
||||||
f.wrapper_formatter.no_wrap = no_wrap
|
f.wrapper_formatter.no_wrap = no_wrap
|
||||||
|
@ -740,7 +741,7 @@ def unset_no_wrap_on_formatters(orig_no_wrap_settings):
|
||||||
|
|
||||||
formatters = {}
|
formatters = {}
|
||||||
|
|
||||||
for k, v in formatter_no_wrap_settings.iteritems():
|
for k, v in formatter_no_wrap_settings.items():
|
||||||
formatters[k] = v[1]
|
formatters[k] = v[1]
|
||||||
formatters[k].no_wrap = v[0]
|
formatters[k].no_wrap = v[0]
|
||||||
|
|
||||||
|
@ -751,7 +752,7 @@ def unset_no_wrap_on_formatters(orig_no_wrap_settings):
|
||||||
|
|
||||||
def _simpleTestHarness(no_wrap):
|
def _simpleTestHarness(no_wrap):
|
||||||
|
|
||||||
import utils
|
from fmclient.common import utils
|
||||||
|
|
||||||
def testFormatter(event):
|
def testFormatter(event):
|
||||||
return "*{}".format(event["state"])
|
return "*{}".format(event["state"])
|
||||||
|
|
Loading…
Reference in New Issue