mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
These aren't runable scripts, so shouldn't have shebangs. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
23 lines
467 B
Python
23 lines
467 B
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)
|