Forráskód Böngészése

Pull request feedback

Cody Scott 8 éve
szülő
commit
c9505a3c2b

+ 1 - 29
nsist/__init__.py

@@ -24,6 +24,7 @@ if os.name == 'nt':
 else:
 else:
     winreg = None
     winreg = None
 
 
+from .configreader import get_installer_builder_args
 from .commands import prepare_bin_directory
 from .commands import prepare_bin_directory
 from .copymodules import copy_modules
 from .copymodules import copy_modules
 from .nsiswriter import NSISFileWriter
 from .nsiswriter import NSISFileWriter
@@ -500,35 +501,6 @@ if __name__ == '__main__':
             if not exitcode:
             if not exitcode:
                 logger.info('Installer written to %s', pjoin(self.build_dir, self.installer_name))
                 logger.info('Installer written to %s', pjoin(self.build_dir, self.installer_name))
 
 
-
-def get_installer_builder_args(config):
-    def get_boolean(s):
-        if s.lower() in ('1', 'yes', 'true', 'on'):
-            return True
-        if s.lower() in ('0', 'no', 'false', 'off'):
-            return False
-        raise ValueError('ValueError: Not a boolean: {}'.format(s))
-
-    appcfg = config['Application']
-    args = {}
-    args['appname'] = appcfg['name'].strip()
-    args['version'] = appcfg['version'].strip()
-    args['publisher'] = appcfg['publisher'].strip() if 'publisher' in appcfg else None
-    args['icon'] = appcfg.get('icon', DEFAULT_ICON).strip()
-    args['packages'] = config.get('Include', 'packages', fallback='').strip().splitlines()
-    args['pypi_wheel_reqs'] = config.get('Include', 'pypi_wheels', fallback='').strip().splitlines()
-    args['extra_files'] = configreader.read_extra_files(config)
-    args['py_version'] = config.get('Python', 'version', fallback=DEFAULT_PY_VERSION).strip()
-    args['py_bitness'] = config.getint('Python', 'bitness', fallback=DEFAULT_BITNESS)
-    args['py_format'] = config.get('Python', 'format').strip() if 'format' in config['Python'] else None
-    inc_msvcrt = config.get('Python', 'include_msvcrt', fallback='True')
-    args['inc_msvcrt'] = get_boolean(inc_msvcrt.strip())
-    args['build_dir'] = config.get('Build', 'directory', fallback=DEFAULT_BUILD_DIR).strip()
-    args['installer_name'] = config.get('Build', 'installer_name') if 'installer_name' in config['Build'] else None
-    args['nsi_template'] = config.get('Build', 'nsi_template').strip() if 'nsi_template' in config['Build'] else None
-    args['exclude'] = config.get('Include', 'exclude', fallback='').strip().splitlines()
-    return args
-
 def main(argv=None):
 def main(argv=None):
     """Make an installer from the command line.
     """Make an installer from the command line.
 
 

+ 40 - 7
nsist/configreader.py

@@ -11,12 +11,12 @@ class SectionValidator(object):
             key is mandatory
             key is mandatory
         """
         """
         self.keys = keys
         self.keys = keys
-    
+
     def check(self, config, section_name):
     def check(self, config, section_name):
         """
         """
         validates the section, if this is the correct validator for it
         validates the section, if this is the correct validator for it
         returns True if this is the correct validator for this section
         returns True if this is the correct validator for this section
-        
+
         raises InvalidConfig if something inside the section is wrong
         raises InvalidConfig if something inside the section is wrong
         """
         """
         self._check_mandatory_fields(section_name, config[section_name])
         self._check_mandatory_fields(section_name, config[section_name])
@@ -33,7 +33,7 @@ class SectionValidator(object):
                                 section_name,
                                 section_name,
                                 key_name)
                                 key_name)
                     raise InvalidConfig(err_msg)
                     raise InvalidConfig(err_msg)
-    
+
     def _check_invalid_keys(self, section_name, section):
     def _check_invalid_keys(self, section_name, section):
         for key in section:
         for key in section:
             key_name = str(key)
             key_name = str(key)
@@ -116,12 +116,12 @@ def read_and_validate(config_file):
                        "be one of these: {1}").format(
                        "be one of these: {1}").format(
                        section,
                        section,
                        ', '.join(['"%s"' % n for n in valid_section_names]))
                        ', '.join(['"%s"' % n for n in valid_section_names]))
-            raise InvalidConfig(err_msg)    
+            raise InvalidConfig(err_msg)
     return config
     return config
 
 
 def read_extra_files(cfg):
 def read_extra_files(cfg):
     """Read the list of extra files from the config file.
     """Read the list of extra files from the config file.
-    
+
     Returns a list of 2-tuples: (file, destination_directory), which can be
     Returns a list of 2-tuples: (file, destination_directory), which can be
     passed as the ``extra_files`` parameter to :class:`nsist.InstallerBuilder`.
     passed as the ``extra_files`` parameter to :class:`nsist.InstallerBuilder`.
     """
     """
