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

Reworked update station files, version upgrade and traslation #57

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ericbsd
Copy link
Member

@ericbsd ericbsd commented Oct 31, 2024

This is the first part for ghostbsd/issues#29

I have reworked extensively, including how the PO and files are created.

More tests are needed to fix the upgrade loop.

@ericbsd ericbsd self-assigned this Oct 31, 2024
@ericbsd ericbsd requested review from a team as code owners October 31, 2024 21:00
Copy link

sourcery-ai bot commented Oct 31, 2024

Reviewer's Guide by Sourcery

This PR extensively reworks the update station implementation, focusing on improving translation handling and code organization. The changes include a new translation management system, restructured package layout, and enhanced UI components with better error handling and user notifications.

Class diagram for translation management system

classDiagram
    class UpdateTranslationsCommand {
        +run()
        +initialize_options()
        +finalize_options()
    }
    class CreateTranslationCommand {
        +run()
        +initialize_options()
        +finalize_options()
        +locale
    }
    Command <|-- UpdateTranslationsCommand
    Command <|-- CreateTranslationCommand
    note for UpdateTranslationsCommand "Handles extraction and updating of translation files"
    note for CreateTranslationCommand "Creates new translation files for specified locales"
Loading

Class diagram for update station UI components

classDiagram
    class UpdateWindow {
        +delete_event()
        +start_update()
        +if_backup()
        +create_bbox()
    }
    class InstallUpdate {
        +close_application()
        +read_output()
        +stop_tread()
    }
    class StartCheckUpdate {
        +close_application()
        +check_for_update()
        +update_progress()
    }
    class UpdateNotifier {
        +notify()
        +on_activated()
    }
    class TrayIcon {
        +tray_icon()
        +nm_menu()
        +left_click()
        +icon_clicked()
    }
    UpdateWindow <|-- InstallUpdate
    UpdateWindow <|-- StartCheckUpdate
    UpdateNotifier <|-- TrayIcon
    note for UpdateWindow "Main window for update management"
    note for InstallUpdate "Displays update progress"
    note for StartCheckUpdate "Checks for available updates"
    note for UpdateNotifier "Handles update notifications"
    note for TrayIcon "Manages system tray icon for updates"
Loading

File-Level Changes

Change Details Files
Implemented new translation management system
  • Added UpdateTranslationsCommand to extract messages to .pot and update .po files
  • Added CreateTranslationCommand to create new .po files for specific languages
  • Removed direct shell script compilation of translations
  • Added command-line interface for translation management
setup.py
README.md
Restructured package layout and improved code organization
  • Moved source files from src/ to update_station/ package
  • Split functionality into separate modules (backend, frontend, dialog, notification)
  • Created dedicated Data class for shared application state
  • Added type hints and improved function documentation
update_station/backend.py
update_station/data.py
update_station/frontend.py
update_station/dialog.py
update_station/notification.py
update_station/common.py
Enhanced UI components and user interaction
  • Added system tray icon support with notification capabilities
  • Implemented major version upgrade handling with user prompts
  • Added progress tracking for update operations
  • Created dedicated dialog windows for various update states and errors
update_station/frontend.py
update_station/dialog.py
update_station/notification.py
Updated package dependencies and system requirements
  • Updated need_reboot.json with new package dependencies
  • Added support for newer NVIDIA drivers and kernel modules
  • Removed outdated OS generic packages
src/need_reboot.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ericbsd - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please add tests to address the upgrade loop issue mentioned in the PR description before merging
  • The README should include more detailed documentation about the new translation workflow and commands
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 3 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

:param fraction: The fraction to add.
:param text: The text to display.
"""
new_val = progress.get_fraction() + fraction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add bounds checking to prevent progress bar fraction from exceeding valid range

The progress bar fraction should be clamped between 0.0 and 1.0 to prevent invalid states. Consider using: new_val = min(1.0, max(0.0, progress.get_fraction() + fraction))

Suggested change
new_val = progress.get_fraction() + fraction
new_val = min(1.0, max(0.0, progress.get_fraction() + fraction))

self.notification = None
Notify.init('Test')
self.msg = _("Software updates are now available.")
self.timeout = 10000 # 10 seconds
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Unused timeout variable in notification setup

The timeout value is defined but never used. Either remove it or pass it to the notification with set_timeout().

GhostBSD update manager.


## Create up
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Section title 'Create up' is unclear and doesn't reflect the content about translations

Consider using a more descriptive title like 'Translation Setup' or 'Managing Translations'

Suggested change
## Create up
## Managing Translations



## Create up
To create translation file.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (documentation): Missing article before 'translation file'

Should be 'To create a translation file.'

./setup.py create_translation --locale=fr
```

To updated translation files
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (documentation): Grammatical error in command description

Should be 'To update translation files'

Comment on lines +97 to +103
backup_checkbox.set_active(True)
backup_checkbox.set_sensitive(True)
Data.backup = True
else:
backup_checkbox.set_active(False)
backup_checkbox.set_sensitive(False)
Data.backup = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Extract duplicate code into method (extract-duplicate-method)

i_num = 0
ri_num = 0
if bool(Data.packages_dictionary['remove']):
r_num = len(Data.packages_dictionary['remove'])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Extract duplicate code into method (extract-duplicate-method)

self.thr = threading.Thread(target=self.read_output, args=[self.pbar], daemon=True)
self.thr.start()

def read_output(self, progress):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:


Explanation

The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

"""
if updating():
unlock_update_station()
if fail is True:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

GLib.idle_add(self.update_progress, progress,
_('The repository is online'))
sleep(1)
if repository_is_syncing() is True:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

1 participant