Przeglądaj źródła

If icon is specified, use it in the installer/uninstaller. Also, if license is specified, include a step in the installer to ask for agreement to the terms of the referenced license.

Nicholas H.Tollervey 7 lat temu
rodzic
commit
7409981a08
4 zmienionych plików z 21 dodań i 5 usunięć
  1. 9 2
      nsist/__init__.py
  2. 2 0
      nsist/configreader.py
  3. 5 2
      nsist/nsiswriter.py
  4. 5 1
      nsist/pyapp.nsi

+ 9 - 2
nsist/__init__.py

@@ -96,7 +96,7 @@ class InstallerBuilder(object):
                 py_format='bundled', inc_msvcrt=True, build_dir=DEFAULT_BUILD_DIR,
                 installer_name=None, nsi_template=None,
                 exclude=None, pypi_wheel_reqs=None, extra_wheel_sources=None,
-                commands=None):
+                commands=None, license=None):
         self.appname = appname
         self.version = version
         self.publisher = publisher
@@ -108,6 +108,7 @@ class InstallerBuilder(object):
         self.pypi_wheel_reqs = pypi_wheel_reqs or []
         self.extra_wheel_sources = extra_wheel_sources or []
         self.commands = commands or {}
+        self.license = license
 
         # Python options
         self.py_version = py_version
@@ -282,7 +283,7 @@ if __name__ == '__main__':
         copy to the build directory. Prepare target and parameters for these
         shortcuts.
 
-        Also copies shortcut icons
+        Also copies shortcut icons, and, if specified, the license file.
         """
         files = set()
         for scname, sc in self.shortcuts.items():
@@ -315,6 +316,12 @@ if __name__ == '__main__':
             sc['icon'] = os.path.basename(sc['icon'])
             files.add(sc['icon'])
 
+        # Copy license
+        if self.license:
+            shutil.copy2(self.license, self.build_dir)
+            license_file_name = os.path.basename(self.license)
+            self.install_files.append((license_file_name, '$INSTDIR'))
+
         self.install_files.extend([(f, '$INSTDIR') for f in files])
 
     def prepare_packages(self):

+ 2 - 0
nsist/configreader.py

@@ -63,6 +63,7 @@ CONFIG_VALIDATORS = {
         ('icon', False),
         ('console', False),
         ('extra_preamble', False),
+        ('license', False),
     ]),
     'Build': SectionValidator([
         ('directory', False),
@@ -220,6 +221,7 @@ def get_installer_builder_args(config):
     args['commands'] = read_commands_config(config)
     args['publisher'] = appcfg.get('publisher', None)
     args['icon'] = appcfg.get('icon', DEFAULT_ICON)
+    args['license'] = appcfg.get('license', None)
     args['packages'] = config.get('Include', 'packages', fallback='').strip().splitlines()
     args['pypi_wheel_reqs'] = config.get('Include', 'pypi_wheels', fallback='').strip().splitlines()
     args['extra_wheel_sources'] = [Path(p) for p in

+ 5 - 2
nsist/nsiswriter.py

@@ -46,7 +46,9 @@ class NSISFileWriter(object):
         grouped_files = [(dest, [x[0] for x in group]) for (dest, group) in
             itertools.groupby(self.installerbuilder.install_files, itemgetter(1))
                 ]
-
+        license = None
+        if installerbuilder.license:
+            license = os.path.basename(installerbuilder.license)
         self.namespace = {
             'ib': installerbuilder,
             'grouped_files': grouped_files,
@@ -56,7 +58,8 @@ class NSISFileWriter(object):
             'single_shortcut': len(installerbuilder.shortcuts) == 1,
             'pynsist_pkg_dir': _PKGDIR,
             'has_commands': len(installerbuilder.commands) > 0,
-            'python': '"$INSTDIR\\Python\\python"'
+            'python': '"$INSTDIR\\Python\\python"',
+            'license': license,
         }
 
     def write(self, target):

+ 5 - 1
nsist/pyapp.nsi

@@ -26,11 +26,15 @@ SetCompressor lzma
 ; Modern UI installer stuff 
 !include "MUI2.nsh"
 !define MUI_ABORTWARNING
-!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
+!define MUI_ICON "[[icon]]"
+!define MUI_UNICON "[[icon]]"
 
 ; UI pages
 [% block ui_pages %]
 !insertmacro MUI_PAGE_WELCOME
+[% if license %]
+!insertmacro MUI_PAGE_LICENSE [[license]]
+[% endif %]
 !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_INSTFILES