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.4.0 #75

Merged
merged 1 commit into from
Sep 28, 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
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ jobs:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
body: |
**Changes:**

- Fixed update process on RHEL based systems
- Added a new parameter to update only a list of packages
- Reposerver module: added the feature to receive a list of packages to update
**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
draft: false
prerelease: false

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ It should help you **installing** and starting using linupdate.
--assume-yes, -y Answer yes to all questions
--check-updates, -cu Only check for updates and exit
--ignore-exclude, -ie Ignore all package exclusions
--get-update-method Get current update method
--set-update-method [one_by_one|global] Set update method: one_by_one (update packages one by one, one apt command executed for each package) or global (update all packages at once, one single apt command executed for all packages)
--exit-on-package-update-error [true|false] When update method is one_by_one, immediately exit if an error occurs during package update and do not update the remaining packages
--exit-on-package-update-error [true|false] Immediately exit if an error occurs during package update and do not update the remaining packages

Packages exclusion and services restart

Expand Down
5 changes: 3 additions & 2 deletions linupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ def main():
my_args.ignore_exclude,
my_args.check_updates,
my_args.dist_upgrade,
my_args.keep_oldconf)
my_args.keep_oldconf,
my_args.dry_run)

# Execute post-update modules functions
my_module.post(my_package.summary)

# Restart services
my_service.restart(my_package.summary)
my_service.restart(my_package.summary, my_args.dry_run)

# Check if reboot is required
if my_system.reboot_required() is True:
Expand Down
41 changes: 1 addition & 40 deletions src/controllers/App/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ def check_conf(self):
if 'update' not in configuration:
raise Exception('update key is missing in ' + self.config_file)

# Check if update.method is set
if 'method' not in configuration['update']:
raise Exception('update.method key is missing in ' + self.config_file)

# Check if update.method is not empty
if configuration['update']['method'] == None:
raise Exception('update.method key is empty in ' + self.config_file)

# Check if update.exit_on_package_update_error is set
if 'exit_on_package_update_error' not in configuration['update']:
raise Exception('update.exit_on_package_update_error key is missing in ' + self.config_file)
Expand Down Expand Up @@ -409,37 +401,6 @@ def get_mail_recipient(self):
return configuration['main']['mail']['recipient']


#-----------------------------------------------------------------------------------------------
#
# Get update method
#
#-----------------------------------------------------------------------------------------------
def get_update_method(self):
# Get current configuration
configuration = self.get_conf()

return configuration['update']['method']


#-----------------------------------------------------------------------------------------------
#
# Set update method
#
#-----------------------------------------------------------------------------------------------
def set_update_method(self, method: str):
if method not in ['one_by_one', 'global']:
raise Exception('Invalid update method: ' + method)

# Get current configuration
configuration = self.get_conf()

# Set method
configuration['update']['method'] = method

# Write config file
self.write_conf(configuration)


#-----------------------------------------------------------------------------------------------
#
# Set exit on package update error
Expand All @@ -449,7 +410,7 @@ def set_exit_on_package_update_error(self, exit_on_package_update_error: bool):
# Get current configuration
configuration = self.get_conf()

# Set method
# Set exit on package update error
configuration['update']['exit_on_package_update_error'] = exit_on_package_update_error

# Write config file
Expand Down
17 changes: 17 additions & 0 deletions src/controllers/App/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ def remove_ansi(self, text):
# If an exception occurs, simply return the original text as it is
except Exception as e:
return text

#-----------------------------------------------------------------------------------------------
#
# Clean log text
#
#-----------------------------------------------------------------------------------------------
def clean_log(self, text):
# First, remove ANSI escape codes
text = self.remove_ansi(text)

# Replace double line breaks with single line breaks before '|' character (occurs mainly with apt logs)
text = re.sub(r'\n\n \|', '\n |', text)

# Remove leading and trailing whitespaces
text = text.strip()

