def test_prepare_shortcuts(self): shortcuts = { 'sc1': { 'entry_point': 'norwegian.blue:parrot', 'icon': DEFAULT_ICON, 'console': False, 'extra_preamble': sample_preamble, } } ib = InstallerBuilder("Test App", "1.0", shortcuts, build_dir=self.target) ib.prepare_shortcuts() scfile = pjoin(self.target, 'sc1.launch.pyw') assert_is_file(scfile) with io.open(scfile, 'r', encoding='utf-8') as f: contents = f.read() last2lines = [l.strip() for l in contents.rstrip().splitlines()[-2:]] assert last2lines == ['from norwegian.blue import parrot', 'parrot()'] with io.open(sample_preamble, 'r', encoding='utf-8') as f: preamble_contents = f.read().strip() assert preamble_contents in contents
def build_msi(bitness=32): egg_path = Path('spreads.egg-info') if egg_path.exists(): shutil.rmtree(unicode(egg_path)) build_path = Path('build') if not build_path.exists(): build_path.mkdir() pkg_dir = build_path / 'pynsist_pkgs' if pkg_dir.exists(): shutil.rmtree(unicode(pkg_dir)) pkg_dir.mkdir() for pkg in BINARY_PACKAGES.itervalues(): arch = 'win32' if bitness == 32 else 'win-amd64' extract_native_pkg(pkg.format(arch=arch), pkg_dir) for pkg in (x.project_name for x in SOURCE_PACKAGES if x.project_name is not None): copy_info(pkg, pkg_dir) icon = os.path.abspath("spreads.ico") extra_files = [(unicode( (Path('win_deps') / 'extra' / x.format(arch='.amd64' if bitness == 64 else '')).absolute()), None) for x in EXTRA_FILES] nsi_template = os.path.abspath("template.nsi") # NOTE: We need to remove the working directory from sys.path to force # pynsist to copy all of our modules, including 'spreads' and 'spreadsplug' # from the site-packages. Additionally, we need to change into the # build directory. if os.getcwd() in sys.path: sys.path.remove(os.getcwd()) os.chdir(unicode(build_path)) builder = InstallerBuilder( appname="spreads", version=spreads.__version__, packages=[x.module_name for x in SOURCE_PACKAGES], extra_files=extra_files, py_version="2.7.6", py_bitness=bitness, build_dir='msi{0}'.format(bitness), installer_name=None, nsi_template=nsi_template, icon=icon, shortcuts={ 'Configure spreads': { 'entry_point': 'spreads.main:run_config_windows', 'icon': icon, 'console': False }, 'Spreads Web Service': { 'entry_point': 'spreads.main:run_service_windows', 'icon': icon, 'console': False } }) builder.run() os.chdir('..')
def build_msi(bitness=32): egg_path = Path('spreads.egg-info') if egg_path.exists(): shutil.rmtree(unicode(egg_path)) build_path = Path('build') if not build_path.exists(): build_path.mkdir() pkg_dir = build_path/'pynsist_pkgs' if pkg_dir.exists(): shutil.rmtree(unicode(pkg_dir)) pkg_dir.mkdir() for pkg in BINARY_PACKAGES.itervalues(): arch = 'win32' if bitness == 32 else 'win-amd64' extract_native_pkg(pkg.format(arch=arch), pkg_dir) for pkg in (x.project_name for x in SOURCE_PACKAGES if x.project_name is not None): copy_info(pkg, pkg_dir) icon = os.path.abspath("spreads.ico") extra_files = [(unicode((Path('win_deps') / 'extra' / x.format(arch='.amd64' if bitness == 64 else '')) .absolute()), None) for x in EXTRA_FILES] nsi_template = os.path.abspath("template.nsi") # NOTE: We need to remove the working directory from sys.path to force # pynsist to copy all of our modules, including 'spreads' and 'spreadsplug' # from the site-packages. Additionally, we need to change into the # build directory. if os.getcwd() in sys.path: sys.path.remove(os.getcwd()) os.chdir(unicode(build_path)) builder = InstallerBuilder( appname="spreads", version=spreads.__version__, packages=[x.module_name for x in SOURCE_PACKAGES], extra_files=extra_files, py_version="2.7.6", py_bitness=bitness, build_dir='msi{0}'.format(bitness), installer_name=None, nsi_template=nsi_template, icon=icon, shortcuts={ 'Configure spreads': { 'entry_point': 'spreads.main:run_config_windows', 'icon': icon, 'console': False}, 'Spreads Web Service': { 'entry_point': 'spreads.main:run_service_windows', 'icon': icon, 'console': False} } ) builder.run() os.chdir('..')
def test_copy_installer_nsi(tmpdir): tmpdir = str(tmpdir) files = [ (pjoin(test_dir, 'data_files', 'dir1', 'installer.nsi'), None), ] ib = InstallerBuilder("Test App", "1.0", {}, extra_files=files, build_dir=tmpdir) ib.copy_extra_files() assert_isfile(pjoin(tmpdir, 'installer.1.nsi')) assert ib.install_files == [('installer.1.nsi', '$INSTDIR')]
def test_prepare_shortcuts(tmpdir): tmpdir = str(tmpdir) shortcuts = {'sc1': {'entry_point': 'norwegian.blue:parrot', 'icon': DEFAULT_ICON, 'console': False, 'extra_preamble': sample_preamble}} ib = InstallerBuilder("Test App", "1.0", shortcuts, build_dir=tmpdir) ib.prepare_shortcuts() scfile = pjoin(tmpdir, 'sc1.launch.pyw') assert_isfile(scfile) with io.open(scfile, 'r', encoding='utf-8') as f: contents = f.read() last2lines = [l.strip() for l in contents.rstrip().splitlines()[-2:]] assert last2lines == ['from norwegian.blue import parrot', 'parrot()'] with io.open(sample_preamble, 'r', encoding='utf-8') as f: preamble_contents = f.read().strip() assert preamble_contents in contents
def test_copy_extra_files(tmpdir): tmpdir = str(tmpdir) files = [ (pjoin(test_dir, 'data_files', 'dir1', 'eg-data.txt'), '$INSTDIR'), (pjoin(test_dir, 'data_files', 'dir2', 'eg-data.txt'), '$INSTDIR\\foo'), (pjoin(test_dir, 'data_files', 'dir1', 'subdir'), '$INSTDIR'), (pjoin(test_dir, 'data_files', 'dir2', 'subdir'), '$INSTDIR\\foo'), ] ib = InstallerBuilder("Test App", "1.0", {}, extra_files=files, build_dir=tmpdir) ib.copy_extra_files() build_dir_files = set(os.listdir(tmpdir)) for file in ['eg-data.txt', 'eg-data.1.txt', 'subdir', 'subdir.1']: assert file in build_dir_files assert ib.install_dirs == [ ('subdir', '$INSTDIR'), ('subdir.1', '$INSTDIR\\foo'), ] assert ib.install_files == [ ('eg-data.txt', '$INSTDIR'), ('eg-data.1.txt', '$INSTDIR\\foo'), ]
import os import sys import zipfile from nsist import (configreader, get_installer_builder_args, InstallerBuilder, InputError) if __name__ == '__main__': if len(sys.argv) < 2: print('Provide config file!') sys.exit(1) # load config file, parse into arguments, and setup InstallerBuilder config = configreader.read_and_validate(sys.argv[1]) args = get_installer_builder_args(config) builder = InstallerBuilder(**args) print('Setting up build directory...') try: builder.run(makensis=False) except InputError as e: print("Error in config values:") print(str(e)) sys.exit(1) print('Building installer...') if builder.run_nsis() == 0: print('Installer created: {}'.format(builder.installer_name)) print('Creating auto-updater bundle...') bundle_name = builder.installer_name.replace('exe', 'zip')