Imported core, m, ag and serial for refactoring

This commit is contained in:
Overwatch 2014-08-05 10:19:01 +02:00
parent 6f28ac0382
commit 5baa9b75d0
25 changed files with 918 additions and 4 deletions

31
core/core.51-import.pyx Normal file
View file

@ -0,0 +1,31 @@
import imp
def import_module(path):
"""
Imports a python file as a module. The path can be relative or absolute.
Based on the work of Yuval Greenfield released into the public domain.
"""
# remove the .py suffix
mod_dn = os.path.dirname(path)
mod_fn = os.path.basename(path)
if mod_fn.endswith(".py"):
mod_name = mod_fn[:-3]
else:
# packages for example
mod_name = mod_fn
fd = None
try:
data = imp.find_module(mod_name, [mod_dn])
module = imp.load_module(mod_name, *data)
fd = data[0]
finally:
if fd is not None:
fd.close()
return module