Conditions | 14 |
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 -*- |
||
34 | def __init__(self, config=None, args=None): |
||
35 | self.config = config |
||
36 | self.args = args |
||
37 | |||
38 | # Quiet mode |
||
39 | self._quiet = args.quiet |
||
40 | self.refresh_time = args.time |
||
41 | |||
42 | # Init stats |
||
43 | start_duration = Counter() |
||
44 | start_duration.reset() |
||
45 | self.stats = GlancesStats(config=config, args=args) |
||
46 | logger.debug("Plugins initialisation duration: {} seconds".format(start_duration.get())) |
||
47 | |||
48 | # Modules (plugins and exporters) are loaded at this point |
||
49 | # Glances can display the list if asked... |
||
50 | if args.modules_list: |
||
51 | self.display_modules_list() |
||
52 | sys.exit(0) |
||
53 | |||
54 | # The args is needed to get the selected process in the process list (Curses mode) |
||
55 | glances_processes.set_args(args) |
||
56 | |||
57 | # If process extended stats is disabled by user |
||
58 | if not args.enable_process_extended: |
||
59 | logger.debug("Extended stats for top process are disabled") |
||
60 | glances_processes.disable_extended() |
||
61 | else: |
||
62 | logger.debug("Extended stats for top process are enabled") |
||
63 | glances_processes.enable_extended() |
||
64 | |||
65 | # Manage optional process filter |
||
66 | if args.process_filter is not None: |
||
67 | logger.info("Process filter is set to: {}".format(args.process_filter)) |
||
68 | glances_processes.process_filter = args.process_filter |
||
69 | |||
70 | if args.export and args.export_process_filter is not None: |
||
71 | logger.info("Export process filter is set to: {}".format(args.export_process_filter)) |
||
72 | glances_processes.export_process_filter = args.export_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_json: |
||
100 | logger.info("Stdout JSON mode is ON, following stats will be displayed: {}".format(args.stdout_json)) |
||
101 | # Init screen |
||
102 | self.screen = GlancesStdoutJson(config=config, args=args) |
||
103 | elif args.stdout_csv: |
||
104 | logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout_csv)) |
||
105 | # Init screen |
||
106 | self.screen = GlancesStdoutCsv(config=config, args=args) |
||
107 | else: |
||
108 | # Default number of processes to displayed is set to 50 |
||
109 | glances_processes.max_processes = 50 |
||
110 | |||
111 | # Init screen |
||
112 | self.screen = GlancesCursesStandalone(config=config, args=args) |
||
113 | |||
114 | # If an error occur during the screen init, continue if export option is set |
||
115 | # It is done in the screen.init function |
||
116 | self._quiet = args.quiet |
||
117 | |||
118 | # Check the latest Glances version |
||
119 | self.outdated = Outdated(config=config, args=args) |
||
120 | |||
211 |