Bläddra i källkod

Merge pull request #143 from ntoll/master

Universal icon usage and allow for license check.
Thomas Kluyver 7 år sedan
förälder
incheckning
22401a403a
6 ändrade filer med 50 tillägg och 9 borttagningar
  1. 10 2
      doc/cfgfile.rst
  2. 11 0
      doc/releasenotes.rst
  3. 17 4
      nsist/__init__.py
  4. 2 0
      nsist/configreader.py
  5. 5 2
      nsist/nsiswriter.py
  6. 5 1
      nsist/pyapp.nsi

+ 10 - 2
doc/cfgfile.rst

@@ -62,8 +62,9 @@ Application section
 
 .. describe:: icon (optional)
 
-  Path to a ``.ico`` file to be used for shortcuts to your application. Pynsist
-  has a default generic icon, but you probably want to replace it.
+  Path to a ``.ico`` file to be used for shortcuts to your application and
+  during the install/uninstall process. Pynsist has a default generic icon, but
+  you probably want to replace it.
 
 .. describe:: console (optional)
 
@@ -80,6 +81,13 @@ Application section
    If you use the Python API, this parameter can also be passed as a file-like
    object, such as :class:`io.StringIO`.
 
+.. describe:: license_file (optional)
+
+  Path to a text file containing the license under which your software is to
+  be distributed. If given, an extra step before installation will check the
+  user's agreement to abide by the displayed license. If not given, the extra
+  step is omitted.
+
 .. _shortcut_config:
 
 Shortcut sections

+ 11 - 0
doc/releasenotes.rst

@@ -1,6 +1,17 @@
 Release notes
 =============
 
+Version 2.2
+-----------
+
+* Ensure that if an icon is specified it will be used during install and
+  uninstall, and as the icon for the installer itself (:ghpull:`143`).
+* Add handling of a license file. If a `license_file` is given in the
+  `Application` section of the configuration file an additional step will take
+  place before installation to check the user's agreement to abide by the
+  displayed license. If the license is not given, the extra step is omitted
+  (the default behaviour) (:ghpull:`143`).
+
 Version 2.1
 -----------
 

+ 17 - 4
nsist/__init__.py

@@ -26,7 +26,7 @@ from .nsiswriter import NSISFileWriter
 from .pypi import fetch_pypi_wheels
 from .util import download, text_types, get_cache_dir
 
-__version__ = '2.1'
+__version__ = '2.2'
 
 pjoin = os.path.join
 logger = logging.getLogger(__name__)
@@ -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_file=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_file = license_file
 
         # 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.
         """
         files = set()
         for scname, sc in self.shortcuts.items():
@@ -314,9 +315,19 @@ if __name__ == '__main__':
             shutil.copy2(sc['icon'], self.build_dir)
             sc['icon'] = os.path.basename(sc['icon'])
             files.add(sc['icon'])
-
         self.install_files.extend([(f, '$INSTDIR') for f in files])
 
+    def copy_license(self):
+        """
+        If a license file has been specified, ensure it's copied into the
+        install directory and added to the install_files list.
+        """
+        if self.license_file:
+            shutil.copy2(self.license_file, self.build_dir)
+            license_file_name = os.path.basename(self.license_file)
+            self.install_files.append((license_file_name, '$INSTDIR'))
+
+
     def prepare_packages(self):
         """Move requested packages into the build directory.
 
@@ -448,6 +459,8 @@ if __name__ == '__main__':
 
         self.prepare_shortcuts()
 
+        self.copy_license()
+
         if self.commands:
             self.prepare_commands()
 

+ 2 - 0
nsist/configreader.py

@@ -63,6 +63,7 @@ CONFIG_VALIDATORS = {
         ('icon', False),
         ('console', False),
         ('extra_preamble', False),
+        ('license_file', 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_file'] = appcfg.get('license_file', 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_file = None
+        if installerbuilder.license_file:
+            license_file = os.path.basename(installerbuilder.license_file)
         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_file': license_file,
         }
 
     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_file %]
+!insertmacro MUI_PAGE_LICENSE [[license_file]]
+[% endif %]
 !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_INSTFILES