Skip to content

Commit ed6392d

Browse files
authored
[sonic_pcie][sonic_ssd] Make Python 3-compliant (sonic-net#150)
Changes to make sonic_pcie and sonic_ssd packages Python 3-compliant. Also remove unnecessary imports and remove executable permissions from files which should not be exectuable.
1 parent 362afc2 commit ed6392d

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

sonic_platform_base/sonic_pcie/__init__.py

100755100644
File mode changed.

sonic_platform_base/sonic_pcie/pcie_base.py

100755100644
File mode changed.

sonic_platform_base/sonic_pcie/pcie_common.py

100755100644
+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def load_config_file(self):
2727
with open(config_file) as conf_file:
2828
self.confInfo = yaml.load(conf_file)
2929
except IOError as e:
30-
print "Error: {}".format(str(e))
31-
print "Not found config file, please add a config file manually, or generate it by running [pcieutil pcie_generate]"
30+
print("Error: {}".format(str(e)))
31+
print("Not found config file, please add a config file manually, or generate it by running [pcieutil pcie_generate]")
3232
sys.exit()
3333

3434
# load current PCIe device
@@ -40,11 +40,11 @@ def get_pcie_device(self):
4040
command1 = "sudo lspci"
4141
command2 = "sudo lspci -n"
4242
# run command 1
43-
proc1 = subprocess.Popen(command1, shell=True, stdout=subprocess.PIPE)
43+
proc1 = subprocess.Popen(command1, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
4444
output1 = proc1.stdout.readlines()
4545
(out, err) = proc1.communicate()
4646
# run command 2
47-
proc2 = subprocess.Popen(command2, shell=True, stdout=subprocess.PIPE)
47+
proc2 = subprocess.Popen(command2, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
4848
output2 = proc2.stdout.readlines()
4949
(out, err) = proc2.communicate()
5050

sonic_platform_base/sonic_ssd/ssd_generic.py

100755100644
+2-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
# - StorFly
88
# - Virtium
99

10-
try:
11-
import exceptions # Python 2
12-
except ImportError:
13-
import builtins as exceptions # Python 3
1410
try:
1511
import re
1612
import subprocess
@@ -54,7 +50,7 @@ def __init__(self, diskdev):
5450
# Known vendor part
5551
if self.model:
5652
model_short = self.model.split()[0]
57-
if self.vendor_ssd_utility.has_key(model_short):
53+
if model_short in self.vendor_ssd_utility:
5854
self.fetch_vendor_ssd_info(diskdev, model_short)
5955
self.parse_vendor_ssd_info(model_short)
6056
else:
@@ -65,7 +61,7 @@ def __init__(self, diskdev):
6561
self.model = "Unknown"
6662

6763
def _execute_shell(self, cmd):
68-
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
64+
process = subprocess.Popen(cmd.split(), universal_newlines=True, stdout=subprocess.PIPE)
6965
output, error = process.communicate()
7066
return output
7167

0 commit comments

Comments
 (0)