Skip to content

Commit

Permalink
Avoid interactive constants (exit) from site module (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia1243 authored Mar 4, 2024
1 parent 9d8b43f commit fb0916d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions kubemarine/procedures/migrate_kubemarine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import argparse
import re
import sys
from abc import ABC, abstractmethod
from textwrap import dedent
from typing import List, Union
Expand Down Expand Up @@ -454,32 +455,32 @@ def run(context: dict) -> None:
print(patch_id)
else:
print("No patches available.")
exit(0)
sys.exit(0)

if args['describe']:
for patch in patches:
if patch.identifier == args['describe']:
print(patch.description)
exit(0)
sys.exit(0)
print(f"Unknown patch '{args['describe']}'")
exit(1)
sys.exit(1)

skip = [] if not args['skip'] else args['skip'].split(",")
apply = [] if not args['apply'] else args['apply'].split(",")

if apply and (set(apply) - set(patch_ids)):
print(f"Unknown patches {list(set(apply) - set(patch_ids))}")
exit(1)
sys.exit(1)

if skip and (set(skip) - set(patch_ids)):
print(f"Unknown patches {list(set(skip) - set(patch_ids))}")
exit(1)
sys.exit(1)

if apply:
positions = [patch_ids.index(apply_id) for apply_id in apply]
if not all(positions[i] < positions[i + 1] for i in range(len(positions) - 1)):
print("Incorrect order of patches to apply. See --list for correct order of patches.")
exit(1)
sys.exit(1)

actions = []
for patch in patches:
Expand All @@ -494,7 +495,7 @@ def run(context: dict) -> None:

if not actions:
print("No patches to apply")
exit(0)
sys.exit(0)

flow.ActionsFlow(actions).run_flow(context)

Expand Down
4 changes: 2 additions & 2 deletions kubemarine/resources/scripts/check_url_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
status_code = urllib.urlopen(source, timeout=timeout).getcode()
if status_code != 200:
sys.stderr.write("Error status code: %s" % status_code)
exit(1)
sys.exit(1)
except Exception as e:
sys.stderr.write(str(e))
exit(1)
sys.exit(1)
2 changes: 1 addition & 1 deletion kubemarine/resources/scripts/simple_port_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
if action == 'send' and len(data) != sz:
sys.stdout.write("Data is lost\n")
sys.stdout.flush()
exit(1)
sys.exit(1)
2 changes: 1 addition & 1 deletion kubemarine/resources/scripts/simple_port_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if "Address already in use" in str(e):
sys.stdout.write("In use\n")
sys.stdout.flush()
exit(1)
sys.exit(1)
else:
raise

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/build_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
def call(args: List[str]) -> None:
return_code = subprocess.call(args)
if return_code != 0:
exit(return_code)
sys.exit(return_code)

# Copy ipip_check from package
with open('kubemarine/version', 'r') as version_file:
Expand Down

0 comments on commit fb0916d

Please sign in to comment.