def set_param_sync(name, dat): for k in dat: org = rospy.get_param(name + '/' + k) if isinstance(dat[k], dict): dictlib.merge(org, dat[k]) else: org = dat[k] rospy.set_param(name + '/' + k, org)
def merge(f): entry = os.listdir(dir) rc = entry[0] yf = open(dir + "/" + rc + "/" + f, "r") master = yaml.load(yf) for rc in entry[1:]: yf = open(dir + "/" + rc + "/" + f, "r") dictlib.merge(master, yaml.load(yf)) yf.close() for rc in entry: yf = open(dir + "/" + rc + "/" + f, "r") dictlib.merge(master, yaml.load(yf)) yf.close() yf = open(dir + "/" + rc + "/" + f, "w") yaml.dump(master, yf, default_flow_style=False) yf.close()
ebox.popup() def parse_argv(argv): args = {} for arg in argv: tokens = arg.split(":=") if len(tokens) == 2: key = tokens[0] args[key] = tokens[1] return args ######################################################## rospy.init_node("dashboard", anonymous=True) dictlib.merge(Config, parse_argv(sys.argv)) thispath = commands.getoutput("rospack find rtk_tools") init_load = None if "load" in Config: init_load = Config["load"] yamlpath = thispath + "/../" + Config["load"] yaml.add_constructor( yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, lambda loader, node: OrderedDict(loader.construct_pairs(node))) try: conf = yaml.load(file(yamlpath)) commands.getoutput("rosparam load " + yamlpath) except: conf = {} try: dictlib.merge(Config, conf["config"]["dashboard"])
if re.match(r'\([ ]*([0-9.]+,[ ]*)*[0-9.]+[ ]*\)$', tokens[1]): # convert tuple-like-string to tuple args[key] = eval(tokens[1]) continue args[key] = tokens[1] return args ####ROS Init#### rospy.init_node("report", anonymous=True) try: conf = rospy.get_param("/config/report") except: conf = {} try: dictlib.merge(Config, conf) except Exception as e: print("get_param exception:", e.args) dictlib.merge(Config, parse_argv(sys.argv)) if "recipe" in Config: Config["keys"].insert(0, "__recipe__") Config["labels"].insert(0, "recipe") Config["keys"].insert(0, "__count__") Config["labels"].insert(0, "#") ####sub pub rospy.Subscriber("/report", String, cb_report) rospy.Subscriber("/report/update", Bool, cb_update)
def parse_argv(argv): args = {} for arg in argv: tokens = arg.split(":=") if len(tokens) == 2: key = tokens[0] args[key] = tokens[1] return args ######################################################## rospy.init_node("dashboard", anonymous=True) #dictlib.merge(Config,parse_argv(sys.argv)) try: dictlib.merge(Config, rospy.get_param("/config/dashboard")) except Exception as e: print "get_param exception:", e.args thispath = commands.getoutput("rospack find rtk_tools") if "load" in Config: commands.getoutput("rosparam load " + thispath + "/../" + Config["load"]) if "recipe" in Config: srcpath = re.subn(r".*?/", "/", thispath[::-1], 1)[0][::-1] dirpath = srcpath + Config["recipe"]["dir"] linkpath = srcpath + Config["recipe"]["link"] print "dirpath", dirpath print "linkpath", linkpath try: dictlib.merge(Config, rospy.get_param("/config/dashboard")) except Exception as e: print "get_param exception:", e.args