Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Sep 23, 2024
1 parent 3add8cc commit fa94a3c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 44 deletions.
44 changes: 37 additions & 7 deletions src/controllers/Module/Reposerver/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def run_inotify_package_event(self):
self.inotify_exception = str(e)


#-----------------------------------------------------------------------------------------------
#
# Set request status
#
#-----------------------------------------------------------------------------------------------
def set_request_status(self, request_id, status):
json_data = {
'response-to-request': {
'request-id': request_id,
'status': status
}
}

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


#-----------------------------------------------------------------------------------------------
#
# On message received from the websocket
Expand Down Expand Up @@ -175,13 +192,21 @@ def websocket_on_message(self, ws, message):
# 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')

# Send a response to the reposerver to make the request as running
self.set_request_status(request_id, 'running')

# Log everything to the log file
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')

# Send a response to the reposerver to make the request as running
self.set_request_status(request_id, 'running')

# Log everything to the log file
with Log(log):
self.packageController.update([], True)
Expand All @@ -191,15 +216,20 @@ def websocket_on_message(self, ws, message):

# Case the request is 'request-specific-packages-installation', then update a list of packages
# A list of packages must be provided in the message
elif message['request'] == 'request-specific-packages-installation' and 'packages' in message and len(message['packages']) > 0:
print('[reposerver-agent] Reposerver requested to update a list of packages')
elif message['request'] == 'request-specific-packages-installation':
if 'data' in message:
if 'packages' in message['data'] and len(message['data']['packages']) > 0:
print('[reposerver-agent] Reposerver requested to update a list of packages')

# Log everything to the log file
with Log(log):
self.packageController.update(message['packages'], True)
# Send a response to the reposerver to make the request as running
self.set_request_status(request_id, 'running')

# Send a summary to the reposerver, with the summary of the installation (number of packages installed or failed)
summary = self.packageController.summary
# Log everything to the log file
with Log(log):
self.packageController.update(message['data']['packages'], True)

# Send a summary to the reposerver, with the summary of the installation (number of packages installed or failed)
summary = self.packageController.summary

else:
raise Exception('unknown request sent by reposerver: ' + message['request'])
Expand Down
30 changes: 15 additions & 15 deletions src/controllers/Package/Apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ def __init__(self):
# Create an instance of the apt cache
self.aptcache = apt.Cache()

# Total count of success and failed package updates
self.summary = {
'update': {
'success': {
'count': 0,
'packages': {}
},
'failed': {
'count': 0,
'packages': {}
}
}
}

# Define some default options
self.dist_upgrade = False
self.keep_oldconf = True
Expand Down Expand Up @@ -256,6 +242,20 @@ def update(self, packagesList, update_method: str = 'one_by_one', exit_on_packag
# Log file to store each package update output (when 'one_by_one' method is used)
log = '/tmp/linupdate-update-package.log'

# Package update summary
self.summary = {
'update': {
'success': {
'count': 0,
'packages': {}
},
'failed': {
'count': 0,
'packages': {}
}
}
}

# If update_method is 'one_by_one', update packages one by one (one command per package)
if update_method == 'one_by_one':
# Loop through the list of packages to update
Expand Down Expand Up @@ -302,7 +302,7 @@ def update(self, packagesList, update_method: str = 'one_by_one', exit_on_packag
cmd = [
'apt-get', 'install', pkg['name'] + '=' + pkg['available_version'], '-y',
# Debug only
'--dry-run',
# '--dry-run',
'-o', 'Dpkg::Options::=--force-confdef',
'-o', 'Dpkg::Options::=--force-confold'
]
Expand Down
29 changes: 14 additions & 15 deletions src/controllers/Package/Dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
from src.controllers.App.Utils import Utils

class Dnf:
def __init__(self):
# Total count of success and failed package updates
self.summary = {
'update': {
'success': {
'count': 0,
'packages': {}
},
'failed': {
'count': 0,
'packages': {}
}
}
}

#-----------------------------------------------------------------------------------------------
#
# Return the current version of a package
Expand Down Expand Up @@ -296,6 +281,20 @@ def update(self, packagesList, update_method: str = 'one_by_one', exit_on_packag
# Log file to store each package update output (when 'one_by_one' method is used)
log = '/tmp/linupdate-update-package.log'

# Package update summary
self.summary = {
'update': {
'success': {
'count': 0,
'packages': {}
},
'failed': {
'count': 0,
'packages': {}
}
}
}

# If update_method is 'one_by_one', update packages one by one (one command per package)
if update_method == 'one_by_one':
# Loop through the list of packages to update
Expand Down
21 changes: 14 additions & 7 deletions src/controllers/Package/Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,20 @@ def update(self, packages_list: list = [], assume_yes: bool = False, ignore_excl
package['current_version'] = self.myPackageManagerController.get_current_version(package['name'])
package['available_version'] = self.myPackageManagerController.get_available_version(package['name'])

# If current version and available version have been found, then add the package to the final list
if package['current_version'] != '' and package['available_version'] != '':
packages_list_temp.append({
'name': package['name'],
'current_version': package['current_version'],
'available_version': package['available_version']
})
# If current version or available version have not been found, skip the package
if package['current_version'] == '' or package['available_version'] == '':
continue

# If current version and available version are the same, skip the package
if package['current_version'] == package['available_version']:
continue

# Add the package to the list
packages_list_temp.append({
'name': package['name'],
'current_version': package['current_version'],
'available_version': package['available_version']
})

self.packagesToUpdateList = packages_list_temp

Expand Down

0 comments on commit fa94a3c

Please sign in to comment.