def load_from_file(filepath):
mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
if mod_name.startswith("__init__"):
return
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
else:
return None
class_inst = getattr(py_mod, mod_name)()
return class_inst
python类load_compiled()的实例源码
def load_compiled(self, name, filename, file=None):
return imp.load_compiled(name, filename, file)
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
oracle_to_redshift_loader.py 文件源码
项目:Oracle-To-Redshift-Data-Loader
作者: alexbuz
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def import_module(filepath):
class_inst = None
#expected_class = 'MyClass'
mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
return py_mod
csv_loader_for_redshift.py 文件源码
项目:CSV_Loader_For_Redshift
作者: alexbuz
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def import_module(filepath):
class_inst = None
#expected_class = 'MyClass'
mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
return py_mod
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
def load_compiled(self, name, filename, file=None):
return imp.load_compiled(name, filename, file)
def load_from_file(filepath, expectedClass):
class_inst = None
mod_name,file_ext = splitext(split(filepath)[-1])
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
if hasattr(py_mod, expectedClass):
class_inst = getattr(py_mod, expectedClass)()
return class_inst
def load_compiled(self, name, filename, file=None):
return imp.load_compiled(name, filename, file)
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
def load_compiled(self, name, filename, file=None):
return imp.load_compiled(name, filename, file)
def load_module_from_file(filepath, d=None):
class_inst = None
expected_class = 'main'
mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
if hasattr(py_mod, expected_class):
class_inst = getattr(py_mod, expected_class)(d)
return class_inst
postgresql_to_redshift_loader.py 文件源码
项目:PostgreSQL_To_Redshift_Loader
作者: alexbuz
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def import_module(filepath):
class_inst = None
#expected_class = 'MyClass'
mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
if file_ext.lower() == '.py':
py_mod = imp.load_source(mod_name, filepath)
elif file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
return py_mod
def load_module_pyc(module_id, path):
with open(path, 'rb') as fp:
mod = imp.load_compiled(module_id, path, fp)
# no source encoding here
return mod
def _load_plugins_from(self, path):
files = sorted(os.listdir(path)) # sorting to ensure that .py goes first
included = []
for f in files:
if f.startswith('plugin_'):
try:
if f.endswith('.py'):
if f + 'c' in files:
if os.path.getmtime(os.path.join(path, f + 'c')) > os.path.getmtime(os.path.join(path, f)):
# .pyc newer
continue
elif f + 'o' in files:
if os.path.getmtime(os.path.join(path, f + 'o')) > os.path.getmtime(os.path.join(path, f)):
# .pyo newer
continue
self._add_plugin(
imp.load_source('', os.path.join(path, f)), f, f[7:-3])
included.append(f)
elif f.endswith('.pyc') or f.endswith('.pyo'):
if f[:-1] in included:
continue
if f.endswith('c') and f[:-1] + 'o' in files:
if os.path.getmtime(os.path.join(path, f[:-1] + 'o')) > os.path.getmtime(os.path.join(path, f)):
# .pyo newer
continue
elif f[:-1] + 'c' in files:
if os.path.getmtime(os.path.join(path, f[:-1] + 'c')) > os.path.getmtime(os.path.join(path, f)):
# .pyc newer
continue
self._add_plugin(
imp.load_compiled('', os.path.join(path, f)), f, f[7:-4])
included.append(f[:-1])
except Exception:
self.log(u'[b]?????? ??? ???????? ??????? %s[/b]' % f, 2)
self.log(traceback.format_exc().decode('utf8'), 2)