true-public-access / Seagull

Seagull is a toolset to uncage information. To put an eye in the sky that guides us through the maze of bureaucracy and over the mountains of paperwork. To give us the wings to fly and eyes to see the truth.
GNU General Public License v2.0
4 stars 4 forks source link

Settings Refinement (#66) #67

Closed Iain-Crowe closed 3 months ago

Iain-Crowe commented 4 months ago

Pull Request: Refactor Settings Management (#66)

Description

This pull request introduces significant refactoring to the settings management system. The key changes are as follows:

  1. Code Refactoring:
    • Merged redundant imports
    • Moved hardcoded paths to use os.path.join for better portability
    • Introduced global SETTINGS dictionary to hold settings in memory.
    • Added type hints for readability.
    • Encapsulated private methods and constants for better code organization.
  2. Error Handling:
    • Created SettingsNotFoundError to handle cases where settings are not initialized properly.
    • Improved error handling during file operations, including JSON-specific errors.
  3. Functionality Enhancements:
    • Added init_settings() method to initialize settings from JSON file.
    • Added _dump_settings() method to save the current state of SETTINGS to the JSON file.
    • Modified/renamed update_setting() and read_setting() methods to interact with global SETTINGS dictionary.
    • NOTE: init_settings() should only be called once, please ask for details on best usage, if unsure.
  4. Licensing and Documentation:
    • Added the GPL license to top of file.
    • Included docstrings for all methods to explain purpose and usage.
    • Added a note about how we should handle settings within the project.

      Issues Addressed

    • Resolves issue #66: Settings Refinement

      How to Test:

  5. Run the script to ensure the settings are being properly loaded and saved.
  6. Modify a setting and verify the changes are being reflected in the JSON file.
  7. Ensure appropriate error messages are displayed when the settings file is missing or corrupted.

    Code Sample

    if __name__ == "__main__":
    init_settings()
    
    print(read_settings("showtc")
    update_setting("showtc", False)
    print(read_settings("showtc")

    Additional Notes

    Future improvements could include moving the custom class into a dedicated exceptions file and integrating a logging library for better error tracking (noted in comments).

    • Fixed requirements.txt, should be able to simply run pip install -r requirements.txt
    • Updated settings usage in other files front.py and orca.py
    • Renamed setings to settings