From bf9e56715fd3b76bdec4e55704b8e3f301ab40bc Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 22 Oct 2023 16:15:20 +0800 Subject: [PATCH 1/2] perf: make make_printable more efficient This cuts the initial MTDA startup time in half by avoiding the creation of a huge replacement table for string ASCII encoding. Instead, we use the encode infrastructure directly (which is also more efficient on the replacement itself). Note, that this is technically not a 1:1 replacement, as non-printable characters are replaced by a '?' instead of a '.'. However, as this is anyways only used in the debug output, we believe it is a reasonable tradeoff. Signed-off-by: Felix Moessbauer --- mtda/main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mtda/main.py b/mtda/main.py index b99b5952..cb57dbf1 100644 --- a/mtda/main.py +++ b/mtda/main.py @@ -47,16 +47,12 @@ www_support = False -_NOPRINT_TRANS_TABLE = { - i: '.' for i in range(0, sys.maxunicode + 1) if not chr(i).isprintable() -} - DEFAULT_PREFIX_KEY = 'ctrl-a' DEFAULT_PASTEBIN_EP = "http://pastebin.com/api/api_post.php" def _make_printable(s): - return s.translate(_NOPRINT_TRANS_TABLE) + return s.encode('ascii', 'replace').decode() class MultiTenantDeviceAccess: From 847c15802afb9f3b3f76d296ecbb01c6712edfb5 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 22 Oct 2023 17:34:27 +0800 Subject: [PATCH 2/2] do not install __pycache__ The pycache is not portable and also leaks information about the build host. Signed-off-by: Felix Moessbauer --- debian/rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/rules b/debian/rules index a0d799a3..cbae1c1a 100755 --- a/debian/rules +++ b/debian/rules @@ -18,6 +18,8 @@ override_dh_auto_install: rm -rf debian/mtda-kvm rm -rf debian/mtda-pytest rm -rf debian/mtda-ui + # lintian package-installs-python-pycache-dir + find debian -name "__pycache__" -type f -delete : install -m 0755 -d debian/mtda mv debian/tmp/usr debian/mtda/