Pārlūkot izejas kodu

Use license_file and minor refactoring in light of code review.

Nicholas H.Tollervey 7 gadi atpakaļ
vecāks
revīzija
0c39e2e94f
5 mainītis faili ar 24 papildinājumiem un 20 dzēšanām
  1. 1 1
      doc/cfgfile.rst
  2. 15 11
      nsist/__init__.py
  3. 2 2
      nsist/configreader.py
  4. 4 4
      nsist/nsiswriter.py
  5. 2 2
      nsist/pyapp.nsi

+ 1 - 1
doc/cfgfile.rst

@@ -81,7 +81,7 @@ Application section
    If you use the Python API, this parameter can also be passed as a file-like
    If you use the Python API, this parameter can also be passed as a file-like
    object, such as :class:`io.StringIO`.
    object, such as :class:`io.StringIO`.
 
 
-.. describe:: license (optional)
+.. describe:: license_file (optional)
 
 
   Path to a text file containing the license under which your software is to
   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
   be distributed. If given, an extra step before installation will check the

+ 15 - 11
nsist/__init__.py

@@ -96,7 +96,7 @@ class InstallerBuilder(object):
                 py_format='bundled', inc_msvcrt=True, build_dir=DEFAULT_BUILD_DIR,
                 py_format='bundled', inc_msvcrt=True, build_dir=DEFAULT_BUILD_DIR,
                 installer_name=None, nsi_template=None,
                 installer_name=None, nsi_template=None,
                 exclude=None, pypi_wheel_reqs=None, extra_wheel_sources=None,
                 exclude=None, pypi_wheel_reqs=None, extra_wheel_sources=None,
-                commands=None, license=None):
+                commands=None, license_file=None):
         self.appname = appname
         self.appname = appname
         self.version = version
         self.version = version
         self.publisher = publisher
         self.publisher = publisher
@@ -108,7 +108,7 @@ class InstallerBuilder(object):
         self.pypi_wheel_reqs = pypi_wheel_reqs or []
         self.pypi_wheel_reqs = pypi_wheel_reqs or []
         self.extra_wheel_sources = extra_wheel_sources or []
         self.extra_wheel_sources = extra_wheel_sources or []
         self.commands = commands or {}
         self.commands = commands or {}
-        self.license = license
+        self.license_file = license_file
 
 
         # Python options
         # Python options
         self.py_version = py_version
         self.py_version = py_version
@@ -202,9 +202,7 @@ class InstallerBuilder(object):
             z.extractall(python_dir)
             z.extractall(python_dir)
 
 
         # Manipulate any *._pth files so the default paths AND pkgs directory
         # Manipulate any *._pth files so the default paths AND pkgs directory
-        # ends up in sys.path. Please see:
+        # ends up in sys.path.
-        # https://docs.python.org/3/using/windows.html#finding-modules
-        # for more information.
         pth_files = [f for f in os.listdir(python_dir)
         pth_files = [f for f in os.listdir(python_dir)
                      if os.path.isfile(pjoin(python_dir, f))
                      if os.path.isfile(pjoin(python_dir, f))
                      and f.endswith('._pth')]
                      and f.endswith('._pth')]
@@ -283,7 +281,7 @@ if __name__ == '__main__':
         copy to the build directory. Prepare target and parameters for these
         copy to the build directory. Prepare target and parameters for these
         shortcuts.
         shortcuts.
 
 
-        Also copies shortcut icons, and, if specified, the license file.
+        Also copies shortcut icons.
         """
         """
         files = set()
         files = set()
         for scname, sc in self.shortcuts.items():
         for scname, sc in self.shortcuts.items():
@@ -315,14 +313,18 @@ if __name__ == '__main__':
             shutil.copy2(sc['icon'], self.build_dir)
             shutil.copy2(sc['icon'], self.build_dir)
             sc['icon'] = os.path.basename(sc['icon'])
             sc['icon'] = os.path.basename(sc['icon'])
             files.add(sc['icon'])
             files.add(sc['icon'])
+        self.install_files.extend([(f, '$INSTDIR') for f in files])
 
 
-        # Copy license
+    def copy_license(self):
-        if self.license:
+        """
-            shutil.copy2(self.license, self.build_dir)
+        If a license file has been specified, ensure it's copied into the
-            license_file_name = os.path.basename(self.license)
+        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'))
             self.install_files.append((license_file_name, '$INSTDIR'))
 
 
-        self.install_files.extend([(f, '$INSTDIR') for f in files])
 
 
     def prepare_packages(self):
     def prepare_packages(self):
         """Move requested packages into the build directory.
         """Move requested packages into the build directory.
@@ -455,6 +457,8 @@ if __name__ == '__main__':
 
 
         self.prepare_shortcuts()
         self.prepare_shortcuts()
 
 
+        self.copy_license()
+
         if self.commands:
         if self.commands:
             self.prepare_commands()
             self.prepare_commands()
 
 

+ 2 - 2
nsist/configreader.py

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

+ 4 - 4
nsist/nsiswriter.py

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

+ 2 - 2
nsist/pyapp.nsi

@@ -32,8 +32,8 @@ SetCompressor lzma
 ; UI pages
 ; UI pages
 [% block ui_pages %]
 [% block ui_pages %]
 !insertmacro MUI_PAGE_WELCOME
 !insertmacro MUI_PAGE_WELCOME
-[% if license %]
+[% if license_file %]
-!insertmacro MUI_PAGE_LICENSE [[license]]
+!insertmacro MUI_PAGE_LICENSE [[license_file]]
 [% endif %]
 [% endif %]
 !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_DIRECTORY