comparison sat_frontends/jp/cmd_pipe.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 2594e1951cf7
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
43 ) 43 )
44 44
45 async def start(self): 45 async def start(self):
46 """ Create named pipe, and send stdin to it """ 46 """ Create named pipe, and send stdin to it """
47 try: 47 try:
48 port = await self.host.bridge.streamOut( 48 port = await self.host.bridge.stream_out(
49 await self.host.get_full_jid(self.args.jid), 49 await self.host.get_full_jid(self.args.jid),
50 self.profile, 50 self.profile,
51 ) 51 )
52 except Exception as e: 52 except Exception as e:
53 self.disp(f"can't start stream: {e}", error=True) 53 self.disp(f"can't start stream: {e}", error=True)
87 try: 87 try:
88 sys.stdout.flush() 88 sys.stdout.flush()
89 except IOError as e: 89 except IOError as e:
90 sys.stderr.write(f"{e}\n") 90 sys.stderr.write(f"{e}\n")
91 break 91 break
92 host.quitFromSignal() 92 host.quit_from_signal()
93 93
94 94
95 class PipeIn(base.CommandAnswering): 95 class PipeIn(base.CommandAnswering):
96 def __init__(self, host): 96 def __init__(self, host):
97 super(PipeIn, self).__init__(host, "in", help=_("receive a pipe stream")) 97 super(PipeIn, self).__init__(host, "in", help=_("receive a pipe stream"))
98 self.action_callbacks = {"STREAM": self.onStreamAction} 98 self.action_callbacks = {"STREAM": self.on_stream_action}
99 99
100 def add_parser_options(self): 100 def add_parser_options(self):
101 self.parser.add_argument( 101 self.parser.add_argument(
102 "jids", 102 "jids",
103 nargs="*", 103 nargs="*",
104 help=_('Jids accepted (none means "accept everything")'), 104 help=_('Jids accepted (none means "accept everything")'),
105 ) 105 )
106 106
107 def getXmluiId(self, action_data): 107 def get_xmlui_id(self, action_data):
108 try: 108 try:
109 xml_ui = action_data["xmlui"] 109 xml_ui = action_data["xmlui"]
110 except KeyError: 110 except KeyError:
111 self.disp(_("Action has no XMLUI"), 1) 111 self.disp(_("Action has no XMLUI"), 1)
112 else: 112 else:
113 ui = xmlui_manager.create(self.host, xml_ui) 113 ui = xmlui_manager.create(self.host, xml_ui)
114 if not ui.submit_id: 114 if not ui.submit_id:
115 self.disp(_("Invalid XMLUI received"), error=True) 115 self.disp(_("Invalid XMLUI received"), error=True)
116 self.quitFromSignal(C.EXIT_INTERNAL_ERROR) 116 self.quit_from_signal(C.EXIT_INTERNAL_ERROR)
117 return ui.submit_id 117 return ui.submit_id
118 118
119 async def onStreamAction(self, action_data, action_id, security_limit, profile): 119 async def on_stream_action(self, action_data, action_id, security_limit, profile):
120 xmlui_id = self.getXmluiId(action_data) 120 xmlui_id = self.get_xmlui_id(action_data)
121 if xmlui_id is None: 121 if xmlui_id is None:
122 self.host.quitFromSignal(C.EXIT_ERROR) 122 self.host.quit_from_signal(C.EXIT_ERROR)
123 try: 123 try:
124 from_jid = jid.JID(action_data["meta_from_jid"]) 124 from_jid = jid.JID(action_data["meta_from_jid"])
125 except KeyError: 125 except KeyError:
126 self.disp(_("Ignoring action without from_jid data"), error=True) 126 self.disp(_("Ignoring action without from_jid data"), error=True)
127 return 127 return
138 else: 138 else:
139 raise e 139 raise e
140 else: 140 else:
141 break 141 break
142 xmlui_data = {"answer": C.BOOL_TRUE, "port": str(port)} 142 xmlui_data = {"answer": C.BOOL_TRUE, "port": str(port)}
143 await self.host.bridge.launchAction( 143 await self.host.bridge.action_launch(
144 xmlui_id, xmlui_data, profile_key=profile) 144 xmlui_id, xmlui_data, profile_key=profile)
145 async with server: 145 async with server:
146 await server.serve_forever() 146 await server.serve_forever()
147 self.host.quitFromSignal() 147 self.host.quit_from_signal()
148 148
149 async def start(self): 149 async def start(self):
150 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] 150 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
151 await self.start_answering() 151 await self.start_answering()
152 152