Commit 7197aff7 authored by Ruslan Kuprieiev's avatar Ruslan Kuprieiev Committed by Pavel Emelyanov

pycriu: images: pb2dict: preserve fields order with "pretty" option

Using collections.OrderedDict allows us to keep fields in the
same order as they appear in corresponding proto files, which
helps to impove readability. In non-pretty mode we still use
regular dict.
Signed-off-by: 's avatarRuslan Kuprieiev <rkuprieiev@cloudlinux.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e0b24e21
...@@ -2,6 +2,7 @@ from google.protobuf.descriptor import FieldDescriptor as FD ...@@ -2,6 +2,7 @@ from google.protobuf.descriptor import FieldDescriptor as FD
import opts_pb2 import opts_pb2
import ipaddr import ipaddr
import socket import socket
import collections
# pb2dict and dict2pb are methods to convert pb to/from dict. # pb2dict and dict2pb are methods to convert pb to/from dict.
# Inspired by: # Inspired by:
...@@ -74,7 +75,7 @@ def pb2dict(pb, pretty = False, is_hex = False): ...@@ -74,7 +75,7 @@ def pb2dict(pb, pretty = False, is_hex = False):
Convert protobuf msg to dictionary. Convert protobuf msg to dictionary.
Takes a protobuf message and returns a dict. Takes a protobuf message and returns a dict.
""" """
d = {} d = collections.OrderedDict() if pretty else {}
for field, value in pb.ListFields(): for field, value in pb.ListFields():
if field.label == FD.LABEL_REPEATED: if field.label == FD.LABEL_REPEATED:
d_val = [] d_val = []
......
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