Conditions | 6 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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:
1 | """ |
||
32 | def __init__(self, config_files=None, plugins=None, strict=False): |
||
33 | if config_files is None: |
||
34 | config_files = [] |
||
35 | |||
36 | self.strict = strict |
||
37 | |||
38 | #: logging object for sending log messages. Example:: |
||
39 | #: |
||
40 | #: from groundwork import App |
||
41 | #: my_app = App() |
||
42 | #: my_app.log.debug("Send debug message") |
||
43 | #: my_app.log.error("Send error....") |
||
44 | self.log = logging.getLogger("groundwork") |
||
45 | |||
46 | self._configure_logging() |
||
47 | self.log.info("Initializing groundwork") |
||
48 | self.log.info("Reading configuration") |
||
49 | |||
50 | #: Instance of :class:`~groundwork.configuration.configmanager.ConfigManager`. |
||
51 | #: Used to load different configuration files and create a common configuration object. |
||
52 | self.config = ConfigManager().load(config_files) |
||
53 | |||
54 | #: Absolute application path. Is configurable by parameter "APP_PATH" of a configuration file. |
||
55 | #: If not given, the current working directory is taken. |
||
56 | #: The path is used to calculate absolute paths for tests, documentation and much more. |
||
57 | self.path = self.config.get("APP_PATH", None) |
||
58 | if self.path is None: |
||
59 | self.path = os.getcwd() |
||
60 | elif not os.path.isabs(self.path): |
||
61 | self.path = os.path.abspath(self.path) |
||
62 | self.log.warning("Given APP_PATH is relative, calculated following, absolute path: %s" % self.path) |
||
63 | elif not os.path.exists(self.path): |
||
64 | raise NotADirectoryError("Given APP_PATH does not exist: %s" % self.path) |
||
65 | |||
66 | self._configure_logging(self.config.get("GROUNDWORK_LOGGING")) |
||
67 | |||
68 | #: Name of the application. Is configurable by parameter "APP_NAME" of a configuration file. |
||
69 | self.name = self.config.get("APP_NAME", None) or "NoName App" |
||
70 | |||
71 | #: Instance of :class:`~groundwork.signals.SignalsApplication`. Provides functions to register and fire |
||
72 | # signals or receivers on application level. |
||
73 | self.signals = SignalsApplication(app=self) |
||
74 | |||
75 | self.signals.register("plugin_activate_pre", self, |
||
76 | "Gets send right before activation routine of a plugins will be executed") |
||
77 | self.signals.register("plugin_activate_post", self, |
||
78 | "Gets send right after activation routine of a plugins was executed") |
||
79 | self.signals.register("plugin_deactivate_pre", self, |
||
80 | "Gets send right before deactivation routine of a plugins will be executed") |
||
81 | self.signals.register("plugin_deactivate_post", self, |
||
82 | "Gets send right after deactivation routine of a plugins was executed") |
||
83 | |||
84 | #: Instance of :class:`~groundwork.pluginmanager.PluginManager`- Provides functions to load, activate and |
||
85 | # deactivate plugins. |
||
86 | self.plugins = PluginManager(app=self) |
||
87 | |||
88 | if plugins is not None: |
||
89 | self.plugins.classes.register(plugins) |
||
90 | |||
121 |