def getobject(fullname): """todo""" if not fullname: return # todo: validate pkgname.modname.object.key names = fullname.split(".") module = None for i, _ in enumerate(names): name = ".".join(names[0:i + 1]) if find_module(name): module = load_module(name) if i == len(names) - 1: return module else: break if not module: # module not found # __builtins__ object ? if hasattr(builtins, fullname): return getattr(builtins, fullname) # module ? if not module: # raise ImportError(fullname) return if objectname(module, fullname=True).lower() == fullname.lower(): return module # module.object ? obj = module for i in range(i, len(names)): attr = names[i] if hasattr(obj, attr): obj = getattr(obj, attr) if i == len(names) - 1: return obj
def import_path(path, name=None, dont_write_bytecode=None): _dont_write_bytecode = sys.dont_write_bytecode try: path = str(path) if name: name = str(name) assert_exists(path) if not name: name = re.sub("[^a-zA-Z0-9]", '_', path) if os.path.isfile(path): name = name.replace(".pyc", "").replace(".py", "") if name in ["__init__.py", "__init__.pyc"]: name = os.path.basename(os.path.dirname(path)) # if exists(path): # if isdir(path): # fullname = basename(path) # path = dirname(path) if dont_write_bytecode is None: dont_write_bytecode = _dont_write_bytecode sys.dont_write_bytecode = dont_write_bytecode warnings.simplefilter("ignore", RuntimeWarning) warnings.simplefilter("ignore", ImportWarning) ext = os.path.splitext(path)[1] if os.path.isfile(path) and ext not in [".py", ".pyc"]: mod = imp.load_source(name, path) else: mod = load_module(name, path) return mod finally: sys.dont_write_bytecode = _dont_write_bytecode
def read(self, json_obj): self._mFrameType = json_obj["type"] self._mDescription = json_obj["description"] formats = json_obj["formats"] for format in formats: if("type" in format): typeStr = format["type"] dataType = lm.load_module(typeStr, self._mLogger)() dataType.setLogger(self._mLogger) dataType.read(format) self._mXBeeDataTypes.append(dataType) else: if(self._mLogger is not None): logMessage = "ERROR: no \"type\" specified for format\n" self._mLogger.critical(logMessage)
import tornado from load_module import load_module load_module('application') load_module('webservice') load_module('physical') from application.Application import Application from webservice.WebService import WebService from physical.controller.pedal_zero_controller.simple_patch_gpio_zero_controller import SimplePatchGpioZeroController from physical.controller.android_controller.android_controller import AndroidController address = 'raspberrypi.local' #address = '10.0.0.102' port = 3000 application = Application(data_patch="data/", address=address, test=True) application.register(WebService(application, port)) application.register(SimplePatchGpioZeroController(application, test=True)) #application.register(AndroidController(application, "adb")) #application.register(AndroidController(application, "~/Desktop/adb-arm/adb-rpi3")) application.start() tornado.ioloop.IOLoop.current().start()