From 62981df5ebd091e4be8bf614f2e55ed682b53c73 Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Mon, 2 Aug 2010 22:22:03 +1000 Subject: [PATCH] got esky support code working properly --- setup.py | 1 + signedimp/bootstrap.py | 2 ++ signedimp/compat/__init__.py | 8 ++++++++ signedimp/compat/esky.py | 17 ++++++++++++----- signedimp/tools.py | 5 ++--- 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 signedimp/compat/__init__.py diff --git a/setup.py b/setup.py index 4f595e5..289818c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ # Copyright (c) 2009-2010, Cloud Matrix Pty. Ltd. # All rights reserved; available under the terms of the BSD License. +import os import sys setup_kwds = {} if sys.version_info > (3,): diff --git a/signedimp/bootstrap.py b/signedimp/bootstrap.py index bc4d1e7..b00b54c 100644 --- a/signedimp/bootstrap.py +++ b/signedimp/bootstrap.py @@ -912,6 +912,8 @@ def __init__(self,path=None,base_path=None): else: # We're nowhere on sys.path self.base_path = path + else: + self.base_path = base_path def _exists(self,*args): """Shortcut for checking if a file exists relative to my path.""" diff --git a/signedimp/compat/__init__.py b/signedimp/compat/__init__.py new file mode 100644 index 0000000..b256fea --- /dev/null +++ b/signedimp/compat/__init__.py @@ -0,0 +1,8 @@ +# Copyright (c) 2009-2010, Cloud Matrix Pty. Ltd. +# All rights reserved; available under the terms of the BSD License. +""" + + signedimp.compat: compatability hook for integrating with other packages + +""" + diff --git a/signedimp/compat/esky.py b/signedimp/compat/esky.py index 8ea48cf..856a226 100644 --- a/signedimp/compat/esky.py +++ b/signedimp/compat/esky.py @@ -13,15 +13,22 @@ import signedimp.tools def get_bootstrap_code(key): - signedimp_bootstrap = signedimp.tools.get_bootstrap_code() + signedimp_bootstrap = signedimp.tools.get_bootstrap_code(indent=" ") + pubkey = key.get_public_key() return """ def _make_signedimp_chainload(orig_chainload): %(signedimp_bootstrap)s - key = %(key)r - def chainload(target_dir): + def _chainload(target_dir): + key = signedimp.%(pubkey)r + manager = signedimp.SignedImportManager([key]) + target_exe = pathjoin(target_dir,basename(sys.executable)) + target_imp = signedimp.DefaultImporter(target_dir,target_dir) + target_imp = signedimp.SignedLoader(manager,target_imp) + # Calling get_data forces verification of the specfied data file + target_imp.get_data(basename(sys.executable)) orig_chainload(target_dir) - return chainload -chainload = _make_signedimp_chainload(chainload) + return _chainload +_chainload = _make_signedimp_chainload(_chainload) """ % locals() diff --git a/signedimp/tools.py b/signedimp/tools.py index b14562d..55eaca7 100644 --- a/signedimp/tools.py +++ b/signedimp/tools.py @@ -85,7 +85,7 @@ def _get_source_lines(mod,indent): %(indent)s def _signedimp_init(): %(indent)s import imp %(indent)s signedimp = imp.new_module("signedimp") -%(indent)s %(bscode)s +%(bscode)s %(indent)s lvars = locals() %(indent)s for nm in __all__: %(indent)s setattr(signedimp,nm,lvars[nm]) @@ -94,8 +94,7 @@ def _get_source_lines(mod,indent): %(indent)s signedimp._path_is_broken = True %(indent)s return signedimp %(indent)s signedimp = sys.modules["signedimp"] = _signedimp_init() -""" % dict(bscode="\n".join(_get_source_lines("signedimp.bootstrap"," "*8)), - indent=indent) +""" % dict(indent=indent,bscode="\n".join(_get_source_lines("signedimp.bootstrap",indent+" "*8))) def sign_directory(path,key,hash="sha1",outfile=signedimp.HASHFILE_NAME):