Skip to content

Commit cf42081

Browse files
committed
feat: support for Pyro5
Prepare support for Debian trixie by modifying our code to work with either Pyro4 or Pyro5. Signed-off-by: Cedric Hombourger <[email protected]>
1 parent af9d12d commit cf42081

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Package: mtda-common
7272
Architecture: all
7373
Multi-Arch: foreign
7474
Depends: python3:any (>= 3.7~),
75-
python3-pyro4
75+
python3-pyro5 | python3-pyro4
7676
Description: common modules for Multi-Tenant Device Access
7777
Modules shared between the service and the client.
7878

mtda-service

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import lockfile
1616
import netifaces
1717
import os
1818
import os.path
19-
import Pyro4
2019
import signal
2120
import sys
2221
import socket
@@ -27,6 +26,12 @@ from systemd import daemon as sd
2726
from mtda.main import MultiTenantDeviceAccess
2827
import mtda.constants as CONSTS
2928

29+
# Pyro
30+
try:
31+
from Pyro5.compatibility import Pyro4
32+
except ImportError:
33+
import Pyro4
34+
3035

3136
class Application:
3237

mtda-www

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import os
2222
import uuid
2323
import zmq.asyncio
2424
import concurrent.futures
25-
import Pyro4.errors
2625
import logging
2726
import abc
2827
import functools
@@ -33,6 +32,12 @@ import mtda.constants as CONSTS
3332
from mtda.console.remote import RemoteConsole
3433
from mtda.console.screen import ScreenOutput
3534

35+
# Pyro
36+
try:
37+
import Pyro5.errors as PyroErrors
38+
except ImportError:
39+
import Pyro4.errors as PyroErrors
40+
3641
# ---------------------------------------------------------------------------
3742
# Configure basic logging for better visibility of errors
3843
# ---------------------------------------------------------------------------
@@ -102,10 +107,10 @@ class RemoteCallHandler(BaseHandler, metaclass=abc.ABCMeta):
102107
f"status={status} response={response}")
103108

104109
self.set_status(status)
110+
# For 204 No Content, we just set status and finish, no body needed
105111
if response is not None:
106112
self.result_as_json(response)
107-
# For 204 No Content, we just set status and finish, no body needed
108-
except Pyro4.errors.TimeoutError:
113+
except PyroErrors.TimeoutError:
109114
logger.warning("Remote service timed out for "
110115
f"{self.__class__.__name__}")
111116
self.set_status(504) # Gateway Timeout
@@ -187,7 +192,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
187192
{"video-info": {"format": fmt, "url": video_url}}
188193
)
189194

190-
except Pyro4.errors.TimeoutError:
195+
except PyroErrors.TimeoutError:
191196
logger.warning("timeout during WebSocket for session "
192197
f"{self.session_id}.")
193198
self.write_message({"error": "timeout during WebSocket "
@@ -237,7 +242,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
237242
mtda.console_send, input_data,
238243
raw=False, session=sid
239244
)
240-
except Pyro4.errors.TimeoutError:
245+
except PyroErrors.TimeoutError:
241246
logger.warning("timeout for console_send "
242247
f"for session {sid}.")
243248
self.write_message(
@@ -1138,7 +1143,7 @@ class OpenAPIHandler(tornado.web.RequestHandler):
11381143
}
11391144
}
11401145
self.write(spec)
1141-
except Pyro4.errors.TimeoutError:
1146+
except PyroErrors.TimeoutError:
11421147
logger.warning("Pyro4 timeout fetching agent version for OpenAPI.")
11431148
self.set_status(504)
11441149
self.write({"error": "timeout while fetching API version"})

mtda/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
import os
14-
import Pyro4
1514
import random
1615
import socket
1716
import subprocess
@@ -24,6 +23,12 @@
2423
from mtda.utils import Compression
2524
import mtda.constants as CONSTS
2625

26+
# Pyro
27+
try:
28+
from Pyro5.compatibility import Pyro4
29+
except ImportError:
30+
import Pyro4
31+
2732

2833
class Client:
2934

mtda/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import glob
1515
import importlib
1616
import os
17-
import Pyro4
1817
import socket
1918
import subprocess
2019
import sys
@@ -26,6 +25,12 @@
2625
import mtda.constants as CONSTS
2726
from mtda import __version__
2827

28+
# Pyro
29+
try:
30+
from Pyro5.compatibility import Pyro4
31+
except ImportError:
32+
import Pyro4
33+
2934

3035
DEFAULT_PREFIX_KEY = 'ctrl-a'
3136
DEFAULT_PASTEBIN_EP = "http://pastebin.com/api/api_post.php"

0 commit comments

Comments
 (0)