From 5c4f5b541de064217c63dd802d01246f99dbc118 Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:30:31 +0200 Subject: [PATCH] patch --- .github/workflows/build-and-test-deb.yml | 48 +++++++++++++++ .github/workflows/build-and-test-rpm.yml | 24 ++++++++ README.md | 4 ++ src/controllers/App/Config.py | 32 ++++++++++ src/controllers/Args.py | 76 ++++++++++++++++++++++++ 5 files changed, 184 insertions(+) diff --git a/.github/workflows/build-and-test-deb.yml b/.github/workflows/build-and-test-deb.yml index 4b9a502..da62bf5 100644 --- a/.github/workflows/build-and-test-deb.yml +++ b/.github/workflows/build-and-test-deb.yml @@ -146,6 +146,18 @@ jobs: - name: "Run test: set mail recipient" run: python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: python3 /opt/linupdate/linupdate.py --exclude "kernel.*" @@ -237,6 +249,18 @@ jobs: - name: "Run test: set mail recipient" run: python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: python3 /opt/linupdate/linupdate.py --exclude "kernel.*" @@ -328,6 +352,18 @@ jobs: - name: "Run test: set mail recipient" run: python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: python3 /opt/linupdate/linupdate.py --exclude "kernel.*" @@ -416,6 +452,18 @@ jobs: - name: "Run test: set mail recipient" run: sudo python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: sudo python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: sudo python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: sudo python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: sudo python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: sudo python3 /opt/linupdate/linupdate.py --exclude "kernel.*" diff --git a/.github/workflows/build-and-test-rpm.yml b/.github/workflows/build-and-test-rpm.yml index 7c79784..31fc47c 100644 --- a/.github/workflows/build-and-test-rpm.yml +++ b/.github/workflows/build-and-test-rpm.yml @@ -177,6 +177,18 @@ jobs: - name: "Run test: set mail recipient" run: python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: python3 /opt/linupdate/linupdate.py --exclude "kernel.*" @@ -275,6 +287,18 @@ jobs: - name: "Run test: set mail recipient" run: python3 /opt/linupdate/linupdate.py --set-mail-recipient test@mail.com,test2@mail.com + - name: "Run test: set mail smtp host" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-host localhost + + - name: "Run test: get mail smtp host" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-host + + - name: "Run test: set mail smtp port" + run: python3 /opt/linupdate/linupdate.py --set-mail-smtp-port 25 + + - name: "Run test: get mail smtp port" + run: python3 /opt/linupdate/linupdate.py --get-mail-smtp-port + - name: "Run test: set package exclusions" run: python3 /opt/linupdate/linupdate.py --exclude "kernel.*" diff --git a/README.md b/README.md index e53d7ae..2199003 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ It should help you **installing** and starting using linupdate. --mail-enable [true|false] Enable or disable mail reports --get-mail-recipient Get current mail recipient(s) --set-mail-recipient [EMAIL] Set mail recipient(s) (separated by commas) + --get-mail-stmp-host Get current mail SMTP host + --set-mail-stmp-host [HOST] Set mail SMTP host + --get-mail-stmp-port Get current mail SMTP port + --set-mail-stmp-port [PORT] Set mail SMTP port Update options diff --git a/src/controllers/App/Config.py b/src/controllers/App/Config.py index 289b233..de95417 100644 --- a/src/controllers/App/Config.py +++ b/src/controllers/App/Config.py @@ -401,6 +401,22 @@ def get_mail_recipient(self): return configuration['main']['mail']['recipient'] + #----------------------------------------------------------------------------------------------- + # + # Set mail smtp host + # + #----------------------------------------------------------------------------------------------- + def set_mail_smtp_host(self, smtp_host: str): + # Get current configuration + configuration = self.get_conf() + + # Set smtp host + configuration['main']['mail']['smtp_host'] = smtp_host + + # Write config file + self.write_conf(configuration) + + #----------------------------------------------------------------------------------------------- # # Get mail smtp host @@ -419,6 +435,22 @@ def get_mail_smtp_host(self): return smtp_host + #----------------------------------------------------------------------------------------------- + # + # Set mail smtp host port + # + #----------------------------------------------------------------------------------------------- + def set_mail_smtp_port(self, smtp_port: int): + # Get current configuration + configuration = self.get_conf() + + # Set smtp port + configuration['main']['mail']['smtp_port'] = smtp_port + + # Write config file + self.write_conf(configuration) + + #----------------------------------------------------------------------------------------------- # # Get mail smtp host port diff --git a/src/controllers/Args.py b/src/controllers/Args.py index d891375..13b942e 100644 --- a/src/controllers/Args.py +++ b/src/controllers/Args.py @@ -73,6 +73,14 @@ def parse(self): parser.add_argument("--get-mail-recipient", action="store_true", default="null") # Set mail recipient parser.add_argument("--set-mail-recipient", action="store", nargs='?', default="null") + # Get mail smtp host + parser.add_argument("--get-mail-smtp-host", action="store_true", default="null") + # Set mail smtp host + parser.add_argument("--set-mail-smtp-host", action="store", nargs='?', default="null") + # Get mail smtp port + parser.add_argument("--get-mail-smtp-port", action="store_true", default="null") + # Set mail smtp port + parser.add_argument("--set-mail-smtp-port", action="store", nargs='?', default="null") # Packages to update list parser.add_argument("--update", "-u", action="store", nargs='?', default="null") @@ -299,6 +307,48 @@ def parse(self): myExit.clean_exit(0, False) except Exception as e: raise ArgsException('Could not set mail recipient(s): ' + str(e)) + + # + # If --get-mail-smtp-host param has been set + # + if args.get_mail_smtp_host != "null": + try: + print(' Current mail SMTP host: ' + Fore.GREEN + myAppConfig.get_mail_smtp_host() + Style.RESET_ALL, end='\n\n') + myExit.clean_exit(0, False) + except Exception as e: + raise ArgsException('Could not get mail SMTP host: ' + str(e)) + + # + # If --set-mail-smtp-host param has been set + # + if args.set_mail_smtp_host != "null": + try: + myAppConfig.set_mail_smtp_host(args.set_mail_smtp_host) + print(' Mail SMTP host set to: ' + Fore.GREEN + args.set_mail_smtp_host + Style.RESET_ALL, end='\n\n') + myExit.clean_exit(0, False) + except Exception as e: + raise ArgsException('Could not set mail SMTP host: ' + str(e)) + + # + # If --get-mail-smtp-port param has been set + # + if args.get_mail_smtp_port != "null": + try: + print(' Current mail SMTP port: ' + Fore.GREEN + str(myAppConfig.get_mail_smtp_port()) + Style.RESET_ALL, end='\n\n') + myExit.clean_exit(0, False) + except Exception as e: + raise ArgsException('Could not get mail SMTP port: ' + str(e)) + + # + # If --set-mail-smtp-port param has been set + # + if args.set_mail_smtp_port != "null": + try: + myAppConfig.set_mail_smtp_port(args.set_mail_smtp_port) + print(' Mail SMTP port set to: ' + Fore.GREEN + str(args.set_mail_smtp_port) + Style.RESET_ALL, end='\n\n') + myExit.clean_exit(0, False) + except Exception as e: + raise ArgsException('Could not set mail SMTP port: ' + str(e)) # # If --update param has been set @@ -620,6 +670,32 @@ def help(self): 'option': 'EMAIL', 'description': 'Set mail recipient(s) (separated by commas)' }, + { + 'args': [ + '--get-mail-smtp-host' + ], + 'description': 'Get current mail SMTP host' + }, + { + 'args': [ + '--set-mail-smtp-host' + ], + 'option': 'HOST', + 'description': 'Set mail SMTP host' + }, + { + 'args': [ + '--get-mail-smtp-port' + ], + 'description': 'Get current mail SMTP port' + }, + { + 'args': [ + '--set-mail-smtp-port' + ], + 'option': 'PORT', + 'description': 'Set mail SMTP port' + }, { 'title': 'Update options' },