Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.0 #61

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and test deb package for linupdate

on:
push:
branches: [ python ]
branches: [ devel ]
pull_request:
push:
branches: [ main ]
Expand Down Expand Up @@ -469,7 +469,7 @@ jobs:
apt-get update -y
apt-get install -y curl gpg
curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh.gpg
echo "deb https://packages.bespin.ovh/repo/linupdate/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/linupdate.list
echo "deb https://packages.bespin.ovh/repo/linupdate/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/linupdate.list
apt-get update -y
apt-get install -y linupdate

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and test rpm package for linupdate

on:
push:
branches: [ python ]
branches: [ devel ]
pull_request:
push:
branches: [ main ]
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/Mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def send(self, subject: str, body_content: str, recipient: list, logfile = None)
# Get logfile real filename
attachment = logfile.split('/')[-1]

# Replace ANSI escape codes
# Remove ANSI escape codes
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
attach_content = ansi_escape.sub('', attach_content)

Expand Down
70 changes: 58 additions & 12 deletions src/controllers/Module/Reposerver/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import websocket
import json
import sys
import re
from pathlib import Path

# Import classes
from src.controllers.Log import Log
from src.controllers.Module.Module import Module
from src.controllers.Module.Reposerver.Status import Status
from src.controllers.Module.Reposerver.Config import Config
Expand Down Expand Up @@ -131,6 +133,16 @@ def websocket_on_message(self, ws, message):
message = json.loads(message)
request_id = None
summary = None
log = '/tmp/linupdate-reposerver-request.log'
error = None
json_response = {
'response-to-request': {
'request-id': '',
'status': '',
'summary': '',
'log': ''
}
}

# If the message contains 'request'
if 'request' in message:
Expand All @@ -152,37 +164,71 @@ def websocket_on_message(self, ws, message):
# Case the request is 'request-general-infos', then send general informations to the reposerver
elif message['request'] == 'request-general-infos':
print('[reposerver-agent] Reposerver requested general informations')
self.reposerverStatusController.send_general_info()
with Log(log):
self.reposerverStatusController.send_general_info()

# Case the request is 'request-packages-infos', then send packages informations to the reposerver
elif message['request'] == 'request-packages-infos':
print('[reposerver-agent] Reposerver requested packages informations')
self.reposerverStatusController.send_packages_info()
with Log(log):
self.reposerverStatusController.send_packages_info()

# Case the request is 'update-all-packages', then update all packages
elif message['request'] == 'update-all-packages':
print('[reposerver-agent] Reposerver requested all packages update')
self.packageController.update(True)

# Log everything to the log file
with Log(log):
self.packageController.update(True)

# Send a summary to the reposerver, with the summary of the update (number of packages updated or failed)
summary = self.packageController.summary
else:
raise Exception('unknown request sent by reposerver: ' + message['request'])

# If there was a request id, then send a response to reposerver to make the request as completed
if request_id:
# If there is a summary to send, then send it
if summary:
self.websocket.send(json.dumps({'response-to-request': {'request-id': request_id, 'status': 'completed', 'summary': summary}}))
else:
self.websocket.send(json.dumps({'response-to-request': {'request-id': request_id, 'status': 'completed'}}))
# If request was successful
status = 'completed'

# If request failed
except Exception as e:
print('[reposerver-agent] Error: ' + str(e))
status = 'failed'
error = str(e)

# If there was a request id, then send a response to reposerver to make the request as failed
finally:
# If there was a request id, then send a response to reposerver to make the request as completed
if request_id:
self.websocket.send(json.dumps({'response-to-request': {'request-id': request_id, 'status': 'failed', 'error': str(e)}}))
# Set request id
json_response['response-to-request']['request-id'] = request_id

# Set status
json_response['response-to-request']['status'] = status

# If there was an error
if error:
json_response['response-to-request']['error'] = error

# If there is a summary
if summary:
json_response['response-to-request']['summary'] = summary

# If there is a log file
if log and Path(log).is_file():
# Get log file content
try:
with open(log, 'r') as file:
# Get log content and remove ANSI escape codes
logcontent = file.read()
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
logcontent = ansi_escape.sub('', logcontent)
except Exception as e:
# If content could not be read, then generate an error message
logcontent = 'Error: could not read log file'

json_response['response-to-request']['log'] = logcontent

# Send the response
self.websocket.send(json.dumps(json_response))

# If the message contains 'info'
if 'info' in message:
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Package/Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def update(self, assume_yes: bool = False, ignore_exclude: bool = False, check_u
self.remove_all_exclusions()
self.exitController.clean_exit(0, False)

# Qui here if there was no packages to update
# Quit here if there was no packages to update
if self.packagesToUpdateCount == 0:
return

Expand Down Expand Up @@ -249,7 +249,7 @@ def update(self, assume_yes: bool = False, ignore_exclude: bool = False, check_u

except Exception as e:
print(Fore.RED + ' ✕ ' + Style.RESET_ALL + str(e))
print('\n' + Fore.RED + ' Packages update failed: ' + Style.RESET_ALL)
print('\n' + Fore.RED + ' Packages update failed ' + Style.RESET_ALL)
self.summary['update']['status'] = 'failed'
finally:
# Remove all exclusions
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.0