Skip to content

Commit

Permalink
3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Oct 31, 2024
1 parent 3260fa6 commit fb71a35
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 83 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build-and-test-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ jobs:
- name: "Run test: set mail recipient"
run: python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down Expand Up @@ -237,6 +249,18 @@ jobs:
- name: "Run test: set mail recipient"
run: python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down Expand Up @@ -328,6 +352,18 @@ jobs:
- name: "Run test: set mail recipient"
run: python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down Expand Up @@ -416,6 +452,18 @@ jobs:
- name: "Run test: set mail recipient"
run: sudo python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/build-and-test-rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ jobs:
- name: "Run test: set mail recipient"
run: python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down Expand Up @@ -275,6 +287,18 @@ jobs:
- name: "Run test: set mail recipient"
run: python3 /opt/linupdate/linupdate.py --set-mail-recipient [email protected],[email protected]

- 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.*"

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ jobs:
release_name: ${{ env.VERSION }}
body: |
**Changes**:
- Added `--dry-run` option to simulate an update
- Removed the `--set-update-method` and `--get-update-method` options, now the update method is always one package at a time (easier to log)
- Reposerver module: improved logs output cleaning before sending it to the reposerver
- Added a way to specify SMTP host and port for mail report sending
draft: false
prerelease: false

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
68 changes: 68 additions & 0 deletions src/controllers/App/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,74 @@ 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
#
#-----------------------------------------------------------------------------------------------
def get_mail_smtp_host(self):
smtp_host = 'localhost'

# Get current configuration
configuration = self.get_conf()

# Get smtp host, if any, otherwise use localhost
if 'smtp_host' in configuration['main']['mail']:
smtp_host = configuration['main']['mail']['smtp_host']

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
#
#-----------------------------------------------------------------------------------------------
def get_mail_smtp_port(self):
smtp_port = 25

# Get current configuration
configuration = self.get_conf()

# Get smtp port, if any, otherwise use 25
if 'smtp_port' in configuration['main']['mail']:
smtp_port = configuration['main']['mail']['smtp_port']

return smtp_port


#-----------------------------------------------------------------------------------------------
#
# Set exit on package update error
Expand Down
1 change: 1 addition & 0 deletions src/controllers/App/Service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def main(self):

try:
print("[linupdate] Hi, I'm linupdate service. I will start all enabled module agents and let them run in background. Stop me and I will stop all module agents.")

# Wait 3 seconds to let the above message to be read
time.sleep(3)

Expand Down
78 changes: 77 additions & 1 deletion src/controllers/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -742,7 +818,7 @@ def help(self):
],
'option': 'MODULE',
'description': 'Disable a module'
},
}
]

# Add options to table
Expand Down
47 changes: 13 additions & 34 deletions src/controllers/Exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# Import classes
from src.controllers.App.App import App
from src.controllers.App.Config import Config
from src.controllers.Mail import Mail

class Exit:
Expand All @@ -16,43 +15,23 @@ class Exit:
#-----------------------------------------------------------------------------------------------
def clean_exit(self, exit_code = 0, send_mail: bool = True, logfile: str = None):
my_app = App()
my_config = Config()
my_mail = Mail()

# If send_mail is True, meaning a mail must be sent (if enabled)
# It is not needed to send a mail if the script has just printed the --help for example
if send_mail is True:
# Try to get mail settings
# It could fail if the config file is not found or if the
# mail section is not defined (e.g. first execution)
# So if it fails to retrieve configuration, just don't send the mail
# Define mail subject depending on exit code
if exit_code == 0:
subject = '✔ Packages update completed'

if exit_code == 1:
subject = '✕ Packages update failed'

try:
mail_enabled = my_config.get_mail_enabled()
mail_recipient = my_config.get_mail_recipient()
except Exception as e:
send_mail = False
mail_enabled = False
mail_recipient = None

# Send mail unless send_mail is False
# (in some case mail is not needed, like when exiting at update confirmation)
if send_mail is True:
# Check if mail is enabled and recipient is set
if (mail_enabled and mail_recipient):
# Define mail subject depending on exit code
if exit_code == 0:
subject = '[ OK ] Packages update completed'

if exit_code == 1:
subject = '[ ERROR ] Packages update failed'

print('\n Sending email report:')

try:
my_mail.send(subject, 'See report below or attached file.', mail_recipient, logfile)
print(' ' + Fore.GREEN + '✔' + Style.RESET_ALL + ' Email sent')
except Exception as e:
print(' ▪ ' + Fore.YELLOW + 'Error: ' + str(e) + Style.RESET_ALL)
# If mail fails, exit with error code
exit_code = 1
my_mail.send(subject, 'See report below or attached file.', logfile)
except Exception:
# If mail fails, exit with error code
exit_code = 1

# Remove lock
my_app.remove_lock()
Expand Down
Loading

0 comments on commit fb71a35

Please sign in to comment.