Browse Source

Add logging, better error for packages not found.

Thomas Kluyver 11 năm trước cách đây
mục cha
commit
c354fc3de5
3 tập tin đã thay đổi với 17 bổ sung3 xóa
  1. 13 2
      nsisbuilder/__init__.py
  2. 2 0
      nsisbuilder/copymodules.py
  3. 2 1
      nsisbuilder/template.nsi

+ 13 - 2
nsisbuilder/__init__.py

@@ -1,3 +1,4 @@
+import logging
 import os
 import shutil
 from subprocess import check_output, call
@@ -6,6 +7,7 @@ from urllib.request import urlretrieve
 from .copymodules import copy_modules
 
 pjoin = os.path.join
+logger = logging.getLogger(__name__)
 
 _PKGDIR = os.path.dirname(__file__)
 DEFAULT_PY_VERSION = '3.3.2'
@@ -28,7 +30,9 @@ def fetch_python(version=DEFAULT_PY_VERSION, bitness=DEFAULT_BITNESS,
     url = 'http://python.org/ftp/python/{0}/python-{0}{1}.msi'.format(version, arch_tag)
     target = pjoin(destination, 'python-{0}{1}.msi'.format(version, arch_tag))
     if os.path.isfile(target):
+        logger.info('Python MSI already in build directory.')
         return
+    logger.info('Downloading Python MSI...')
     urlretrieve(url, target)
     urlretrieve(url+'.asc', target+'.asc')
     try:
@@ -36,7 +40,7 @@ def fetch_python(version=DEFAULT_PY_VERSION, bitness=DEFAULT_BITNESS,
         check_output(['gpg', '--import', keys_file])
         check_output(['gpg', '--verify', target+'.asc'])
     except FileNotFoundError:
-        print("GPG not available - could not check signature of {0}".format(target))
+        logger.warn("GPG not available - could not check signature of {0}".format(target))
 
 def write_nsis_file(nsi_file, definitions):
     with open(nsi_file, 'w') as f:
@@ -81,14 +85,21 @@ def all_steps(appname, version, script, packages=None, icon=DEFAULT_ICON,
     run_nsis(nsi_file)
 
 def main(argv=None):
+    logger.setLevel(logging.INFO)
+    logger.addHandler(logging.StreamHandler())
+    
     import argparse
     argp = argparse.ArgumentParser(prog='pynsis')
     argp.add_argument('config_file')
     options = argp.parse_args(argv)
     
+    dirname, config_file = os.path.split(options.config_file)
+    if dirname:
+        os.chdir(dirname)
+    
     import configparser
     cfg = configparser.ConfigParser()
-    cfg.read(options.config_file)
+    cfg.read(config_file)
     appcfg = cfg['Application']
     all_steps(
         appname = appcfg['name'],

+ 2 - 0
nsisbuilder/copymodules.py

@@ -10,6 +10,8 @@ class ModuleCopier:
     
     def copy(self, modname, target):
         loader = importlib.find_loader(modname, self.path)
+        if loader is None:
+            raise ImportError('Could not find %s' % modname)
         pkg = loader.is_package(modname)
         file = loader.get_filename(modname)
         if isinstance(loader, importlib.abc.FileLoader):

+ 2 - 1
nsisbuilder/template.nsi

@@ -29,7 +29,7 @@ SectionEnd
 
 Section "Python ${PY_VERSION}" sec_py
   File "python-${PY_VERSION}${ARCH_TAG}.msi"
-  ExecWait 'msiexec /i "$INSTDIR\python-${PY_VERSION}{$ARCH_TAG}.msi" /qb ALLUSERS=1'
+  ExecWait 'msiexec /i "$INSTDIR\python-${PY_VERSION}${ARCH_TAG}.msi" /qb ALLUSERS=1'
   Delete $INSTDIR\python-${PY_VERSION}.msi
 SectionEnd
 
@@ -37,6 +37,7 @@ Section "!${PRODUCT_NAME}" sec_app
   SectionIn RO
   File ${SCRIPT}
   File ${PRODUCT_ICON}
+  File /r "pkgs\*"
   CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}.lnk" "pyw" '"$INSTDIR\${SCRIPT}"' \
       "$INSTDIR\${PRODUCT_ICON}"
   WriteUninstaller $INSTDIR\uninstall.exe