Skip to content

Commit

Permalink
Add a hwi.spec file for pyinstaller to build standalone binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Mar 8, 2019
1 parent d6b24b8 commit 9e04d1a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
4 changes: 4 additions & 0 deletions contrib/pyinstaller-hooks/hook-hwilib.devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from hwilib.devices import __all__
hiddenimports = []
for d in __all__:
hiddenimports.append('hwilib.devices.' + d)
42 changes: 42 additions & 0 deletions hwi.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- mode: python -*-
import platform
import subprocess

block_cipher = None

binaries = []
if platform.system() == 'Windows':
binaries = [("c:/python3/libusb-1.0.dll", ".")]
elif platform.system() == 'Linux':
binaries = [("/lib/x86_64-linux-gnu/libusb-1.0.so.0", ".")]
elif platform.system() == 'Darwin':
find_brew_libusb_proc = subprocess.Popen(['brew', '--prefix', 'libusb'], stdout=subprocess.PIPE)
libusb_path = find_brew_libusb_proc.communicate()[0]
binaries = [(libusb_path.rstrip().decode() + "/lib/libusb-1.0.dylib", ".")]

a = Analysis(['hwi.py'],
binaries=binaries,
datas=[],
hiddenimports=[],
hookspath=['contrib/pyinstaller-hooks/'],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='hwi',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
9 changes: 2 additions & 7 deletions hwilib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

# Hardware wallet interaction script

import glob
import importlib

from .serializations import PSBT, Base64ToHex, HexToBase64, hash160
from .base58 import get_xpub_fingerprint_as_id, get_xpub_fingerprint_hex, xpub_to_pub_hex
from os.path import dirname, basename, isfile
from .errors import NoPasswordError, UnavailableActionError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, UnknownDeviceError, BAD_ARGUMENT, NOT_IMPLEMENTED
from .descriptor import Descriptor
from .devices import __all__ as all_devs

# Get the client for the device
def get_client(device_type, device_path, password=''):
Expand All @@ -32,11 +31,7 @@ def get_client(device_type, device_path, password=''):
def enumerate(password=''):
result = []

# Gets the module names of all the files in devices/
files = glob.glob(dirname(__file__)+"/devices/*.py")
modules = [ basename(f)[:-3] for f in files if isfile(f) and not f.endswith('__init__.py')]

for module in modules:
for module in all_devs:
try:
imported_dev = importlib.import_module('.devices.' + module, __package__)
result.extend(imported_dev.enumerate(password))
Expand Down
7 changes: 7 additions & 0 deletions hwilib/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__all__ = [
'trezor',
'ledger',
'keepkey',
'digitalbitbox',
'coldcard'
]

0 comments on commit 9e04d1a

Please sign in to comment.