Skip to content

Commit 3d093ec

Browse files
committed
Python 3 compliance
1 parent 0225c09 commit 3d093ec

38 files changed

+290
-291
lines changed

config/aaa.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def fallback(option):
7070
def login(auth_protocol):
7171
"""Switch login authentication [ {tacacs+, local} | default ]"""
7272
if len(auth_protocol) is 0:
73-
print 'Not support empty argument'
73+
click.echo('Argument "auth_protocol" is required')
7474
return
7575

7676
if 'default' in auth_protocol:
@@ -107,7 +107,7 @@ def timeout(ctx, second):
107107
elif second:
108108
add_table_kv('TACPLUS', 'global', 'timeout', second)
109109
else:
110-
click.echo('Not support empty argument')
110+
click.echo('Argument "second" is required')
111111
tacacs.add_command(timeout)
112112
default.add_command(timeout)
113113

@@ -122,7 +122,7 @@ def authtype(ctx, type):
122122
elif type:
123123
add_table_kv('TACPLUS', 'global', 'auth_type', type)
124124
else:
125-
click.echo('Not support empty argument')
125+
click.echo('Argument "type" is required')
126126
tacacs.add_command(authtype)
127127
default.add_command(authtype)
128128

@@ -137,7 +137,7 @@ def passkey(ctx, secret):
137137
elif secret:
138138
add_table_kv('TACPLUS', 'global', 'passkey', secret)
139139
else:
140-
click.echo('Not support empty argument')
140+
click.echo('Argument "secret" is required')
141141
tacacs.add_command(passkey)
142142
default.add_command(passkey)
143143

config/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def config(ctx):
818818
try:
819819
version_info = device_info.get_sonic_version_info()
820820
asic_type = version_info['asic_type']
821-
except KeyError, TypeError:
821+
except (KeyError, TypeError):
822822
raise click.Abort()
823823

824824
if asic_type == 'mellanox':

config/mlnx.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def sniffer_env_variable_set(enable, env_variable_name, env_variable_string=""):
100100
env_variable_exist_string = env_variable_read(env_variable_name)
101101
if env_variable_exist_string:
102102
if enable is True:
103-
print "sniffer is already enabled, do nothing"
103+
click.echo("sniffer is already enabled, do nothing")
104104
ignore = True
105105
else:
106106
env_variable_delete(env_variable_exist_string)
107107
else:
108108
if enable is True:
109109
env_variable_write(env_variable_string)
110110
else:
111-
print "sniffer is already disabled, do nothing"
111+
click.echo("sniffer is already disabled, do nothing")
112112
ignore = True
113113

114114
if not ignore:
@@ -164,17 +164,17 @@ def sdk():
164164
prompt='Swss service will be restarted, continue?')
165165
def enable():
166166
"""Enable SDK Sniffer"""
167-
print "Enabling SDK sniffer"
167+
click.echo("Enabling SDK sniffer")
168168
sdk_sniffer_enable()
169-
print "Note: the sniffer file may exhaust the space on /var/log, please disable it when you are done with this sniffering."
169+
click.echo("Note: the sniffer file may exhaust the space on /var/log, please disable it when you are done with this sniffering.")
170170

171171

172172
@sdk.command()
173173
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, expose_value=False,
174174
prompt='Swss service will be restarted, continue?')
175175
def disable():
176176
"""Disable SDK Sniffer"""
177-
print "Disabling SDK sniffer"
177+
click.echo("Disabling SDK sniffer")
178178
sdk_sniffer_disable()
179179

180180

@@ -198,7 +198,7 @@ def sdk_sniffer_enable():
198198
err = restart_swss()
199199
if err is not 0:
200200
return
201-
print 'SDK sniffer is Enabled, recording file is %s.' % sdk_sniffer_filename
201+
click.echo('SDK sniffer is Enabled, recording file is %s.' % sdk_sniffer_filename)
202202
else:
203203
pass
204204

@@ -211,7 +211,7 @@ def sdk_sniffer_disable():
211211
err = restart_swss()
212212
if err is not 0:
213213
return
214-
print "SDK sniffer is Disabled."
214+
click.echo("SDK sniffer is Disabled.")
215215
else:
216216
pass
217217

consutil/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def consutil():
2020
"""consutil - Command-line utility for interacting with switches via console device"""
2121

2222
if os.geteuid() != 0:
23-
print "Root privileges are required for this operation"
23+
click.echo("Root privileges are required for this operation")
2424
sys.exit(1)
2525

2626
# 'show' subcommand

