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

Reduce code complexity #2801

Open
nicolargo opened this issue May 26, 2024 · 14 comments · Fixed by #2919
Open

Reduce code complexity #2801

nicolargo opened this issue May 26, 2024 · 14 comments · Fixed by #2919

Comments

@nicolargo
Copy link
Owner

nicolargo commented May 26, 2024

Reduce complexity of function higher than 20:

https://scrutinizer-ci.com/g/nicolargo/glances/code-structure/develop?elementType=py-function&orderField=conditional_complexity&order=desc&changesExpanded=0

@ariel-anieli
Copy link
Contributor

Hello @nicolargo,
I will take on glances.plugins.system.PluginModel.update(). For us to agree on the expectation; I should follow How to fix, and that's it. Is it right?

@nicolargo
Copy link
Owner Author

nicolargo commented Jul 22, 2024

@ariel-anieli yes and all code optimization that look interesting to you .

Thanks !

@ariel-anieli
Copy link
Contributor

@ariel-anieli yes and all code optimization that loo, interesting to you .

Thanks !

🙂 Je t'en prie! I will keep you posted.

ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 22, 2024
Part of nicolargo#2801. Broke `update` in two parts:

* if `local`, stats taken from `get_stats_from_std_sys_lib`
* and readability achieved by `add_human_readable_name`
* else if `snmp`, taken from `update_stats_with_snmp`.

`get_stats_from_std_sys_lib` has two helpers:

1. `get_win_version_and_platform`.
2. `get_linux_version_and_distro`.

Signed-off-by: Ariel Otilibili <[email protected]>
@ariel-anieli
Copy link
Contributor

@nicolargo
Copy link
Owner Author

Huge task :) This method is historical...

@ariel-anieli
Copy link
Contributor

Huge task :) This method is historical...

🙂 I'll have a try. Are there caveats worth noticing?

ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 24, 2024
Part of nicolargo#2801. Broken `msg_curse`: if no stats returns empty list, else:

1. `define_headers_from_os`
2. `maybe_build_string_msg`
3. `display_cpu_stats_per_line`
4. `manage_max_cpu_to_display`
5. Then, for CPU:
   * `display_cpu_header_in_columns`
   * `display_cpu_stats_in_columns`
6. Hence, `summarize_all_cpus_not_displayed`

Signed-off-by: Ariel Otilibili <[email protected]>
@ariel-anieli
Copy link
Contributor

ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 26, 2024
Part of nicolargo#2801. Common tests follows the flow:

* `reset_stats_history_and_views`
* `do_checks_before_update`
* add first element with `update_stats`
* `check_stats`
* `filter_stats`
* add second element `update_stats`
* `chk_hist_maybe_add_third_elem`
* `check_views`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 26, 2024
Part of nicolargo#2801. Common tests follows the flow:

* `reset_stats_history_and_views`
* `do_checks_before_update`
* add first element with `update_stats`
* `check_stats`
* `filter_stats`
* add second element `update_stats`
* `chk_hist_maybe_add_third_elem`
* `check_views`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 27, 2024
Part of nicolargo#2801. Common tests follows the flow:

* `reset_stats_history_and_views`
* `do_checks_before_update`
* add first element with `update_stats`
* `check_stats`
* `filter_stats`
* add second element `update_stats`
* `chk_hist_maybe_add_third_elem`
* `check_views`.

Signed-off-by: Ariel Otilibili <[email protected]>
@ariel-anieli
Copy link
Contributor

I will tackle _GlancesCurses.__catch_key()

ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Jul 27, 2024
Part of nicolargo#2801. Broken down `__catch_key` in two parts:

* `catch_actions_from_hotkey`
* `catch_other_actions_maybe_return_to_browser`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 1, 2024
* part of nicolargo#2801
* formatted into a dict; if input method is SNMP, returns default stats
* if input method is local, calls `get_stats_for_local_input`
* it has three steps:  `get_private_ipv4`, `get_first_ipv4`, `get_public_ipv4`.

Signed-off-by: Ariel Otilibili <[email protected]>
@ariel-anieli
Copy link
Contributor

I'll take on glances.processes.GlancesProcesses.update.

ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 11, 2024
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 11, 2024
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 22, 2024
* part of nicolargo#2801
* second take of 09bf06d0e04d036f676a32d4324750cc019334b5
* reverted in 0c635af.
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 22, 2024
* part of nicolargo#2801
* second take of 09bf06d0e04d036f676a32d4324750cc019334b5
* reverted in 0c635af.
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 22, 2024
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 23, 2024
* part of nicolargo#2801
* second take of 1fda541
* reverted in 0c635af.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 23, 2024
* part of nicolargo#2801
* second take of 1fda541
* reverted in 0c635af.

Signed-off-by: Ariel Otilibili <[email protected]>
ariel-anieli added a commit to ariel-anieli/glances that referenced this issue Nov 23, 2024
* part of nicolargo#2801
* second take of 1fda541
* reverted in 0c635af.

Signed-off-by: Ariel Otilibili <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants