def check_config(self): """ Checks to see if the config has the required XMPP fields filled out accordingly. Then, it evaluates the config file to make sure that all fields exist, at least corresponding to the example config file. """ conf = self.configuration if conf.has_section('xmpp'): if all( conf.has_option('xmpp', k) and conf.get('xmpp', k) for k in MANDATORY_XMPP_OPTIONS): self.xmpp_config_ok = True def_conf = ConfigParser() def_conf.read(DEFAULT_CONFIG_PATH) for section in def_conf.sections(): if conf.has_section(section): for option in def_conf.options(section): if not conf.has_option(section, option) or conf.get( section, option) is None: conf.set(section, option, def_conf.get(section, option)) else: conf.add_section(section) for option in def_conf.options(section): conf.set(section, option, def_conf.get(section, option)) self.configuration = conf self.configuration.write()
def GetCharacterIni(configname): config = ConfigParser() config.read("./characters/"+configname) dictionary = {} for section in config.sections(): dictionary[section] = {} for option in config.options(section): dictionary[section][option] = config.get(section, option) return dictionary
def exec_legacy(arg): try: tmp = arg.split(":") if len(tmp) < 2: raise AssertionError("Error: incorrect service path: " + arg) app_name = tmp[0] app_path = tmp[1] # print "Service: app_name=",app_name," app_path=",app_path setup_logger(app_name) t = threading.Thread(target=alive_worker, args=(30.0, )) t.start() app_dir = os.path.join(mi2app_utils.get_files_dir(), "app") # add this dir to module search path sys.path.append(os.path.join(app_dir, app_path)) app_file = os.path.join(app_dir, app_path, "main.mi2app") Logger.info("Phone model: " + mi2app_utils.get_phone_model()) Logger.info("Running app: " + app_file) # print arg,app_dir,os.path.join(app_dir, arg) namespace = {"service_context": mi2app_utils.get_service_context()} # Load configurations as global variables config = ConfigParser() config.read('/sdcard/.mobileinsight.ini') ii = arg.rfind('/') section_name = arg[ii + 1:] plugin_config = {} if section_name in config.sections(): config_options = config.options(section_name) for item in config_options: plugin_config[item] = config.get(section_name, item) namespace["plugin_config"] = plugin_config gps_provider = GpsListener(on_gps) gps_provider.start() execfile(app_file, namespace) # print app_name, "stops normally" except Exception as e: # Print traceback logs to analysis tb_exc = traceback.format_exc() Logger.error(tb_exc) l = logging.getLogger("mobileinsight_logger") l.error(tb_exc) sys.exit(tb_exc)
print "Phone model: " + mi2app_utils.get_phone_model() print "Running app: " + app_file # print arg,app_dir,os.path.join(app_dir, arg) namespace = {"service_context": mi2app_utils.get_service_context()} # Load configurations as global variables config = ConfigParser() config.read('/sdcard/.mobileinsight.ini') ii = arg.rfind('/') section_name = arg[ii + 1:] plugin_config = {} if section_name in config.sections(): config_options = config.options(section_name) for item in config_options: plugin_config[item] = config.get(section_name, item) namespace["plugin_config"] = plugin_config # gps_provider = GpsListener(on_gps) gps_provider.start() execfile(app_file, namespace) # print app_name, "stops normally" except Exception as e: # print "Exceptions!!!"