First stab at packaging with pyinstaller

This commit is contained in:
Adam Goldsmith 2017-04-27 19:53:23 -04:00
parent f4273338d8
commit 06a6cad980
3 changed files with 78 additions and 16 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
/*.png
/*.json
/__pycache__/
/build/
/dist/

55
SotMDeckBuilder.py Normal file → Executable file
View File

@ -10,17 +10,23 @@ from PIL import Image, ImageDraw, ImageFont
import textwrap
import math
import os
import sys
IMG_HERO_CHAR_FRONT = Image.open("images/HeroCharFront.png")
IMG_HERO_CHAR_BACK = Image.open("images/HeroCharBack.png")
IMG_HERO_DECK = Image.open("images/HeroCard.png")
IMG_TARGET_HP = Image.open("images/targetHP.png")
if getattr(sys, 'frozen', False): # we are running in a bundle
bundle_dir = sys._MEIPASS
else: # we are running in a normal Python environment
bundle_dir = os.path.dirname(os.path.abspath(__file__))
FONT_KEYWORD = ImageFont.truetype("fonts/RedStateBlueStateBB_reg.otf", size=40)
FONT_TITLE = ImageFont.truetype("fonts/CrashLandingBB.otf", size=60)
FONT_DESCRIPTION = ImageFont.truetype("fonts/RedStateBlueStateBB_reg.otf", size=30)
FONT_TARGET_HP = ImageFont.truetype("fonts/CrashLandingBB.otf", size=120)
FONT_CHAR_HP = ImageFont.truetype("fonts/ap.ttf", size=120)
IMG_HERO_CHAR_FRONT = Image.open(bundle_dir + "/images/HeroCharFront.png")
IMG_HERO_CHAR_BACK = Image.open(bundle_dir + "/images/HeroCharBack.png")
IMG_HERO_DECK = Image.open(bundle_dir + "/images/HeroCard.png")
IMG_TARGET_HP = Image.open(bundle_dir + "/images/targetHP.png")
FONT_KEYWORD = ImageFont.truetype(bundle_dir + "/fonts/RedStateBlueStateBB_reg.otf", size=40)
FONT_TITLE = ImageFont.truetype(bundle_dir + "/fonts/CrashLandingBB.otf", size=60)
FONT_DESCRIPTION = ImageFont.truetype(bundle_dir + "/fonts/RedStateBlueStateBB_reg.otf", size=30)
FONT_TARGET_HP = ImageFont.truetype(bundle_dir + "/fonts/CrashLandingBB.otf", size=120)
FONT_CHAR_HP = ImageFont.truetype(bundle_dir + "/fonts/ap.ttf", size=120)
def drawTextIf(draw, position, font, card, key, wrap=False):
if key in card:
@ -84,9 +90,9 @@ def makeFaces(deckJson, outfile):
return (baseX, baseX)
def makeJson(deckJson, imgWidth, imgHeight, outfile):
with open("templates/deck.json") as f:
with open(bundle_dir + "/templates/deck.json") as f:
outJson = json.load(f)
with open("templates/card.json") as f:
with open(bundle_dir + "/templates/card.json") as f:
cardTemplate = json.load(f)
# number of cards in x and y direction
@ -130,10 +136,27 @@ def makeJson(deckJson, imgWidth, imgHeight, outfile):
with open(outfile + ".json", "w") as f:
json.dump(outJson, f)
with open("hero_3.json") as f:
deckJson = json.load(f)
if __name__ == '__main__':
if len(sys.argv) < 3:
print("not enough arguments!")
inputJson = input("Input file: ")
outfile = input("Output file (no suffix): ")
else:
inputJson = sys.argv[1]
outfile = sys.argv[2]
outfile = "out"
with open(inputJson) as f:
deckJson = json.load(f)
imgWidth, imgHeight = makeFaces(deckJson, outfile)
makeJson(deckJson, imgWidth, imgHeight, outfile)
imgWidth, imgHeight = makeFaces(deckJson, outfile)
makeJson(deckJson, imgWidth, imgHeight, outfile)
else:
with open("hero_3.json") as f:
deckJson = json.load(f)
outfile = "out"
imgWidth, imgHeight = makeFaces(deckJson, outfile)
makeJson(deckJson, imgWidth, imgHeight, outfile)

36
SotMDeckBuilder.spec Normal file
View File

@ -0,0 +1,36 @@
# -*- mode: python -*-
block_cipher = None
a = Analysis(['SotMDeckBuilder.py'],
pathex=['Z:\\home\\adam\\scratch\\TTS_SotM_Deck'],
binaries=[],
datas=[('images/*.png', 'images'),
('fonts/*.ttf', 'fonts'),
('fonts/*.otf', 'fonts'),
('templates/*.json', 'templates')],
hiddenimports=['pillow'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='SotMDeckBuilder',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='SotMDeckBuilder')