Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import os
00018 import re
00019 import imp
00020
00021 regex = re.compile(ur'^(.*)(\b.msg\b)(.*)$')
00022
00023
00024 class LibLoader:
00025 @staticmethod
00026 def loadFromFile(filepath):
00027
00028
00029 mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])
00030
00031 if file_ext.lower() == '.py':
00032 py_mod = imp.load_source(mod_name, filepath)
00033
00034 elif file_ext.lower() == '.pyc':
00035 py_mod = imp.load_compiled(mod_name, filepath)
00036
00037 return py_mod
00038
00039 @staticmethod
00040 def load3rdParty(filepath, className):
00041
00042
00043
00044 module = LibLoader.loadFromFile(filepath)
00045 return getattr(module, className)
00046
00047 @staticmethod
00048 def loadFromSystem(lib):
00049
00050
00051 module = None
00052 matches = re.search(regex, lib)
00053 if matches is not None:
00054 module_name = str(matches.group(1)) + str(matches.group(2))
00055 modules = str(matches.group(3)).split(".")
00056 modules = modules[1: len(modules)]
00057 module = __import__(module_name, globals(), locals(), [module_name.split('.')[-1]])
00058 for name in modules:
00059 module = getattr(module, name)
00060 return module
00061
00062
00063 def generateRosDependencies():
00064 directories = os.environ["ROS_PACKAGE_PATH"].split(":")
00065 imports = """from include.logger import Log\n\n"""
00066 imports = """unloaded = 0\nlibs=[]\n"""
00067 for directory in directories:
00068 if os.path.isdir(directory):
00069 for folder in os.listdir(directory):
00070 if "msg" in folder:
00071 imports += """try:\n import {}.msg\nexcept Exception:\n unloaded += 1\n libs.append('{}')\n""".format(folder, folder)
00072 imports += "Log('WARNING', str(unloaded) + ' libraries not loaded: ' + str(libs))"
00073 path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ros", "dependencies", "generated.py")
00074 f = open(path, 'w')
00075 f.write(imports)
00076 f.close()