Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_app_manager.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 402d31527af4 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
82 self._managers = {} | 82 self._managers = {} |
83 self._apps = {} | 83 self._apps = {} |
84 self._started = {} | 84 self._started = {} |
85 # instance id to app data map | 85 # instance id to app data map |
86 self._instances = {} | 86 self._instances = {} |
87 host.bridge.addMethod( | 87 host.bridge.add_method( |
88 "applicationsList", | 88 "applications_list", |
89 ".plugin", | 89 ".plugin", |
90 in_sign="as", | 90 in_sign="as", |
91 out_sign="as", | 91 out_sign="as", |
92 method=self.list_applications, | 92 method=self.list_applications, |
93 ) | 93 ) |
94 host.bridge.addMethod( | 94 host.bridge.add_method( |
95 "applicationStart", | 95 "application_start", |
96 ".plugin", | 96 ".plugin", |
97 in_sign="ss", | 97 in_sign="ss", |
98 out_sign="s", | 98 out_sign="s", |
99 method=self._start, | 99 method=self._start, |
100 async_=True, | 100 async_=True, |
101 ) | 101 ) |
102 host.bridge.addMethod( | 102 host.bridge.add_method( |
103 "applicationStop", | 103 "application_stop", |
104 ".plugin", | 104 ".plugin", |
105 in_sign="sss", | 105 in_sign="sss", |
106 out_sign="", | 106 out_sign="", |
107 method=self._stop, | 107 method=self._stop, |
108 async_=True, | 108 async_=True, |
109 ) | 109 ) |
110 host.bridge.addMethod( | 110 host.bridge.add_method( |
111 "applicationExposedGet", | 111 "application_exposed_get", |
112 ".plugin", | 112 ".plugin", |
113 in_sign="sss", | 113 in_sign="sss", |
114 out_sign="s", | 114 out_sign="s", |
115 method=self._get_exposed, | 115 method=self._get_exposed, |
116 async_=True, | 116 async_=True, |
117 ) | 117 ) |
118 # application has been started succeesfully, | 118 # application has been started succeesfully, |
119 # args: name, instance_id, extra | 119 # args: name, instance_id, extra |
120 host.bridge.addSignal( | 120 host.bridge.add_signal( |
121 "application_started", ".plugin", signature="sss" | 121 "application_started", ".plugin", signature="sss" |
122 ) | 122 ) |
123 # application went wrong with the application | 123 # application went wrong with the application |
124 # args: name, instance_id, extra | 124 # args: name, instance_id, extra |
125 host.bridge.addSignal( | 125 host.bridge.add_signal( |
126 "application_error", ".plugin", signature="sss" | 126 "application_error", ".plugin", signature="sss" |
127 ) | 127 ) |
128 yaml.add_constructor( | 128 yaml.add_constructor( |
129 "!sat_conf", self._sat_conf_constr, Loader=Loader) | 129 "!sat_conf", self._sat_conf_constr, Loader=Loader) |
130 yaml.add_constructor( | 130 yaml.add_constructor( |
167 raise ValueError( | 167 raise ValueError( |
168 f"invalid !sat_conf value ({config_data!r}), a list of 1 to 4 items is " | 168 f"invalid !sat_conf value ({config_data!r}), a list of 1 to 4 items is " |
169 "expected" | 169 "expected" |
170 ) | 170 ) |
171 | 171 |
172 value = self.host.memory.getConfig(section, name, default) | 172 value = self.host.memory.config_get(section, name, default) |
173 # FIXME: "public_url" is used only here and doesn't take multi-sites into account | 173 # FIXME: "public_url" is used only here and doesn't take multi-sites into account |
174 if name == "public_url" and (not value or value.startswith('http')): | 174 if name == "public_url" and (not value or value.startswith('http')): |
175 if not value: | 175 if not value: |
176 log.warning(_( | 176 log.warning(_( |
177 'No value found for "public_url", using "example.org" for ' | 177 'No value found for "public_url", using "example.org" for ' |
406 instance_id, "instance", {"skip_compute": True} | 406 instance_id, "instance", {"skip_compute": True} |
407 ) | 407 ) |
408 log.info(f"{app_name!r} is already started or being started") | 408 log.info(f"{app_name!r} is already started or being started") |
409 return ret_data | 409 return ret_data |
410 else: | 410 else: |
411 cache_path = self.host.memory.getCachePath( | 411 cache_path = self.host.memory.get_cache_path( |
412 PLUGIN_INFO[C.PI_IMPORT_NAME], app_name | 412 PLUGIN_INFO[C.PI_IMPORT_NAME], app_name |
413 ) | 413 ) |
414 cache_path.mkdir(0o700, parents=True, exist_ok=True) | 414 cache_path.mkdir(0o700, parents=True, exist_ok=True) |
415 app_data['_instance_dir_path'] = cache_path | 415 app_data['_instance_dir_path'] = cache_path |
416 else: | 416 else: |