return text
59 changes: 16 additions & 43 deletions src/controllers/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def parse(self):
Args.packages_to_update = []
Args.dist_upgrade = False
Args.keep_oldconf = True
Args.dry_run = False

myApp = App()
myAppConfig = Config()
Expand Down Expand Up @@ -77,6 +78,8 @@ def parse(self):
parser.add_argument("--update", "-u", action="store", nargs='?', default="null")
# Dist upgrade
parser.add_argument("--dist-upgrade", "-du", action="store_true", default="null")
# Dry run
parser.add_argument("--dry-run", action="store_true", default="null")
# Keep oldconf
parser.add_argument("--keep-oldconf", action="store_true", default="null")
# Force / assume-yes
Expand All @@ -85,10 +88,6 @@ def parse(self):
parser.add_argument("--check-updates", "-cu", action="store_true", default="null")
# Ignore exclude
parser.add_argument("--ignore-exclude", "-ie", action="store_true", default="null")
# Get update method
parser.add_argument("--get-update-method", action="store", nargs='?', default="null")
# Set Update method
parser.add_argument("--set-update-method", action="store", nargs='?', default="null")
# Exit on package update error
parser.add_argument("--exit-on-package-update-error", action="store", nargs='?', default="null")

Expand Down Expand Up @@ -310,6 +309,12 @@ def parse(self):
Args.packages_to_update.append({'name': package.strip()})
except Exception as e:
raise ArgsException('Could not parse update list: ' + str(e))

#
# If --dry-run param has been set
#
if args.dry_run != "null":
Args.dry_run = True

#
# If --ignore-exclude param has been set
Expand Down Expand Up @@ -341,28 +346,6 @@ def parse(self):
if args.assume_yes != "null":
Args.assume_yes = True

#
# If --get-update-method param has been set
#
if args.get_update_method != "null":
try:
update_method = myAppConfig.get_update_method()
print(' Current update method: ' + Fore.GREEN + update_method + Style.RESET_ALL, end='\n\n')
myExit.clean_exit(0, False)
except Exception as e:
raise ArgsException('Could not get update method: ' + str(e))

#
# If --set-update-method param has been set
#
if args.set_update_method != "null":
try:
myAppConfig.set_update_method(args.set_update_method)
print(' Update method set to ' + Fore.GREEN + args.set_update_method + Style.RESET_ALL, end='\n\n')
myExit.clean_exit(0, False)
except Exception as e:
raise ArgsException('Could not set update method: ' + str(e))

#
# If --exit-on-package-update-error param has been set
#
Expand Down Expand Up @@ -510,9 +493,6 @@ def parse(self):

print(' Setting services to restart after package update: ' + Fore.GREEN)

for service in services:
print(' ▪ ' + service)

# If no service is set to restart
if not services:
print(' ▪ None')
Expand Down Expand Up @@ -658,6 +638,12 @@ def help(self):
],
'description': 'Enable distribution upgrade when updating packages (Debian based OS only)'
},
{
'args': [
'--dry-run'
],
'description': 'Simulate the update process (do not update packages)'
},
{
'args': [
'--keep-oldconf'
Expand Down Expand Up @@ -685,25 +671,12 @@ def help(self):
],
'description': 'Ignore all package exclusions'
},
{
'args': [
'--get-update-method',
],
'description': 'Get current update method'
},
{
'args': [
'--set-update-method',
],
'option': 'one_by_one|global',
'description': 'Set update method: one_by_one (update packages one by one, one apt command executed for each package) or global (update all packages at once, one single apt command executed for all packages)'
},
{
'args': [
'--exit-on-package-update-error',
],
'option': 'true|false',
'description': 'When update method is one_by_one, immediately exit if an error occurs during package update and do not update the remaining packages'
'description': 'Immediately exit if an error occurs during package update and do not update the remaining packages'
},
{
'title': 'Packages exclusion and services restart'
Expand Down
Loading