Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_forums.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 | be6d91572633 |
children | 4b842c1fb686 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
52 "--key", | 52 "--key", |
53 default="", | 53 default="", |
54 help=_("forum key (DEFAULT: default forums)"), | 54 help=_("forum key (DEFAULT: default forums)"), |
55 ) | 55 ) |
56 | 56 |
57 def getTmpSuff(self): | 57 def get_tmp_suff(self): |
58 """return suffix used for content file""" | 58 """return suffix used for content file""" |
59 return "json" | 59 return "json" |
60 | 60 |
61 async def publish(self, forums_raw): | 61 async def publish(self, forums_raw): |
62 try: | 62 try: |
63 await self.host.bridge.forumsSet( | 63 await self.host.bridge.forums_set( |
64 forums_raw, | 64 forums_raw, |
65 self.args.service, | 65 self.args.service, |
66 self.args.node, | 66 self.args.node, |
67 self.args.key, | 67 self.args.key, |
68 self.profile, | 68 self.profile, |
74 self.disp(_("forums have been edited"), 1) | 74 self.disp(_("forums have been edited"), 1) |
75 self.host.quit() | 75 self.host.quit() |
76 | 76 |
77 async def start(self): | 77 async def start(self): |
78 try: | 78 try: |
79 forums_json = await self.host.bridge.forumsGet( | 79 forums_json = await self.host.bridge.forums_get( |
80 self.args.service, | 80 self.args.service, |
81 self.args.node, | 81 self.args.node, |
82 self.args.key, | 82 self.args.key, |
83 self.profile, | 83 self.profile, |
84 ) | 84 ) |
87 forums_json = "" | 87 forums_json = "" |
88 else: | 88 else: |
89 self.disp(f"can't get node configuration: {e}", error=True) | 89 self.disp(f"can't get node configuration: {e}", error=True) |
90 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 90 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
91 | 91 |
92 content_file_obj, content_file_path = self.getTmpFile() | 92 content_file_obj, content_file_path = self.get_tmp_file() |
93 forums_json = forums_json.strip() | 93 forums_json = forums_json.strip() |
94 if forums_json: | 94 if forums_json: |
95 # we loads and dumps to have pretty printed json | 95 # we loads and dumps to have pretty printed json |
96 forums = json.loads(forums_json) | 96 forums = json.loads(forums_json) |
97 # cf. https://stackoverflow.com/a/18337754 | 97 # cf. https://stackoverflow.com/a/18337754 |
98 f = codecs.getwriter("utf-8")(content_file_obj) | 98 f = codecs.getwriter("utf-8")(content_file_obj) |
99 json.dump(forums, f, ensure_ascii=False, indent=4) | 99 json.dump(forums, f, ensure_ascii=False, indent=4) |
100 content_file_obj.seek(0) | 100 content_file_obj.seek(0) |
101 await self.runEditor("forums_editor_args", content_file_path, content_file_obj) | 101 await self.run_editor("forums_editor_args", content_file_path, content_file_obj) |
102 | 102 |
103 | 103 |
104 class Get(base.CommandBase): | 104 class Get(base.CommandBase): |
105 def __init__(self, host): | 105 def __init__(self, host): |
106 extra_outputs = {"default": self.default_output} | 106 extra_outputs = {"default": self.default_output} |
152 A.color(level * 4 * " ", head_color, key, A.RESET, ": ", value) | 152 A.color(level * 4 * " ", head_color, key, A.RESET, ": ", value) |
153 ) | 153 ) |
154 | 154 |
155 async def start(self): | 155 async def start(self): |
156 try: | 156 try: |
157 forums_raw = await self.host.bridge.forumsGet( | 157 forums_raw = await self.host.bridge.forums_get( |
158 self.args.service, | 158 self.args.service, |
159 self.args.node, | 159 self.args.node, |
160 self.args.key, | 160 self.args.key, |
161 self.profile, | 161 self.profile, |
162 ) | 162 ) |