| Conditions | 15 |
| Total Lines | 86 |
| Code Lines | 51 |
| 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 -*- |
||
| 33 | def __init__(self, config=None, args=None): |
||
| 34 | self.config = config |
||
| 35 | self.args = args |
||
| 36 | |||
| 37 | # Quiet mode |
||
| 38 | self._quiet = args.quiet |
||
| 39 | self.refresh_time = args.time |
||
| 40 | |||
| 41 | # Init stats |
||
| 42 | start_duration = Counter() |
||
| 43 | start_duration.reset() |
||
| 44 | self.stats = GlancesStats(config=config, args=args) |
||
| 45 | logger.debug("Plugins initialisation duration: {} seconds".format(start_duration.get())) |
||
| 46 | |||
| 47 | # Modules (plugins and exporters) are loaded at this point |
||
| 48 | # Glances can display the list if asked... |
||
| 49 | if args.modules_list: |
||
| 50 | self.display_modules_list() |
||
| 51 | sys.exit(0) |
||
| 52 | |||
| 53 | # The args is needed to get the selected process in the process list (Curses mode) |
||
| 54 | glances_processes.set_args(args) |
||
| 55 | |||
| 56 | # If process extended stats is disabled by user |
||
| 57 | if not args.enable_process_extended: |
||
| 58 | logger.debug("Extended stats for top process are disabled") |
||
| 59 | glances_processes.disable_extended() |
||
| 60 | else: |
||
| 61 | logger.debug("Extended stats for top process are enabled") |
||
| 62 | glances_processes.enable_extended() |
||
| 63 | |||
| 64 | # Manage optional process filter |
||
| 65 | if args.process_filter is not None: |
||
| 66 | logger.info("Process filter is set to: {}".format(args.process_filter)) |
||
| 67 | glances_processes.process_filter = args.process_filter |
||
| 68 | |||
| 69 | if (args.export or args.stdout) and args.export_process_filter is not None: |
||
| 70 | logger.info("Export process filter is set to: {}".format(args.export_process_filter)) |
||
| 71 | glances_processes.export_process_filter = args.export_process_filter |
||
| 72 | |||
| 73 | if (not WINDOWS) and args.no_kernel_threads: |
||
| 74 | # Ignore kernel threads in process list |
||
| 75 | glances_processes.disable_kernel_threads() |
||
| 76 | |||
| 77 | # Initial system information update |
||
| 78 | start_duration.reset() |
||
| 79 | self.stats.update() |
||
| 80 | logger.debug("First stats update duration: {} seconds".format(start_duration.get())) |
||
| 81 | |||
| 82 | if self.quiet: |
||
| 83 | logger.info("Quiet mode is ON, nothing will be displayed") |
||
| 84 | # In quiet mode, nothing is displayed |
||
| 85 | glances_processes.max_processes = 0 |
||
| 86 | elif args.stdout_issue: |
||
| 87 | logger.info("Issue mode is ON") |
||
| 88 | # Init screen |
||
| 89 | self.screen = GlancesStdoutIssue(config=config, args=args) |
||
| 90 | elif args.stdout_apidoc: |
||
| 91 | logger.info("Fields descriptions mode is ON") |
||
| 92 | # Init screen |
||
| 93 | self.screen = GlancesStdoutApiDoc(config=config, args=args) |
||
| 94 | elif args.stdout: |
||
| 95 | logger.info("Stdout mode is ON, following stats will be displayed: {}".format(args.stdout)) |
||
| 96 | # Init screen |
||
| 97 | self.screen = GlancesStdout(config=config, args=args) |
||
| 98 | elif args.stdout_json: |
||
| 99 | logger.info("Stdout JSON mode is ON, following stats will be displayed: {}".format(args.stdout_json)) |
||
| 100 | # Init screen |
||
| 101 | self.screen = GlancesStdoutJson(config=config, args=args) |
||
| 102 | elif args.stdout_csv: |
||
| 103 | logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout_csv)) |
||
| 104 | # Init screen |
||
| 105 | self.screen = GlancesStdoutCsv(config=config, args=args) |
||
| 106 | else: |
||
| 107 | # Default number of processes to displayed is set to 50 |
||
| 108 | glances_processes.max_processes = 50 |
||
| 109 | |||
| 110 | # Init screen |
||
| 111 | self.screen = GlancesCursesStandalone(config=config, args=args) |
||
| 112 | |||
| 113 | # If an error occur during the screen init, continue if export option is set |
||
| 114 | # It is done in the screen.init function |
||
| 115 | self._quiet = args.quiet |
||
| 116 | |||
| 117 | # Check the latest Glances version |
||
| 118 | self.outdated = Outdated(config=config, args=args) |
||
| 119 | |||
| 211 |