| Conditions | 11 |
| Total Lines | 70 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like glances.standalone.GlancesStandalone.__init__() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 42 | def __init__(self, config=None, args=None): |
||
| 43 | self.config = config |
||
| 44 | self.args = args |
||
| 45 | |||
| 46 | # Quiet mode |
||
| 47 | self._quiet = args.quiet |
||
| 48 | self.refresh_time = args.time |
||
| 49 | |||
| 50 | # Init stats |
||
| 51 | start_duration = Counter() |
||
| 52 | start_duration.reset() |
||
| 53 | self.stats = GlancesStats(config=config, args=args) |
||
| 54 | logger.debug("Plugins initialisation duration: {} seconds".format(start_duration.get())) |
||
| 55 | |||
| 56 | # Modules (plugins and exporters) are loaded at this point |
||
| 57 | # Glances can display the list if asked... |
||
| 58 | if args.modules_list: |
||
| 59 | self.display_modules_list() |
||
| 60 | sys.exit(0) |
||
| 61 | |||
| 62 | # If process extended stats is disabled by user |
||
| 63 | if not args.enable_process_extended: |
||
| 64 | logger.debug("Extended stats for top process are disabled") |
||
| 65 | glances_processes.disable_extended() |
||
| 66 | else: |
||
| 67 | logger.debug("Extended stats for top process are enabled") |
||
| 68 | glances_processes.enable_extended() |
||
| 69 | |||
| 70 | # Manage optional process filter |
||
| 71 | if args.process_filter is not None: |
||
| 72 | glances_processes.process_filter = args.process_filter |
||
| 73 | |||
| 74 | if (not WINDOWS) and args.no_kernel_threads: |
||
| 75 | # Ignore kernel threads in process list |
||
| 76 | glances_processes.disable_kernel_threads() |
||
| 77 | |||
| 78 | # Initial system information update |
||
| 79 | start_duration.reset() |
||
| 80 | self.stats.update() |
||
| 81 | logger.debug("First stats update duration: {} seconds".format(start_duration.get())) |
||
| 82 | |||
| 83 | if self.quiet: |
||
| 84 | logger.info("Quiet mode is ON, nothing will be displayed") |
||
| 85 | # In quiet mode, nothing is displayed |
||
| 86 | glances_processes.max_processes = 0 |
||
| 87 | elif args.stdout_issue: |
||
| 88 | logger.info("Issue mode is ON") |
||
| 89 | # Init screen |
||
| 90 | self.screen = GlancesStdoutIssue(config=config, args=args) |
||
| 91 | elif args.stdout_apidoc: |
||
| 92 | logger.info("Fields descriptions mode is ON") |
||
| 93 | # Init screen |
||
| 94 | self.screen = GlancesStdoutApiDoc(config=config, args=args) |
||
| 95 | elif args.stdout: |
||
| 96 | logger.info("Stdout mode is ON, following stats will be displayed: {}".format(args.stdout)) |
||
| 97 | # Init screen |
||
| 98 | self.screen = GlancesStdout(config=config, args=args) |
||
| 99 | elif args.stdout_csv: |
||
| 100 | logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout_csv)) |
||
| 101 | # Init screen |
||
| 102 | self.screen = GlancesStdoutCsv(config=config, args=args) |
||
| 103 | else: |
||
| 104 | # Default number of processes to displayed is set to 50 |
||
| 105 | glances_processes.max_processes = 50 |
||
| 106 | |||
| 107 | # Init screen |
||
| 108 | self.screen = GlancesCursesStandalone(config=config, args=args) |
||
| 109 | |||
| 110 | # Check the latest Glances version |
||
| 111 | self.outdated = Outdated(config=config, args=args) |
||
| 112 | |||
| 200 |