diff --git a/.gitignore b/.gitignore index 17f5d1e..0d23776 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ config.yaml *yapf +build/ +dist/ +*.pyc diff --git a/hb_downloader.py b/hb_downloader.py index dca77ae..8e016eb 100644 --- a/hb_downloader.py +++ b/hb_downloader.py @@ -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 @@ -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 @@ -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): diff --git a/hb_downloader.spec b/hb_downloader.spec new file mode 100644 index 0000000..8b3c6b2 --- /dev/null +++ b/hb_downloader.spec @@ -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 )