@@ -138,10 +138,10 @@ def read_extra_files(cfg):
 
 
 def read_shortcuts_config(cfg):
 def read_shortcuts_config(cfg):
     """Read and verify the shortcut definitions from the config file.
     """Read and verify the shortcut definitions from the config file.
-    
+
     There is one shortcut per 'Shortcut <name>' section, and one for the
     There is one shortcut per 'Shortcut <name>' section, and one for the
     Application section.
     Application section.
-    
+
     Returns a dict of dicts with the fields from the shortcut sections.
     Returns a dict of dicts with the fields from the shortcut sections.
     The optional 'icon' and 'console' fields will be filled with their
     The optional 'icon' and 'console' fields will be filled with their
     default values if not supplied.
     default values if not supplied.
@@ -201,3 +201,36 @@ def read_commands_config(cfg):
                                     cc['extra_preamble'])
                                     cc['extra_preamble'])
 
 
     return commands
     return commands
+
+
+def get_installer_builder_args(config):
+    from . import (DEFAULT_BITNESS,
+                    DEFAULT_BUILD_DIR,
+                    DEFAULT_ICON,
+                    DEFAULT_PY_VERSION)
+    def get_boolean(s):
+        if s.lower() in ('1', 'yes', 'true', 'on'):
+            return True
+        if s.lower() in ('0', 'no', 'false', 'off'):
+            return False
+        raise ValueError('ValueError: Not a boolean: {}'.format(s))
+
+    appcfg = config['Application']
+    args = {}
+    args['appname'] = appcfg['name'].strip()
+    args['version'] = appcfg['version'].strip()
+    args['publisher'] = appcfg['publisher'].strip() if 'publisher' in appcfg else None
+    args['icon'] = appcfg.get('icon', DEFAULT_ICON).strip()
+    args['packages'] = config.get('Include', 'packages', fallback='').strip().splitlines()
+    args['pypi_wheel_reqs'] = config.get('Include', 'pypi_wheels', fallback='').strip().splitlines()
+    args['extra_files'] = read_extra_files(config)
+    args['py_version'] = config.get('Python', 'version', fallback=DEFAULT_PY_VERSION).strip()
+    args['py_bitness'] = config.getint('Python', 'bitness', fallback=DEFAULT_BITNESS)
+    args['py_format'] = config.get('Python', 'format').strip() if 'format' in config['Python'] else None
+    inc_msvcrt = config.get('Python', 'include_msvcrt', fallback='True')
+    args['inc_msvcrt'] = get_boolean(inc_msvcrt.strip())
+    args['build_dir'] = config.get('Build', 'directory', fallback=DEFAULT_BUILD_DIR).strip()
+    args['installer_name'] = config.get('Build', 'installer_name') if 'installer_name' in config['Build'] else None
+    args['nsi_template'] = config.get('Build', 'nsi_template').strip() if 'nsi_template' in config['Build'] else None
+    args['exclude'] = config.get('Include', 'exclude', fallback='').strip().splitlines()
+    return args

+ 2 - 6
nsist/tests/test_configuration_validator.py

@@ -4,7 +4,6 @@ import os
 from nose.tools import *
 from nose.tools import *
 
 
 from .. import configreader
 from .. import configreader
-from .. import get_installer_builder_args
 
 
 
 
 DATA_FILES = os.path.join(os.path.dirname(__file__), 'data_files')
 DATA_FILES = os.path.join(os.path.dirname(__file__), 'data_files')
@@ -12,10 +11,7 @@ DATA_FILES = os.path.join(os.path.dirname(__file__), 'data_files')
 def test_valid_config():
 def test_valid_config():
     configfile = os.path.join(DATA_FILES, 'valid_config.cfg')
     configfile = os.path.join(DATA_FILES, 'valid_config.cfg')
     config = configreader.read_and_validate(configfile)
     config = configreader.read_and_validate(configfile)
-    print(config['Application'])
-    print('Application' in config)
-    print(config.has_section('Application'))
-    # assert False
+    assert config.has_section('Application')
 
 
 def test_valid_config_with_shortcut():
 def test_valid_config_with_shortcut():
     configfile = os.path.join(DATA_FILES, 'valid_config_with_shortcut.cfg')
     configfile = os.path.join(DATA_FILES, 'valid_config_with_shortcut.cfg')
@@ -49,7 +45,7 @@ def test_valid_config_with_values_starting_on_new_line():
     assert config.get('Include', 'exclude') == '\nsomething'
     assert config.get('Include', 'exclude') == '\nsomething'
     assert config.get('Include', 'files') == '\nLICENSE\ndata_files/'
     assert config.get('Include', 'files') == '\nLICENSE\ndata_files/'
 
 
-    args = get_installer_builder_args(config)
+    args = configreader.get_installer_builder_args(config)
     assert args['appname'] == 'My App'
     assert args['appname'] == 'My App'
     assert args['version'] == '1.0'
     assert args['version'] == '1.0'
     assert args['publisher'] == 'Test'
     assert args['publisher'] == 'Test'