##// END OF EJS Templates
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ipython branch. This is not a true merge in the formal sense because all history is not coming over with the files. For a detailed history of the added files, please see the ipython1-dev branch or the svn repository on scipy.org that ipython1-dev came from. More specifically, here is what I have done in this commit: 1) Moved the following by hand ipython1.config -> IPython.config ipython1.kernel -> IPython.kernel ipython1.external -> IPython.external ipython1.core -> IPython.kernel.core ipython1.testutils -> IPython.testing ipython1.tools -> IPython.tools 2) Moved IPython.tools.guid -> IPython1.external.guid 3) Renamed: ipython1 -> IPython IPython.core -> IPython.kernel.core IPython.testutils -> IPython.testing 4) Then did a "bzr add" for all the new stuff. That is all folks!

File last commit:

r1234:52b55407
r1234:52b55407
Show More
util.py
102 lines | 3.1 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""General utilities for kernel related things."""
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
import os, types
#-------------------------------------------------------------------------------
# Code
#-------------------------------------------------------------------------------
def tarModule(mod):
"""Makes a tarball (as a string) of a locally imported module.
This method looks at the __file__ attribute of an imported module
and makes a tarball of the top level of the module. It then
reads the tarball into a binary string.
The method returns the tarball's name and the binary string
representing the tarball.
Notes:
- It will handle both single module files, as well as packages.
- The byte code files (\*.pyc) are not deleted.
- It has not been tested with modules containing extension code, but
it should work in most cases.
- There are cross platform issues.
"""
if not isinstance(mod, types.ModuleType):
raise TypeError, "Pass an imported module to push_module"
module_dir, module_file = os.path.split(mod.__file__)
# Figure out what the module is called and where it is
print "Locating the module..."
if "__init__.py" in module_file: # package
module_name = module_dir.split("/")[-1]
module_dir = "/".join(module_dir.split("/")[:-1])
module_file = module_name
else: # Simple module
module_name = module_file.split(".")[0]
module_dir = module_dir
print "Module (%s) found in:\n%s" % (module_name, module_dir)
# Make a tarball of the module in the cwd
if module_dir:
os.system('tar -cf %s.tar -C %s %s' % \
(module_name, module_dir, module_file))
else: # must be the cwd
os.system('tar -cf %s.tar %s' % \
(module_name, module_file))
# Read the tarball into a binary string
tarball_name = module_name + ".tar"
tar_file = open(tarball_name,'rb')
fileString = tar_file.read()
tar_file.close()
# Remove the local copy of the tarball
#os.system("rm %s" % tarball_name)
return tarball_name, fileString
#from the Python Cookbook:
def curry(f, *curryArgs, **curryKWargs):
"""Curry the function f with curryArgs and curryKWargs."""
def curried(*args, **kwargs):
dikt = dict(kwargs)
dikt.update(curryKWargs)
return f(*(curryArgs+args), **dikt)
return curried
#useful callbacks
def catcher(r):
pass
def printer(r, msg=''):
print "%s\n%r" % (msg, r)
return r