Skip to content

Commit

Permalink
prepare for building with pyinstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokariew committed Jun 3, 2020
1 parent a29f91c commit 2639c6c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
config.yaml
*yapf
build/
dist/
*.pyc
12 changes: 11 additions & 1 deletion hb_downloader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import argparse
import hashlib
import http.cookiejar
import os
import re
import sys
import time
from concurrent.futures import ThreadPoolExecutor
from math import floor, log2
Expand All @@ -17,6 +19,14 @@
import yaml


def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)

return os.path.join(os.path.abspath("."), relative_path)


def round10(x):
return floor(x / 10) * 10

Expand Down Expand Up @@ -61,7 +71,7 @@ def read_yaml():
cfg = yaml.safe_load(yamfile)
return cfg
except FileNotFoundError:
Path('config.yaml').write_text(Path('example_config.yaml').read_text())
Path('config.yaml').write_text(Path(resource_path('example_config.yaml')).read_text())


def parse_config(parser):
Expand Down
33 changes: 33 additions & 0 deletions hb_downloader.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['hb_downloader.py'],
pathex=[''],
binaries=[],
datas=[('example_config.yaml', '.')],
hiddenimports=[],
hookspath=[],
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='hb_downloader',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )

0 comments on commit 2639c6c

Please sign in to comment.