소스 검색

Better script template

Closes gh-7
Thomas Kluyver 11 년 전
부모
커밋
af4d3ed576
1개의 변경된 파일13개의 추가작업 그리고 2개의 파일을 삭제
  1. 13 2
      nsist/__init__.py

+ 13 - 2
nsist/__init__.py

@@ -79,8 +79,19 @@ def fetch_pylauncher(bitness=DEFAULT_BITNESS, destination=DEFAULT_BUILD_DIR):
     urlretrieve(url, target)
 
 SCRIPT_TEMPLATE = """#!python{qualifier}
-import sys
-sys.path.insert(0, 'pkgs')
+import sys, os
+scriptdir, script = os.path.split(__file__)
+pkgdir = os.path.join(scriptdir, 'pkgs')
+sys.path.insert(0, pkgdir)
+os.environ['PYTHONPATH'] = pkgdir + os.pathsep + os.environ.get('PYTHONPATH', '')
+
+def excepthook(etype, value, tb):
+    "Write unhandled exceptions to a file rather than exiting silently."
+    import traceback
+    with open(os.path.join(scriptdir, script+'.log'), 'w') as f:
+        traceback.print_exception(etype, value, tb, file=f)
+sys.excepthook = excepthook
+
 from {module} import {func}
 {func}()
 """