Coverage for modules/org/openteacher/logic/pyinstallerInterface/pyinstallerInterface : 38%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2012-2013, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
"""This module freezes the current installation of OpenTeacher with PyInstaller into an executable. For more on PyInstaller, see:
http://www.pyinstaller.org/
"""
self._mm.mods(type="sourceSaver"), self._mm.mods(type="metadata") )
def _saveSource(self): return self._modules.default("active", type="sourceSaver").saveSource
path = tempfile.mkdtemp() self._tempPaths.add(path) for iconName in ["icon.ico", "icon.icns"]: shutil.copy( self._mm.resourcePath(iconName), os.path.join(path, iconName) ) with open(os.path.join(path, "starter.py"), "w") as f: f.write(""" import sys import os
if not sys.frozen: #import OT dependencies, so PyInstaller adds them to the build. #not required at runtime though, so that's why the if statement #above is here. from xml.etree import ElementTree from PyQt5 import QtCore, QtGui, QtWebEngine, QtWebEngineWidgets, QtNetwork, QtMultimedia, QtMultimediaWidgets, QtQml, QtOpenGL import argparse import atexit import bisect import chardet import code import collections import contextlib import csv import docutils import enchant import html.parser import Image import itertools import json import latexcodec import logging import mimetypes import platform import runpy import shutil import sqlite3 import subprocess import traceback import urllib import urllib.request import urllib.error import urwid import uuid import weakref import webbrowser import xml.dom.minidom import zipfile #windows only, so wrapped. try: import win32com except ImportError: pass
#filter the -psn argument passed by mac os x out. sys.argv = [a for a in sys.argv if not a.startswith("-psn")]
sys.path.insert(0, os.path.join(os.path.dirname(sys.executable), 'source')) sys.exit(__import__('openteacher').ModuleApplication().run()) """)
if platform.system() == "Darwin": icon = "icon.icns" else: icon = "icon.ico"
#save so they can be restored later cwd = os.getcwd() os.chdir(path) #run pyinstaller subprocess.check_call([ "pyinstaller", "--windowed", "--name", self._metadata["name"].lower(), "--icon", icon, "starter.py", ]) #restore environment os.chdir(cwd)
if platform.system() == "Darwin": resultPath = os.path.join(path, "dist", self._metadata["name"] + ".app") else: resultPath = os.path.join(path, "dist", self._metadata["name"].lower())
#save source sourcePath = self._saveSource()
#copy the source in if platform.system() == "Darwin": shutil.copytree(sourcePath, os.path.join(resultPath, "Contents/MacOS/source")) else: shutil.copytree(sourcePath, os.path.join(resultPath, "source"))
# self._copyInTesseractPortableExecutables(resultPath)# FIXME
return resultPath
if platform.system() != "Windows": return #copy in the portable tesseract executables. tesseractDir = os.path.join(os.getcwd(), "tesseract-portable") for fileOrDir in os.listdir(tesseractDir): source = os.path.join(tesseractDir, fileOrDir) result = os.path.join(resultPath, fileOrDir) copy = shutil.copy if os.path.isfile(source) else shutil.copytree copy(source, result)
for path in self._tempPaths: shutil.rmtree(path)
|