mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
convert-legacy-stream is only used for incomming migration from pre Xen 4.7, and verify-stream-v2 appears to only be used by me during migration development - it is little surprise that they missed the main converstion effort in Xen 4.13. Fix it all up. Move open_file_or_fd() into a new util.py to avoid duplication, making it a more generic wrapper around open() or fdopen(). In libxc.py, drop all long() conversion. Python 2 will DTRT with int => long promotion, even on 32bit builds. In convert-legacy-stream, don't pass empty strings to write_record(). Join on the empty argl will do the right thing. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
24 lines
489 B
Python
24 lines
489 B
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
def open_file_or_fd(val, *argl, **kwargs):
|
|
"""
|
|
If 'val' looks like a decimal integer, open it as an fd. If not, try to
|
|
open it as a regular file.
|
|
"""
|
|
|
|
fd = -1
|
|
try:
|
|
# Does it look like an integer?
|
|
fd = int(val, 10)
|
|
except ValueError:
|
|
pass
|
|
|
|
# Try to open it...
|
|
if fd != -1:
|
|
return os.fdopen(fd, *argl, **kwargs)
|
|
else:
|
|
return open(val, *argl, **kwargs)
|