Translate python2 to python3

*opencas.py*: changed result class to contain text values instead of bytes,
translated chache configuring methods to py3,
*init script*: changed regex input on raw string to work in py3.

Signed-off-by: Slawomir_Jankowski <slawomir.jankowski@intel.com>
This commit is contained in:
Slawomir_Jankowski 2019-07-30 09:51:55 +02:00 committed by Slawomir_Jankowski
parent d01c26d629
commit 3d5d82f892
3 changed files with 10 additions and 12 deletions

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright(c) 2012-2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
from __future__ import print_function
import argparse
import sys
import re
@ -42,7 +41,7 @@ def add_core_recursive(core, config):
.format(core.device, core.cache_id))
exit(3)
core.marked = True
match = re.match('/dev/cas(\d)-(\d).*', core.device)
match = re.match(r'/dev/cas(\d)-(\d).*', core.device)
if match:
cache_id,core_id = match.groups()
with_error = add_core_recursive(config.caches[int(cache_id)].cores[int(core_id)], config)

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright(c) 2012-2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
from __future__ import print_function
import subprocess
import time
import opencas

View File

@ -17,11 +17,11 @@ class casadm:
class result:
def __init__(self, cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.exit_code = p.wait()
output = p.communicate()
self.stdout = output[0]
self.stderr = output[1]
p = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.exit_code = p.returncode
self.stdout = p.stdout
self.stderr = p.stderr
class CasadmError(Exception):
def __init__(self, result):
@ -500,10 +500,10 @@ def start_cache(cache, load, force=False):
force=force)
def configure_cache(cache):
if cache.params.has_key('cleaning_policy'):
if 'cleaning_policy' in cache.params:
casadm.set_param('cleaning', cache_id=cache.cache_id,
policy=cache.params['cleaning_policy'])
if cache.params.has_key('ioclass_file'):
if 'ioclass_file' in cache.params:
casadm.io_class_load_config(cache_id=cache.cache_id,
ioclass_file=cache.params['ioclass_file'])