def _make_spec(self, spec_args, temp_name, app_info, spec_only=False): log.debug('App Info: %s', app_info) # Ensure that onefile mode is passed spec_args.append('-F') spec_args.append('--name={}'.format(temp_name)) if spec_only is True: log.debug('*** User generated spec file ***') log.debug('There could be errors') spec_args.append('--specpath={}'.format(os.getcwd())) else: # Place spec file in .pyupdater/spec spec_args.append('--specpath={}'.format(self.spec_dir)) # Use hooks included in PyUpdater package hook_dir = get_hook_dir() log.debug('Hook directory: %s', hook_dir) spec_args.append('--additional-hooks-dir={}'.format(hook_dir)) spec_args.append(app_info['name']) log.debug('Make spec cmd: %s', ' '.join([c for c in spec_args])) success = pyi_makespec(spec_args) if success is False: log.error('PyInstaller > 3.0 needed for this python installation.') sys.exit(1)
def _make_spec(self, temp_name, spec_only=False): log.debug("App Info: %s", self.app_info) self.pyi_args.append("--name={}".format(temp_name)) if spec_only is True: log.debug("*** User generated spec file ***") log.debug("There could be errors") self.pyi_args.append("--specpath={}".format(os.getcwd())) else: # Place spec file in .pyupdater/spec self.pyi_args.append("--specpath={}".format(self.spec_dir)) # Use hooks included in PyUpdater package hook_dir = get_hook_dir() log.debug("Hook directory: %s", hook_dir) self.pyi_args.append("--additional-hooks-dir={}".format(hook_dir)) if self.args.pyi_log_info is False: self.pyi_args.append("--log-level=ERROR") self.pyi_args.append(self.app_info["name"]) log.debug("Make spec cmd: %s", " ".join([c for c in self.pyi_args])) success = pyi_makespec(self.pyi_args) if success is False: log.error("PyInstaller > 3.0 needed for this python installation.") sys.exit(1)
def _make_spec(self, spec_args, temp_name, app_info, spec_only=False): log.debug('App Info: %s', app_info) # Ensure that onefile mode is passed spec_args.append('-F') spec_args.append('--name={}'.format(temp_name)) if spec_only is True: log.debug('*** User generated spec file ***') log.debug('There could be errors') spec_args.append('--specpath={}'.format(os.getcwd())) else: # Place spec file in .pyupdater/spec spec_args.append('--specpath={}'.format(self.spec_dir)) # Use hooks included in PyUpdater package hook_dir = get_hook_dir() log.debug('Hook directory: %s', hook_dir) spec_args.append('--additional-hooks-dir={}'.format(hook_dir)) spec_args.append(app_info['name']) log.debug('Make spec cmd: %s', ' '.join([c for c in spec_args])) success = pyi_makespec(spec_args) if success is False: log.error('PyInstaller > 3.0 needed for this python installation.') sys.exit(1)
def _make_spec(self, args, spec_args, temp_name, app_info, spec_only=False): log.debug('App Info: {}'.format(app_info)) if args.console is True: if '-c' not in spec_args: log.debug('Adding -c to pyi args') spec_args.append('-c') if args.windowed is True: if '-w' not in spec_args: log.debug('Adding -w to pyi args') spec_args.append('-w') # Ensure that onefile mode is passed spec_args.append('-F') spec_args.append('--name={}'.format(temp_name)) if spec_only is True: log.debug('User generated spec file') spec_args.append('--specpath={}'.format(os.getcwd())) else: # Place spec file in .pyupdater/spec spec_args.append('--specpath={}'.format(self.spec_dir)) # Use hooks included in PyUpdater package hook_dir = get_hook_dir() log.debug('Hook directory: {}'.format(hook_dir)) spec_args.append('--additional-hooks-dir={}'.format(hook_dir)) spec_args.append(app_info['name']) log.debug('Make spec cmd: {}'.format(' '.join([c for c in spec_args]))) pyi_makespec(spec_args)
def _make_spec(self, args, spec_args, temp_name, app_info, spec_only=False): log.debug('App Info: {}'.format(app_info)) if args.console is True: if '-c' not in spec_args: log.debug('Adding -c to pyi args') spec_args.append('-c') if args.windowed is True: if '-w' not in spec_args: log.debug('Adding -w to pyi args') spec_args.append('-w') # Ensure that onefile mode is passed spec_args.append('-F') spec_args.append('--name={}'.format(temp_name)) if spec_only is True: log.debug('User generated spec file') spec_args.append('--specpath={}'.format(os.getcwd())) else: # Place spec file in .pyupdater/spec spec_args.append('--specpath={}'.format(self.spec_dir)) # Use hooks included in PyUpdater package hook_dir = get_hook_dir() log.debug('Hook directory: {}'.format(hook_dir)) spec_args.append('--additional-hooks-dir={}'.format(hook_dir)) spec_args.append(app_info['name']) log.debug('Make spec cmd: {}'.format(' '.join([c for c in spec_args]))) pyi_makespec(spec_args)
def run(self): """ Custom "python setup.py build" command On Windows, create dist/MyData/*.*, including dist/MyData/MyData.exe On macOS, create dist/MyData.app/* """ if sys.platform.startswith("win"): sys.stdout.write( "Creating dist/MyData.exe using PyUpdater / PyInstaller...\n") if os.path.exists("build"): shutil.rmtree("build") os.mkdir("build") if not os.path.exists("build/pyu-data"): os.makedirs("build/pyu-data") if os.path.exists("dist"): shutil.rmtree("dist") os.mkdir("dist") if not os.path.exists("dist/MyData"): os.makedirs("dist/MyData") if not os.path.exists("dist/MyData-console"): os.makedirs("dist/MyData-console") pyu_settings.CONFIG_DATA_FOLDER = \ os.path.abspath("build/.pyupdater") if not os.path.exists(pyu_settings.CONFIG_DATA_FOLDER): os.makedirs(pyu_settings.CONFIG_DATA_FOLDER) pyu_settings.USER_DATA_FOLDER = os.path.abspath("build/pyu-data") # The way we set the App name below avoids having to # create .pyupdater/config.pyu: pyu_settings.GENERIC_APP_NAME = APP_NAME pyu_settings.GENERIC_COMPANY_NAME = COMPANY_NAME pyinstallerArgs = [ '--windowed', 'run.py', '--icon', 'mydata/media/MyData.ico' ] args = Namespace(app_version=APP_VERSION, clean=False, command='build', distpath=None, keep=False, name=None, onedir=False, onefile=False, specpath=None, workpath=None) builder = Builder(args, pyinstallerArgs) builder.build() pyuNewDir = os.path.join(pyu_settings.USER_DATA_FOLDER, 'new') buildFileName = '%s-win-%s.zip' % (APP_NAME, APP_VERSION) buildFilePath = os.path.join(pyuNewDir, buildFileName) with zipfile.ZipFile(buildFilePath, 'r') as zipFile: zipFile.extractall("dist/MyData") pyu_settings.GENERIC_APP_NAME = "%s-console" % APP_NAME pyinstallerArgs = ['--console', 'run.py'] builder = Builder(args, pyinstallerArgs) builder.build() pyuNewDir = os.path.join(pyu_settings.USER_DATA_FOLDER, 'new') buildFileName = '%s-console-win-%s.zip' % (APP_NAME, APP_VERSION) buildFilePath = os.path.join(pyuNewDir, buildFileName) with zipfile.ZipFile(buildFilePath, 'r') as zipFile: zipFile.extractall("dist/MyData-console") os.system(r"COPY /Y dist\MyData-console\MyData-console.exe " r"dist\MyData\MyData.com") # favicon.ico and MyData.ico are really the same thing. favicon.ico # is the original from the MyTardis repository, and MyData.ico is # the result of converting it to PNG and then back to ICO, which # fixed a problem with the Windows build. if not os.path.exists("dist/MyData/media"): os.makedirs("dist/MyData/media") os.system(r"COPY /Y mydata\media\favicon.ico " r"dist\MyData\media") os.system(r"COPY /Y mydata\media\MyData.ico " r"dist\MyData\media") distutils.dir_util.copy_tree("mydata/media/Aha-Soft", "dist/MyData/media/Aha-Soft") distutils.dir_util\ .copy_tree("resources/win64/openssh-7.3p1-cygwin-2.6.0", "dist/MyData/win64/openssh-7.3p1-cygwin-2.6.0") cygwin64HomeDir = \ "dist/MyData/win64/openssh-7.3p1-cygwin-2.6.0/home" for subdir in os.listdir(cygwin64HomeDir): subdirpath = os.path.join(cygwin64HomeDir, subdir) if os.path.isdir(subdirpath): shutil.rmtree(subdirpath) distutils.dir_util.copy_tree( "resources/win32/openssh-7.3p1-cygwin-2.8.0", "dist/MyData/win32/openssh-7.3p1-cygwin-2.8.0") cygwin32HomeDir = \ "dist/MyData/win32/openssh-7.3p1-cygwin-2.8.0/home" for subdir in os.listdir(cygwin32HomeDir): subdirpath = os.path.join(cygwin32HomeDir, subdir) if os.path.isdir(subdirpath): shutil.rmtree(subdirpath) os.system(r"COPY /Y GPL.txt dist\MyData") cacert = requests.certs.where() os.system(r"COPY /Y %s dist\MyData" % cacert) elif sys.platform.startswith("darwin"): sys.stdout.write( "Creating dist/MyData.app using PyUpdater / PyInstaller...\n") os.system("rm -fr build/*") os.system("rm -fr dist/*") if not os.path.exists("build/pyu-data"): os.makedirs("build/pyu-data") pyu_settings.CONFIG_DATA_FOLDER = \ os.path.abspath("build/.pyupdater") if not os.path.exists(pyu_settings.CONFIG_DATA_FOLDER): os.makedirs(pyu_settings.CONFIG_DATA_FOLDER) pyu_settings.USER_DATA_FOLDER = os.path.abspath("build/pyu-data") # The way we set the App name below avoids having to # create .pyupdater/config.pyu: pyu_settings.GENERIC_APP_NAME = APP_NAME pyu_settings.GENERIC_COMPANY_NAME = COMPANY_NAME with open("setup_templates/macOS/mac.spec.template", 'r') as macSpecTemplateFile: macSpecTemplate = macSpecTemplateFile.read() macSpec = macSpecTemplate \ .replace("<MYDATA_REPO_PATH>", os.path.abspath(".")) \ .replace("<MYDATA_RUNNER>", os.path.abspath("run.py")) \ .replace("<APP_VERSION>", APP_VERSION) \ .replace("<PYUPDATER_HOOKS_PATH>", os.path.dirname(get_hook_dir())) with open("MyData.spec", 'w') as macSpecFile: macSpecFile.write(macSpec) pyinstallerArgs = ['--windowed', 'MyData.spec'] args = Namespace(app_version=APP_VERSION, clean=False, command='build', distpath=None, keep=False, name=None, onedir=False, onefile=False, specpath=None, workpath=None) builder = Builder(args, pyinstallerArgs) builder.build() pyuNewDir = os.path.join(pyu_settings.USER_DATA_FOLDER, 'new') buildFileName = '%s-mac-%s.tar.gz' % (APP_NAME, APP_VERSION) buildFilePath = os.path.join(pyuNewDir, buildFileName) tar = tarfile.open(buildFilePath, "r:gz") tar.extractall("dist") tar.close() resourceFiles = [(requests.certs.where(), ""), ("mydata/media/MyData.icns", ""), ("mydata/media/favicon.ico", "media"), ("mydata/media/Aha-Soft/LICENSE.txt", "media/Aha-Soft")] for iconFilesPath in ("media/Aha-Soft/png-normal/icons16x16", "media/Aha-Soft/png-normal/icons24x24", "media/Aha-Soft/png-disabled/icons16x16", "media/Aha-Soft/png-disabled/icons24x24", "media/Aha-Soft/png-hot/icons24x24"): for iconFile in os.listdir( os.path.join(PACKAGE_NAME, iconFilesPath)): iconFilePath = \ os.path.join(PACKAGE_NAME, iconFilesPath, iconFile) if os.path.isfile(iconFilePath): resourceFile = (iconFilePath, iconFilesPath) resourceFiles.append(resourceFile) for resourceFile in resourceFiles: targetDir = os.path.join("dist", "%s.app" % APP_NAME, "Contents", "Resources", resourceFile[1]) if not os.path.exists(targetDir): os.makedirs(targetDir) shutil.copy(resourceFile[0], targetDir) shutil.copytree( "resources/macOS/MyData Notifications.app", "dist/MyData.app/Contents/MacOS/MyData Notifications.app") shutil.copy("resources/macOS/ObjectiveC/bin/add-loginitem", "dist/MyData.app/Contents/MacOS/") shutil.copy("resources/macOS/ObjectiveC/bin/delete-loginitem", "dist/MyData.app/Contents/MacOS/") shutil.copy("resources/macOS/ObjectiveC/bin/loginitem-exists", "dist/MyData.app/Contents/MacOS/") from setup_helpers.mac_signing import MAC_SIGNING MAC_SIGNING.SignApp("dist/MyData.app") MAC_SIGNING.VerifySignature("dist/MyData.app") elif sys.platform.startswith("linux"): os.system("cd linux; ./package_linux_version.sh")