Skip to content

*: python3 support #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_routing_stack():
proc.wait()
result = stdout.rstrip('\n')

except OSError, e:
except OSError as e:
raise OSError("Cannot detect routing-stack")

return (result)
Expand Down
2 changes: 1 addition & 1 deletion config/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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('Not support empty argument')
return

if 'default' in auth_protocol:
Expand Down
20 changes: 10 additions & 10 deletions config/mlnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def log_info(msg, syslog_identifier, also_print_to_console=False):
syslog.closelog()

if also_print_to_console:
print msg
click.echo(msg)


def log_warning(msg, syslog_identifier, also_print_to_console=False):
Expand All @@ -56,7 +56,7 @@ def log_warning(msg, syslog_identifier, also_print_to_console=False):
syslog.closelog()

if also_print_to_console:
print msg
click.echo(msg)


def log_error(msg, syslog_identifier, also_print_to_console=False):
Expand All @@ -65,7 +65,7 @@ def log_error(msg, syslog_identifier, also_print_to_console=False):
syslog.closelog()

if also_print_to_console:
print msg
click.echo(msg)


# run command
Expand Down Expand Up @@ -145,15 +145,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 All @@ -169,7 +169,7 @@ def sniffer_env_variable_set(enable, env_variable_name, env_variable_string=""):
def restart_swss():
try:
run_command(COMMAND_RESTART_SWSS)
except OSError, e:
except OSError as e:
log_error("Not able to restart swss service, %s" % str(e), SNIFFER_SYSLOG_IDENTIFIER, True)
return 1
return 0
Expand Down Expand Up @@ -212,7 +212,7 @@ def sdk(option):

def sdk_sniffer_enable():
"""Enable SDK Sniffer"""
print "Enabling SDK sniffer"
click.echo("Enabling SDK sniffer")
sdk_sniffer_filename = sniffer_filename_generate(SDK_SNIFFER_TARGET_PATH,
SDK_SNIFFER_FILENAME_PREFIX,
SDK_SNIFFER_FILENAME_EXT)
Expand All @@ -231,21 +231,21 @@ def sdk_sniffer_enable():
err = restart_swss()
if err is not 0:
return
print 'Enabled SDK sniffer, recording file is %s' % sdk_sniffer_filename
click.echo('Enabled SDK sniffer, recording file is %s' % sdk_sniffer_filename)
else:
pass


def sdk_sniffer_disable():
"""Disable SDK Sniffer"""
print "Disabling SDK sniffer"
click.echo("Disabling SDK sniffer")

ignore = sniffer_env_variable_set(enable=False, env_variable_name=ENV_VARIABLE_SX_SNIFFER)
if not ignore:
err = restart_swss()
if err is not 0:
return
print "Disabled SDK sniffer"
click.echo("Disabled SDK sniffer")
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 @@ -136,5 +136,5 @@ def show():
if pg_wm_info:
data.append(["PG_WATERMARK_STAT", pg_wm_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in pg_wm_info else 'default (1000)', pg_wm_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in pg_wm_info else '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 @@ -31,9 +31,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 @@ -56,11 +56,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 @@ -82,11 +82,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 @@ -110,9 +110,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 @@ -139,9 +139,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
6 changes: 3 additions & 3 deletions pfc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ 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')


@click.group()
Expand Down
2 changes: 1 addition & 1 deletion pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,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
6 changes: 3 additions & 3 deletions psuutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_platform_and_hwsku():
stdout = proc.communicate()[0]
proc.wait()
hwsku = stdout.rstrip('\n')
except OSError, e:
except OSError as e:
raise OSError("Cannot detect platform")

return (platform, hwsku)
Expand All @@ -108,14 +108,14 @@ def load_platform_psuutil():
try:
module_file = "/".join([platform_path, "plugins", PLATFORM_SPECIFIC_MODULE_NAME + ".py"])
module = imp.load_source(PLATFORM_SPECIFIC_MODULE_NAME, module_file)
except IOError, e:
except IOError as e:
log_error("Failed to load platform module '%s': %s" % (PLATFORM_SPECIFIC_MODULE_NAME, str(e)), True)
return -1

try:
platform_psuutil_class = getattr(module, PLATFORM_SPECIFIC_CLASS_NAME)
platform_psuutil = platform_psuutil_class()
except AttributeError, e:
except AttributeError as e:
log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_SPECIFIC_CLASS_NAME, str(e)), True)
return -2

Expand Down
Loading