PKLdyJBZ@@pygame_fpak/__init__.py"""Flatpak packaging for pygame games. """ __version__ = '0.1' PKwJe6pygame_fpak/__main__.pyfrom .main import main main() PKOwJ^;VVpygame_fpak/inner.py"""This is copied into the project directory and run in the flatpak build environment. It installs the necessary files for the game into the /app prefix. """ import json import os from pathlib import Path from shutil import copy2, copytree, ignore_patterns import sys DESKTOP_TEMPLATE = """\ [Desktop Entry] Type=Application Name={name} Icon={appid} Exec=/app/bin/launch-game Categories=Game """ LAUNCHER_TEMPLATE = """\ #!{python} from {mod} import {func} {func}() """ python_paths = { '3.6': '/app/bin/python3', '3.4': '/usr/bin/python3', '2.7': '/usr/bin/python', } def main(): with open('build/flatpak/config.json') as f: config = json.load(f) print("Making install dir") install_dir = Path('/app/share/mygame') install_dir.mkdir(parents=True) for file in config['files']: if os.path.isdir(file): copytree(file, str(install_dir / file), ignore=ignore_patterns('__pycache__', '*.pyc')) else: copy2(file, str(install_dir)) # Icons print("Installing icons") for size, path in config['icons'].items(): target_path = '/app/share/icons/hicolor/{size}x{size}/apps/{appid}.png'.format( size=size, appid=config['appid']) os.makedirs(os.path.dirname(target_path), exist_ok=True) copy2(path, target_path) # Desktop file print("Writing desktop file") desktop_target = '/app/share/applications/{}.desktop'.format(config['appid']) os.makedirs(os.path.dirname(desktop_target), exist_ok=True) with open(desktop_target, 'w') as f: f.write(DESKTOP_TEMPLATE.format_map(config)) # Launcher print("Creating launch script") module, func = config['entry-point'].split(':') launcher_file = install_dir / 'launch-game.py' with launcher_file.open('w') as f: f.write(LAUNCHER_TEMPLATE.format( python=python_paths[config['python']], mod = module, func=func )) launcher_file.chmod(0o755) Path('/app/bin/launch-game').symlink_to(launcher_file) if __name__ == '__main__': main() PKayJmļXpygame_fpak/main.pyimport json from pathlib import Path import pytoml import shutil from subprocess import run, PIPE import sys def flatpak(*args): run(('flatpak',) + args, check=True) class PkgRef: def __init__(self, name, arch, branch): self.name = name self.arch = arch self.branch = branch def list_installed(): res = run(['flatpak', 'list'], check=True, stdout=PIPE) lines = res.stdout.decode('utf-8', 'replace').splitlines() for line in lines: yield PkgRef(*line.split()[0].split('/')) def get_baseapp(baseapp): installed_names = [p.name for p in list_installed()] if baseapp in installed_names: return flatpak('--user', 'remote-add', '--if-not-exists', '--from', 'pygame-bases', 'https://takluyver.github.io/pygame-flatpak-test/pgbase.flatpakrepo') flatpak('--user', 'install', 'pygame-bases', baseapp) inner_py = Path(__file__).parent / 'inner.py' class Flatpacker: def __init__(self, config_path): self.config_path = config_path with config_path.open() as f: self.config = pytoml.load(f) check_config(self.config) self.project_dir = config_path.parent self.packing_dir = self.project_dir / 'build' / 'flatpak' self.build_dir = self.packing_dir / 'build' self.repo_dir = self.project_dir / 'build' / 'flatpak-repo' def call_build_script(self): """Copy the build script and call it inside the flatpak build. """ print('Running build script...') build_script = self.packing_dir / 'inner_build.py' shutil.copy(str(inner_py), str(build_script)) # pytoml isn't in the build environment, so store the config as JSON with (self.packing_dir / 'config.json').open('w') as f: json.dump(self.config, f, indent=2) run(['flatpak', 'build', str(self.build_dir), '/usr/bin/python3', str(build_script)], cwd=str(self.project_dir), check=True) def build(self): try: shutil.rmtree(str(self.packing_dir)) except FileNotFoundError: pass baseapp = 'org.pygame.BaseApp-py{}{}'.format(*self.config['python'].split('.')) get_baseapp(baseapp) flatpak('build-init', '--base', baseapp, str(self.build_dir), self.config['appid'], 'org.freedesktop.Sdk', 'org.freedesktop.Platform', '1.4') self.call_build_script() flatpak('build-finish', str(self.build_dir), '--socket=x11', '--socket=pulseaudio', '--command=launch-game') flatpak('build-export', str(self.repo_dir), str(self.build_dir)) def info(self): repo_rel = self.repo_dir.relative_to(Path.cwd()) print() print("Built to repo in {}".format(repo_rel)) print("To distribute, see http://docs.flatpak.org/en/latest/distributing-applications.html") print("Make a single file bundle:") print(" flatpak build-bundle {repo} {appid}.bundle {appid}" .format(repo=repo_rel, appid=self.config['appid'])) print("Install and test:") print(" flatpak --user remote-add --no-gpg-verify --if-not-exists {}-origin {}" .format(self.config['appid'], repo_rel)) print(" flatpak --user install {appid}-origin {appid}" .format(appid=self.config['appid'])) class InputError(ValueError): pass def check_config(config): if config['python'] not in {'3.6', '3.4', '2.7'}: raise InputError("Python version should be 3.6, 3.4 or 2.7, not {}" .format(config['python'])) def main(argv=None): if argv is None: argv = sys.argv config_path = Path(argv[1]).resolve() packer = Flatpacker(config_path) packer.build() packer.info() if __name__ == '__main__': main() PK!H;@QPpygame_fpak-0.1.dist-info/WHEEL1 0 RZq+D-Dv;_[*7Fp ܦpv/fݞoL(*IPK!Hik "pygame_fpak-0.1.dist-info/METADATAVo6]!6N[ݺmӢI7 PeqHb{QG y#ߪ( vvJ'b]ZM,l2-?'U[oȈUjd mT:r6rUMF v.rW\vsaT!fotlחX9?2ζ=TfJ1-;2ګ0|:<{:FKഏF)Fz]m{Ȳvg.j/Ff?$)H[Aeˈ U7ڶk?+ԍ2Q ~A Ui[bm82(=~_k}+ {xcFL]+9h]Vеqe'r-1dcuhgOA'm@\6dx %eD筍-" l1fn~>!Ju8@gh}keKڸ'T hu,^`=LٌrgK hh- B K/Q yvE 8 іШ\:G:=bّ؛c@Uܬ*i P c[Yd3l:tO;{wX,3_߼WΔFROGswxQX),0v:gwFob!;Tp{R,57ɳgUp]pLoM :G5L!7Cu8 (])xm6* ODGws{[6O⁄@qDezLi(1pEѤyv?7ix즼(;;BF,,Q/B1ҫALI^+qegW\dNV&>X4Yĩxar/=.*1dZ&C}i΃NL=@`<̿N.V r,sG"臝zas Z5B [ `Q-ټzRyy| ķs㑍`3l6Ǣ@þϺ-\]t+HlQ!k 7 #l\QX?u q7d9yHoCv w?h'Ieݘtr_#" _DKI4Ph+”ї5| < W05WHrmD=?~Ii9twئY$lJsڡf~  "]kcRΈ,w[|$ȏ)$728@fj6JeIx!Ė~[]W$-6vۚ&/f *nsek0c, li;Zmđ+O`!n25MɰAuPK!Hb_P  pygame_fpak-0.1.dist-info/RECORD}ˎ0@ѽ߂Jy,@QPG5# R~f&Nnn8)p:F2Z#4*:_j_SJcm~-r{HkZQ3""(hʠx2LٛC|8o8 t0h+AAZRC=eA4XTPl%IXZn<,0P`OU#H@~O{*nM?=8nӈkĤ=f3 (PPQHy=c߶]y,v;YH1V>pdÀΧDu0fx¥'sF쳂HQZf,+E8JhϚn ~PKLdyJBZ@@pygame_fpak/__init__.pyPKwJe6upygame_fpak/__main__.pyPKOwJ^;VVpygame_fpak/inner.pyPKayJmļXP pygame_fpak/main.pyPK!H;@QPpygame_fpak-0.1.dist-info/WHEELPK!Hik "pygame_fpak-0.1.dist-info/METADATAPK!Hb_P  pygame_fpak-0.1.dist-info/RECORDPK