Skip to content

Commit 8c3deb6

Browse files
committed
factor PyInstaller test to toolbox; exception catch-all
1 parent e27977e commit 8c3deb6

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

sql shell.exe

-3.68 MB
Binary file not shown.

sql shell.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#! /usr/bin/env python
22

33
import configparser, curses, os, pathlib, subprocess, sys
4-
import click, pycompat, sshtunnel
5-
import tunnel
4+
import click, pycompat
5+
import toolbox as tb, tunnel
66
# https://npyscreen.readthedocs.io/
77
from npyscreen import * # NOSONAR
88

@@ -54,8 +54,8 @@
5454
config = configparser.ConfigParser(delimiters='=')
5555

5656
def read_config():
57-
if getattr(sys, 'frozen', False): # PyInstaller
58-
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
57+
if tb.is_pyinstaller():
58+
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#using-sys-executable-and-sys-argv-0
5959
script_dir = sys.executable
6060
else:
6161
script_dir = __file__
@@ -297,8 +297,7 @@ def on_ok(self): # NOSONAR
297297
except KeyboardInterrupt:
298298
pass
299299

300-
except (FileNotFoundError, ValueError, sshtunnel.BaseSSHTunnelForwarderError,
301-
Exception) as exception:
300+
except Exception as exception:
302301
print(exception)
303302

304303
print()

toolbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
3+
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
4+
def is_pyinstaller():
5+
return getattr(sys, 'frozen', False)

tunnel.py

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

33
import configparser, getpass, logging, pathlib, sys
44
import sshtunnel
5+
import toolbox as tb
56

67
ini_file = 'tunnel.ini'
78
defaults = {
@@ -27,7 +28,7 @@ def __exit__(self, *args): # for `with tunnel:`
2728
pass
2829

2930
def tunnel(remote_host, remote_port, local_port=0): # `0` means random port
30-
if getattr(sys, 'frozen', False): # PyInstaller
31+
if tb.is_pyinstaller():
3132
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
3233
script_dir = sys.executable
3334
else:

0 commit comments

Comments
 (0)