Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/param_metadata/ednemit.py
Views: 1799
"""1Emits parameters as an EDN file, does some small remapping of names2"""34from emit import Emit5import edn_format6import datetime7import pytz8import subprocess91011class EDNEmit(Emit):12def __init__(self, *args, **kwargs):13Emit.__init__(self, *args, **kwargs)14self.output = "{:date " + edn_format.dumps(datetime.datetime.now(pytz.utc)) + " "15git = subprocess.Popen(["git log --pretty=format:'%h' -n 1"], shell=True, stdout=subprocess.PIPE).communicate()[0]16self.output += ":git-hash \"" + git.decode("ascii") + "\" "17self.remove_keys = ["real_path"]18self.explict_remap = [["displayname", "display-name"]]19self.vehicle_name = None2021def close(self):22if self.vehicle_name is not None:23self.output += ":vehicle \"" + self.vehicle_name + "\" "24else:25raise Exception('Vehicle name never found')26self.output += "}"27f = open("parameters.edn", mode='w')28f.write(self.output)29f.close()3031def start_libraries(self):32pass3334def emit(self, g):35for param in g.params:36output_dict = dict()37# lowercase all keywords38for key in param.__dict__.keys():39output_dict[key.lower()] = param.__dict__[key]4041# strip off any leading sillyness on the param name42split_name = param.__dict__["name"].split(":")43if len(split_name) == 2:44self.vehicle_name = split_name[0]45name = param.__dict__["name"].split(":")[-1]46output_dict["name"] = name4748# remove any keys we don't really care to share49for key in self.remove_keys:50output_dict.pop(key, None)51for key in list(output_dict.keys()):52if not self.should_emit_field(param, key):53output_dict.pop(key, None)5455# rearrange bitmasks to be a vector with nil's if the bit doesn't have meaning56if "bitmask" in output_dict:57highest_set_bit = 058bits = []59for bit in output_dict["bitmask"].split(","):60bit_parts = bit.split(":")61bit_number = int(bit_parts[0])62bit_parts[0] = bit_number63bits.append(bit_parts)64if bit_number > highest_set_bit:65highest_set_bit = bit_number66output_bits = (highest_set_bit+1)*[None]67for bit in bits:68output_bits[bit[0]] = bit[1]69output_dict["bitmask"] = output_bits7071# rearrange values into a float indexed map72if "values" in output_dict:73values = dict()74for value in output_dict["values"].split(","):75index, description = value.split(":")76values[float(index)] = description77output_dict["values"] = values7879# remap range to be a map of floats80if "range" in output_dict:81low, high = output_dict["range"].split()82output_dict["range"] = {"low": float(low), "high": float(high)}8384# remap the string to a float85if "increment" in output_dict:86output_dict["increment"] = float(output_dict["increment"])8788# do any name changing desired89for remap in self.explict_remap:90output_dict[remap[1]] = output_dict.pop(remap[0])9192self.output += "\"" + name + "\" " + edn_format.dumps(output_dict, keyword_keys=True)939495