counterpoll/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ def show():
186186
if buffer_pool_wm_info:
187187
data.append(["BUFFER_POOL_WATERMARK_STAT", buffer_pool_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), buffer_pool_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
188188

189-
print tabulate(data, headers=header, tablefmt="simple", missingval="")
189+
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
190190

crm/main.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def show_summary(self):
2929
crm_info = configdb.get_entry('CRM', 'Config')
3030

3131
if crm_info:
32-
print '\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n'
32+
click.echo('\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n')
3333
else:
34-
print '\nError! Could not get CRM configuration.\n'
34+
click.echo('\nError! Could not get CRM configuration.\n')
3535

3636
def show_thresholds(self, resource):
3737
"""
@@ -54,11 +54,11 @@ def show_thresholds(self, resource):
5454
else:
5555
data.append([resource, crm_info[resource + "_threshold_type"], crm_info[resource + "_low_threshold"], crm_info[resource + "_high_threshold"]])
5656
else:
57-
print '\nError! Could not get CRM configuration.'
57+
click.echo('\nError! Could not get CRM configuration.')
5858

59-
print '\n'
60-
print tabulate(data, headers=header, tablefmt="simple", missingval="")
61-
print '\n'
59+
click.echo('\n')
60+
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
61+
click.echo('\n')
6262

6363
def show_resources(self, resource):
6464
"""
@@ -80,11 +80,11 @@ def show_resources(self, resource):
8080
else:
8181
data.append([resource, crm_stats['crm_stats_' + resource + "_used"], crm_stats['crm_stats_' + resource + "_available"]])
8282
else:
83-
print '\nCRM counters are not ready. They would be populated after the polling interval.'
83+
click.echo('\nCRM counters are not ready. They would be populated after the polling interval.')
8484

85-
print '\n'
86-
print tabulate(data, headers=header, tablefmt="simple", missingval="")
87-
print '\n'
85+
click.echo('\n')
86+
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
87+
click.echo('\n')
8888

8989
def show_acl_resources(self):
9090
"""
@@ -108,9 +108,9 @@ def show_acl_resources(self):
108108
crm_stats['crm_stats_' + res + "_available"]
109109
])
110110

111-
print '\n'
112-
print tabulate(data, headers=header, tablefmt="simple", missingval="")
113-
print '\n'
111+
click.echo('\n')
112+
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
113+
click.echo('\n')
114114

115115
def show_acl_table_resources(self):
116116
"""
@@ -136,9 +136,9 @@ def show_acl_table_resources(self):
136136
if ('crm_stats_' + res + '_used' in crm_stats) and ('crm_stats_' + res + '_available' in crm_stats):
137137
data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']])
138138

139-
print '\n'
140-
print tabulate(data, headers=header, tablefmt="simple", missingval="")
141-
print '\n'
139+
click.echo('\n')
140+
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
141+
click.echo('\n')
142142

143143

144144
@click.group()

pcieutil/main.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def print_result(name, result):
3333
sys.stdout.write(string)
3434
for i in xrange(int(length)):
3535
sys.stdout.write("-")
36-
print(' [%s]' % result)
36+
click.echo(' [%s]' % result)
3737

3838
# ==================== Methods for initialization ====================
3939

@@ -103,7 +103,7 @@ def pcie_show():
103103
Fn = item["fn"]
104104
Name = item["name"]
105105
Id = item["id"]
106-
print "bus:dev.fn %s:%s.%s - dev_id=0x%s, %s" % (Bus, Dev, Fn, Id, Name)
106+
click.echo("bus:dev.fn %s:%s.%s - dev_id=0x%s, %s" % (Bus, Dev, Fn, Id, Name))
107107

108108

109109
# Show PCIE Vender ID and Device ID
@@ -122,17 +122,17 @@ def pcie_check():
122122
log.log_warning("PCIe Device: " + item["name"] + " Not Found")
123123
err += 1
124124
if err:
125-
print "PCIe Device Checking All Test ----------->>> FAILED"
125+
click.echo("PCIe Device Checking All Test ----------->>> FAILED")
126126
else:
127-
print "PCIe Device Checking All Test ----------->>> PASSED"
127+
click.echo("PCIe Device Checking All Test ----------->>> PASSED")
128128

129129

130130
@cli.command()
131131
@click.confirmation_option(prompt="Are you sure to overwrite config file pcie.yaml with current pcie device info?")
132132
def pcie_generate():
133133
'''Generate config file with current pci device'''
134134
platform_pcieutil.dump_conf_yaml()
135-
print "Generate config file pcie.yaml under path %s" % platform_plugins_path
135+
click.echo("Generate config file pcie.yaml under path %s" % platform_plugins_path)
136136

137137

138138
if __name__ == '__main__':

pddf_thermalutil/main.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,19 @@ def gettemp(index):
135135

136136
except NotImplementedError:
137137
pass
138-
else:
139-
label, value = platform_thermalutil.show_thermal_temp_values(thermal)
138+
else:
139+
label, value = platform_thermalutil.show_thermal_temp_values(thermal)
140140

141-
if label is None:
142-
status_table.append([thermal_name, value])
143-
else:
144-
status_table.append([thermal_name, label, value])
141+
if label is None:
142+
status_table.append([thermal_name, value])
143+
else:
144+
status_table.append([thermal_name, label, value])
145145

146146
if status_table:
147-
if label is None:
148-
header = ['Temp Sensor', 'Value']
149-
else:
150-
header = ['Temp Sensor', 'Label', 'Value']
147+
if label is None:
148+
header = ['Temp Sensor', 'Value']
149+
else:
150+
header = ['Temp Sensor', 'Label', 'Value']
151151
click.echo(tabulate(status_table, header, tablefmt="simple"))
152152

153153
@cli.group()
@@ -159,11 +159,11 @@ def debug():
159159
def dump_sysfs():
160160
"""Dump all Temp Sensor related SysFS paths"""
161161
if platform_chassis is not None:
162-
supported_thermal = range(1, _wrapper_get_num_thermals()+ 1)
163-
for index in supported_thermal:
164-
status = platform_chassis.get_thermal(index-1).dump_sysfs()
162+
supported_thermal = range(1, _wrapper_get_num_thermals()+ 1)
163+
for index in supported_thermal:
164+
status = platform_chassis.get_thermal(index-1).dump_sysfs()
165165
else:
166-
status = platform_thermalutil.dump_sysfs()
166+
status = platform_thermalutil.dump_sysfs()
167167

168168
if status:
169169
for i in status:

pfc/main.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ def showPfcAsym(interface):
4545

4646
sorted_table = natsorted(table)
4747

48-
print '\n'
49-
print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="")
50-
print '\n'
48+
click.echo('\n')
49+
click.echo(tabulate(sorted_table, headers=header, tablefmt="simple", missingval=""))
50+
click.echo('\n')
5151

5252
def configPfcPrio(status, interface, priority):
5353
configdb = swsssdk.ConfigDBConnector()
5454
configdb.connect()
5555

5656
if interface not in configdb.get_keys('PORT_QOS_MAP'):
57-
print 'Cannot find interface {0}'.format(interface)
57+
click.echo('Cannot find interface {0}'.format(interface))
5858
return
5959

6060
"""Current lossless priorities on the interface"""
@@ -65,11 +65,11 @@ def configPfcPrio(status, interface, priority):
6565
enable_prio = [x.strip() for x in enable_prio if x.strip()]
6666

6767
if status == 'on' and priority in enable_prio:
68-
print 'Priority {0} has already been enabled on {1}'.format(priority, interface)
68+
click.echo('Priority {0} has already been enabled on {1}'.format(priority, interface))
6969
return
7070

7171
if status == 'off' and priority not in enable_prio:
72-
print 'Priority {0} is not enabled on {1}'.format(priority, interface)
72+
click.echo('Priority {0} is not enabled on {1}'.format(priority, interface))
7373
return
7474

7575
if status == 'on':
@@ -99,7 +99,7 @@ def showPfcPrio(interface):
9999

100100
"""The user specifies an interface but we cannot find it"""
101101
if interface and interface not in intfs:
102-
print 'Cannot find interface {0}'.format(interface)
102+
click.echo('Cannot find interface {0}'.format(interface))
103103
return
104104

105105
if interface:
@@ -110,9 +110,9 @@ def showPfcPrio(interface):
110110
table.append([intf, entry.get('pfc_enable', 'N/A')])
111111

112112
sorted_table = natsorted(table)
113-
print '\n'
114-
print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="")
115-
print '\n'
113+
click.echo('\n')
114+
click.echo(tabulate(sorted_table, headers=header, tablefmt="simple", missingval=""))
115+
click.echo('\n')
116116

117117
@click.group()
118118
def cli():

pfcwd/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def start(action, restoration_time, ports, detection_time):
171171
pfcwd_info['restoration_time'] = restoration_time
172172
else:
173173
pfcwd_info['restoration_time'] = 2 * detection_time
174-
print "restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time)
174+
click.echo("restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time))
175175

176176
for port in ports:
177177
if port == "all":
@@ -209,7 +209,7 @@ def interval(poll_interval):
209209
entry_min = restoration_time_entry_value
210210
entry_min_str = "restoration time"
211211
if entry_min < poll_interval:
212-
print >> sys.stderr, "unable to use polling interval = {}ms, value is bigger than one of the configured {} values, please choose a smaller polling_interval".format(poll_interval,entry_min_str)
212+
click.echo("unable to use polling interval = {}ms, value is bigger than one of the configured {} values, please choose a smaller polling_interval".format(poll_interval,entry_min_str), err=True)
213213
exit(1)
214214

215215
pfcwd_info['POLL_INTERVAL'] = poll_interval

scripts/boot_part

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def print_partitions(blkdev):
5252
index = m.group(3)
5353
if name != blkdev or not index:
5454
continue
55-
print index, label
55+
print(index, label)
5656

5757
## Get the current boot partition index
5858
def get_boot_partition(blkdev):
@@ -117,7 +117,7 @@ def main():
117117
if cur is None:
118118
logger.error('Failed to get boot partition')
119119
return -1
120-
print 'Current rootfs partition is: {0}'.format(cur)
120+
print('Current rootfs partition is: {0}'.format(cur))
121121

122122
## Handle the command line
123123
if args.index is None:

0 commit comments

Comments
 (0)