Skip to content

Commit

Permalink
Python 3 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque committed Aug 11, 2020
1 parent 0225c09 commit 3d093ec
Show file tree
Hide file tree
Showing 38 changed files with 290 additions and 291 deletions.
8 changes: 4 additions & 4 deletions config/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def fallback(option):
def login(auth_protocol):
"""Switch login authentication [ {tacacs+, local} | default ]"""
if len(auth_protocol) is 0:
print 'Not support empty argument'
click.echo('Argument "auth_protocol" is required')
return

if 'default' in auth_protocol:
Expand Down Expand Up @@ -107,7 +107,7 @@ def timeout(ctx, second):
elif second:
add_table_kv('TACPLUS', 'global', 'timeout', second)
else:
click.echo('Not support empty argument')
click.echo('Argument "second" is required')
tacacs.add_command(timeout)
default.add_command(timeout)

Expand All @@ -122,7 +122,7 @@ def authtype(ctx, type):
elif type:
add_table_kv('TACPLUS', 'global', 'auth_type', type)
else:
click.echo('Not support empty argument')
click.echo('Argument "type" is required')
tacacs.add_command(authtype)
default.add_command(authtype)

Expand All @@ -137,7 +137,7 @@ def passkey(ctx, secret):
elif secret:
add_table_kv('TACPLUS', 'global', 'passkey', secret)
else:
click.echo('Not support empty argument')
click.echo('Argument "secret" is required')
tacacs.add_command(passkey)
default.add_command(passkey)

Expand Down
2 changes: 1 addition & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def config(ctx):
try:
version_info = device_info.get_sonic_version_info()
asic_type = version_info['asic_type']
except KeyError, TypeError:
except (KeyError, TypeError):
raise click.Abort()

if asic_type == 'mellanox':
Expand Down
14 changes: 7 additions & 7 deletions config/mlnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ def sniffer_env_variable_set(enable, env_variable_name, env_variable_string=""):
env_variable_exist_string = env_variable_read(env_variable_name)
if env_variable_exist_string:
if enable is True:
print "sniffer is already enabled, do nothing"
click.echo("sniffer is already enabled, do nothing")
ignore = True
else:
env_variable_delete(env_variable_exist_string)
else:
if enable is True:
env_variable_write(env_variable_string)
else:
print "sniffer is already disabled, do nothing"
click.echo("sniffer is already disabled, do nothing")
ignore = True

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


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


Expand All @@ -198,7 +198,7 @@ def sdk_sniffer_enable():
err = restart_swss()
if err is not 0:
return
print 'SDK sniffer is Enabled, recording file is %s.' % sdk_sniffer_filename
click.echo('SDK sniffer is Enabled, recording file is %s.' % sdk_sniffer_filename)
else:
pass

Expand All @@ -211,7 +211,7 @@ def sdk_sniffer_disable():
err = restart_swss()
if err is not 0:
return
print "SDK sniffer is Disabled."
click.echo("SDK sniffer is Disabled.")
else:
pass

Expand Down
2 changes: 1 addition & 1 deletion consutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def consutil():
"""consutil - Command-line utility for interacting with switches via console device"""

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

# 'show' subcommand
Expand Down
2 changes: 1 addition & 1 deletion counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def show():
if buffer_pool_wm_info:
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)])

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

32 changes: 16 additions & 16 deletions crm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def show_summary(self):
crm_info = configdb.get_entry('CRM', 'Config')

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

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

print '\n'
print tabulate(data, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')

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

print '\n'
print tabulate(data, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')

def show_acl_resources(self):
"""
Expand All @@ -108,9 +108,9 @@ def show_acl_resources(self):
crm_stats['crm_stats_' + res + "_available"]
])

print '\n'
print tabulate(data, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')

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

print '\n'
print tabulate(data, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(data, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')


@click.group()
Expand Down
10 changes: 5 additions & 5 deletions pcieutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def print_result(name, result):
sys.stdout.write(string)
for i in xrange(int(length)):
sys.stdout.write("-")
print(' [%s]' % result)
click.echo(' [%s]' % result)

# ==================== Methods for initialization ====================

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


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


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


if __name__ == '__main__':
Expand Down
28 changes: 14 additions & 14 deletions pddf_thermalutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ def gettemp(index):

except NotImplementedError:
pass
else:
label, value = platform_thermalutil.show_thermal_temp_values(thermal)
else:
label, value = platform_thermalutil.show_thermal_temp_values(thermal)

if label is None:
status_table.append([thermal_name, value])
else:
status_table.append([thermal_name, label, value])
if label is None:
status_table.append([thermal_name, value])
else:
status_table.append([thermal_name, label, value])

if status_table:
if label is None:
header = ['Temp Sensor', 'Value']
else:
header = ['Temp Sensor', 'Label', 'Value']
if label is None:
header = ['Temp Sensor', 'Value']
else:
header = ['Temp Sensor', 'Label', 'Value']
click.echo(tabulate(status_table, header, tablefmt="simple"))

@cli.group()
Expand All @@ -159,11 +159,11 @@ def debug():
def dump_sysfs():
"""Dump all Temp Sensor related SysFS paths"""
if platform_chassis is not None:
supported_thermal = range(1, _wrapper_get_num_thermals()+ 1)
for index in supported_thermal:
status = platform_chassis.get_thermal(index-1).dump_sysfs()
supported_thermal = range(1, _wrapper_get_num_thermals()+ 1)
for index in supported_thermal:
status = platform_chassis.get_thermal(index-1).dump_sysfs()
else:
status = platform_thermalutil.dump_sysfs()
status = platform_thermalutil.dump_sysfs()

if status:
for i in status:
Expand Down
20 changes: 10 additions & 10 deletions pfc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def showPfcAsym(interface):

sorted_table = natsorted(table)

print '\n'
print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(sorted_table, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')

def configPfcPrio(status, interface, priority):
configdb = swsssdk.ConfigDBConnector()
configdb.connect()

if interface not in configdb.get_keys('PORT_QOS_MAP'):
print 'Cannot find interface {0}'.format(interface)
click.echo('Cannot find interface {0}'.format(interface))
return

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

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

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

if status == 'on':
Expand Down Expand Up @@ -99,7 +99,7 @@ def showPfcPrio(interface):

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

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

sorted_table = natsorted(table)
print '\n'
print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="")
print '\n'
click.echo('\n')
click.echo(tabulate(sorted_table, headers=header, tablefmt="simple", missingval=""))
click.echo('\n')

@click.group()
def cli():
Expand Down
4 changes: 2 additions & 2 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def start(action, restoration_time, ports, detection_time):
pfcwd_info['restoration_time'] = restoration_time
else:
pfcwd_info['restoration_time'] = 2 * detection_time
print "restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time)
click.echo("restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time))

for port in ports:
if port == "all":
Expand Down Expand Up @@ -209,7 +209,7 @@ def interval(poll_interval):
entry_min = restoration_time_entry_value
entry_min_str = "restoration time"
if entry_min < poll_interval:
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)
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)
exit(1)

pfcwd_info['POLL_INTERVAL'] = poll_interval
Expand Down
4 changes: 2 additions & 2 deletions scripts/boot_part
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def print_partitions(blkdev):
index = m.group(3)
if name != blkdev or not index:
continue
print index, label
print(index, label)

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

## Handle the command line
if args.index is None:
Expand Down
Loading

0 comments on commit 3d093ec

Please sign in to comment.