mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
crit: add --format hex option
Pavel reported that decimal values for some fields are hard to read,
because people used to see hex values in there. Unfortunately, json
doesn't support hex representation of integers, so we can only store
them as hex strings. Not all field need to be represented as hex
strings, so this set introduces a custom field option called "criu"
to use in our proto files. One should use [(criu).hex = true] to mark
which field should be represented as a hex string. pb2dict module
from pycriu package will look into field options and if he finds that
criu.hex is set to True, it will convert such field to/from hex string.
Though, such behaviour is optional and user can request it by specifying
--format hex when calling crit decode("crit encode" in its turn, detects
such fields automatically and doesn't require any special cmdline options
to be set).
We need our proto files to compile with both protoc and
protoc-c compilers, which requires creating google/protobuf
directory with a symlink to /usr/include/google/protobuf/
descriptor.proto to make protoc-c and generated c files happy.
Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
5feac80336
commit
87da3e3437
7 changed files with 59 additions and 25 deletions
14
crit
14
crit
|
|
@ -7,7 +7,7 @@ import pycriu
|
|||
|
||||
def handle_cmdline_opts():
|
||||
desc = 'CRiu Image Tool'
|
||||
parser = argparse.ArgumentParser(description=desc)
|
||||
parser = argparse.ArgumentParser(description=desc, formatter_class=argparse.RawTextHelpFormatter)
|
||||
parser.add_argument('command',
|
||||
choices = ['decode', 'encode'],
|
||||
help = 'decode/encode - convert criu image from/to binary type to/from json')
|
||||
|
|
@ -19,8 +19,12 @@ def handle_cmdline_opts():
|
|||
help = 'output file (stdout by default)')
|
||||
parser.add_argument('-f',
|
||||
'--format',
|
||||
choices = ['raw', 'nice'],
|
||||
help = 'well-formated output (by default: raw for files and nice for stdout)')
|
||||
choices = ['raw', 'nice', 'hex'],
|
||||
nargs = '+',
|
||||
default = [],
|
||||
help = 'raw - all in one line\n'\
|
||||
'nice - add indents and newlines to look nice(default for stdout)\n'\
|
||||
'hex - print int fields as hex strings where suitable(could be combined with others)')
|
||||
|
||||
opts = vars(parser.parse_args())
|
||||
|
||||
|
|
@ -41,10 +45,10 @@ def outf(opts):
|
|||
|
||||
def decode(opts):
|
||||
indent = None
|
||||
img = pycriu.images.load(inf(opts))
|
||||
img = pycriu.images.load(inf(opts), opts['format'])
|
||||
|
||||
# For stdout --format nice is set by default.
|
||||
if opts['format'] == 'nice' or (opts['format'] == None and opts['out'] == None):
|
||||
if 'nice' in opts['format'] or ('raw' not in opts['format'] and opts['out'] == None):
|
||||
indent = 4
|
||||
|
||||
f = outf(opts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue