From cf7af2a2c8835adaea93d339ef0d38b5caf19270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=A8=D1=83=D1=82=D0=BA=D0=B8=D0=BD?= Date: Sun, 25 Feb 2024 14:55:39 +0300 Subject: [PATCH] Fix printings --- create_systemd_service.py | 19 ++++++++----------- create_systemd_timer.py | 15 ++++++--------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/create_systemd_service.py b/create_systemd_service.py index 3f0ae71..6862104 100755 --- a/create_systemd_service.py +++ b/create_systemd_service.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 import sys, os, subprocess -def print_help(): - help_text = f""" +help_text = f""" Usage: {os.path.basename(__file__)} $1 $2 $3 required: @@ -11,25 +10,23 @@ required: optional: $3 - description of service - """ - print(help_text) - +""" number_of_required_arguments = 2 number_of_optional_arguments = 1 if len(sys.argv) == 1: - print_help() + print(help_text) sys.exit() elif sys.argv[1] in ["help", "-h"]: - print_help() + print(help_text) sys.exit() elif len(sys.argv) - 1 < number_of_required_arguments: print(f"You provided not enough arguments") - print_help() + print(help_text) sys.exit(1) elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1: print(f"You provided extra arguments") - print_help() + print(help_text) sys.exit(1) name_of_service = sys.argv[1] @@ -38,11 +35,11 @@ description = sys.argv[3] if sys.argv[3:4] else "" # empty if no description if not os.path.isabs(path_to_script): print("Path to script should be absolute!") - print_help() + print(help_text) sys.exit(1) elif not os.path.isfile(path_to_script): print("Path to script should exist and must be file!") - print_help() + print(help_text) sys.exit(1) diff --git a/create_systemd_timer.py b/create_systemd_timer.py index 737299f..96dca1a 100755 --- a/create_systemd_timer.py +++ b/create_systemd_timer.py @@ -1,32 +1,29 @@ #!/usr/bin/env python3 import sys, os, subprocess -def print_help(): - help_text = f""" +help_text = f""" Usage: {os.path.basename(__file__)} $1 $2 required: $1 - name of service $2 - calendar () - """ - print(help_text) +""" number_of_required_arguments = 2 number_of_optional_arguments = 0 if len(sys.argv) == 1: - print_help() + print(help_text) sys.exit() elif sys.argv[1] in ["help", "-h"]: - print_help() - sys.exit() + print(help_text) elif len(sys.argv) - 1 < number_of_required_arguments: print(f"You provided not enough arguments") - print_help() + print(help_text) sys.exit(1) elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1: print(f"You provided extra arguments") - print_help() + print(help_text) sys.exit(1) name_of_service = sys.argv[1]