From 5e086402f3684059629d761c7bc4d326a9ece963 Mon Sep 17 00:00:00 2001 From: Eli Finer Date: Tue, 25 Dec 2012 16:42:27 +0200 Subject: [PATCH] use absolute filenames in dumps --- .gitignore | 1 + pydump.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ebda54e..45e3810 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ develop-eggs .installed.cfg lib lib64 +MANIFEST # Installer logs pip-log.txt diff --git a/pydump.py b/pydump.py index 4c7f8fd..6aa9a67 100644 --- a/pydump.py +++ b/pydump.py @@ -29,6 +29,8 @@ __version__ = "1.0.0" __all__ = ['save_dump', 'load_dump', '__version__'] +DUMP_VERSION = 1 + def save_dump(filename, tb=None): """ Saves a Python traceback in a pickled file. This function will usually be called from @@ -46,11 +48,15 @@ def save_dump(filename, tb=None): fake_tb = FakeTraceback(tb) dump = { 'traceback':fake_tb, - 'files':_get_traceback_files(fake_tb) + 'files':_get_traceback_files(fake_tb), + 'dump_version' : DUMP_VERSION } pickle.dump(dump, open(filename, 'wb')) def load_dump(filename): + # ugly hack to handle running non-install pydump + if 'pydump.pydump' not in sys.modules: + sys.modules['pydump.pydump'] = sys.modules[__name__] return pickle.load(open(filename, 'rb')) class FakeClass(object): @@ -99,10 +105,11 @@ def _get_traceback_files(traceback): while traceback: frame = traceback.tb_frame while frame: + filename = os.path.abspath(frame.f_code.co_filename) try: - files[frame.f_code.co_filename] = open(frame.f_code.co_filename).read() + files[filename] = open(filename).read() except IOError: - files[frame.f_code.co_filename] = "couldn't locate '%s' during dump" % frame.f_code.co_filename + files[filename] = "couldn't locate '%s' during dump" % frame.f_code.co_filename frame = frame.f_back traceback = traceback.tb_next return files