def set(self): key = self.args.key self._ensure(key in get_session_keys(), "key {} not in {}".format(key, get_session_keys())) value = self.args.value if key == "default_eth_rpc_endpoint": self._ensure( self.session.identity.identity_type != "rpc", "cannot set default_eth_rpc_endpoint while using rpc identity_type" ) to_delete = [] for k in self.config["session"]: if k[-3:] == "_at": to_delete.append(k) for k in to_delete: del self.config["session"][k] self._printerr("unset {}\n".format(k)) if key == "identity_name": self._ensure(self.config.has_section("identity.{}".format(value)), "identity_name {} does not exist".format(value)) identity = self.config["identity.{}".format(value)] for k, _ in identity.items(): try: del self.config["session"]["default_{}".format(k)] self._printerr("unset default_{}\n".format(k)) except KeyError: pass self.config["session"][key] = value self.config.persist() self._printout("set {} {}\n".format(key, value))
def add_unset_options(parser): parser.set_defaults(cmd=SessionCommand) parser.set_defaults(fn="unset") parser.add_argument("key", choices=get_session_keys(), help="session key to unset from {}".format( get_session_keys()), metavar="KEY")
def add_set_options(parser): parser.set_defaults(cmd=SessionCommand) parser.set_defaults(fn="set") parser.add_argument("key", choices=get_session_keys(), help="session key to set from {}".format( get_session_keys()), metavar="KEY") parser.add_argument("value", help="desired value of session key", metavar="VALUE")
def unset(self): key = self.args.key self._ensure(key in get_session_keys(), "key {} not in {}".format(key, get_session_keys())) try: del self.config["session"][key] self.config.persist() self._printout("unset {}\n".format(key)) except KeyError: pass