Commit fba3f128 authored by Gyanendra Mishra's avatar Gyanendra Mishra

this looks alright

parent f6af4e11
...@@ -21,6 +21,7 @@ def replace_with_defaults(input_args): ...@@ -21,6 +21,7 @@ def replace_with_defaults(input_args):
result = {} result = {}
for attr in dir(input_args): for attr in dir(input_args):
value = getattr(input_args, attr) value = getattr(input_args, attr)
print(attr, value, type(value))
if type(value) == "int" and value == 0: if type(value) == "int" and value == 0:
result[attr] = default_input[attr] result[attr] = default_input[attr]
elif type(value) == "string" and value == "": elif type(value) == "string" and value == "":
...@@ -33,10 +34,14 @@ def replace_with_defaults(input_args): ...@@ -33,10 +34,14 @@ def replace_with_defaults(input_args):
result["network_params"][attr_] = default_input["network_params"][attr_] result["network_params"][attr_] = default_input["network_params"][attr_]
elif type(value_) == "string" and value_ == "": elif type(value_) == "string" and value_ == "":
result["network_params"][attr_] = default_input["network_params"][attr_] result["network_params"][attr_] = default_input["network_params"][attr_]
elif attr_ != "descriptor": # if there are some string, int values we assign it
elif type(value_) in ("int", "string", "bool"):
result["network_params"][attr_] = value_ result["network_params"][attr_] = value_
elif attr == "participants" and value == []: elif type(value) in "proto.EnumValueDescriptor":
result["participant"] = [default_input["participants"][0]] result[attr] = value.name
# no participants are assigned at all
elif attr == "participants" and len(value) == 0:
result["participant"] = default_input["participants"]
elif attr == "participants": elif attr == "participants":
participants = [] participants = []
for participant in participants: for participant in participants:
...@@ -47,10 +52,17 @@ def replace_with_defaults(input_args): ...@@ -47,10 +52,17 @@ def replace_with_defaults(input_args):
participant[attr_] = getattr(default_input[participants][0], attr_, 0) participant[attr_] = getattr(default_input[participants][0], attr_, 0)
elif type(attr_) == "str" and value_ == "": elif type(attr_) == "str" and value_ == "":
participant[attr_] = getattr(default_input[participants][0], attr_, "") participant[attr_] = getattr(default_input[participants][0], attr_, "")
elif type(value_) in ("int", "string", "bool"):
result["participants"][attr_] = value_
elif type(value_) in "proto.EnumValueDescriptor":
result[attr_] = value.name
participants.append(participant) participants.append(participant)
result["participants"] = participants result["participants"] = participants
elif attr != "descriptor": # if there are some string, int values we assign it
result[attr] = default_input[attr] elif type(value) in ("int", "string", "bool"):
result[attr] = value
elif type(value) in "proto.EnumValueDescriptor":
result[attr] = value.name
encoded_json = json.encode(result) encoded_json = json.encode(result)
print(json.indent(encoded_json)) print(json.indent(encoded_json))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment