Skip to content

Commit

Permalink
Correct last failing pylint 10/10
Browse files Browse the repository at this point in the history
  • Loading branch information
ghantoos committed Oct 23, 2024
1 parent 05c7793 commit d54f30a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
8 changes: 3 additions & 5 deletions lshell/checkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def check_config_file_exists(self, configfile):
"""Check if the configuration file exists, else exit with error"""
if not os.path.exists(configfile):
self.stderr.write("Error: Config file doesn't exist\n")
self.stderr.write(variables.usage)
sys.exit(1)
utils.usage()

def check_script(self):
"""Check if lshell is invoked with the correct binary and script extension"""
Expand Down Expand Up @@ -96,7 +95,7 @@ def getoptions(self, arguments, conf):
if option in ["-c"]:
conf["ssh"] = value
if option in ["-h", "--help"]:
utils.usage()
utils.usage(exitcode=0)
if option in ["--version"]:
utils.version()

Expand Down Expand Up @@ -141,8 +140,7 @@ def check_file(self, file):
"""
if not os.path.exists(file):
self.stderr.write("Error: Config file doesn't exist\n")
self.stderr.write(variables.usage)
sys.exit(1)
utils.usage()
else:
self.config = configparser.ConfigParser()

Expand Down
16 changes: 6 additions & 10 deletions lshell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from lshell import builtincmd


def usage():
def usage(exitcode=1):
"""Prints the usage"""
sys.stderr.write(variables.usage)
sys.exit(0)
sys.stderr.write(variables.USAGE)
sys.exit(exitcode)


def version():
Expand Down Expand Up @@ -71,18 +71,17 @@ def cmd_parse_execute(command_line, shell_context=None):
# Split command line by shell grammar: '&&', '||', and ';;'
cmd_split = re.split(r"(;;|&&|\|\|)", command_line)

# Initialize a variable to track whether the previous command succeeded or failed
previous_retcode = 0
retcode = 0 # Initialize return code

# Iterate over commands and operators
for i in range(0, len(cmd_split), 2):
command = cmd_split[i].strip()
operator = cmd_split[i - 1].strip() if i > 0 else None

# Only execute commands based on the previous operator and return code
if operator == "&&" and previous_retcode != 0:
if operator == "&&" and retcode != 0:
continue
elif operator == "||" and previous_retcode == 0:
elif operator == "||" and retcode == 0:
continue

# Get the executable command
Expand All @@ -106,9 +105,6 @@ def cmd_parse_execute(command_line, shell_context=None):
else:
retcode = exec_cmd(command)

# Update the previous return code
previous_retcode = retcode

return retcode


Expand Down
2 changes: 1 addition & 1 deletion lshell/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
HISTORY_FILE = ".lhistory"

# help text
usage = f"""Usage: lshell [OPTIONS]
USAGE = f"""Usage: lshell [OPTIONS]
--config <file> : Config file location (default {configfile})
--<param> <value> : where <param> is *any* config file parameter
-h, --help : Show this help message
Expand Down
2 changes: 2 additions & 0 deletions test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ def test_25_keyboard_interrupt(self):
expected = "foo"
elif result.startswith("^C"):
expected = "^C"
else:
expected = "unknown"
except IndexError:
# outputs u' ^C' on Debian
expected = "^C"
Expand Down

0 comments on commit d54f30a

Please sign in to comment.