diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index fba656cf6f..490b4122f6 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -30,12 +30,6 @@ from osc_lib import utils from openstackclient.i18n import _ -if os.name == "nt": - import msvcrt -else: - msvcrt = None - - CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"] DEFAULT_CONTAINER_FORMAT = 'bare' DEFAULT_DISK_FORMAT = 'raw' @@ -53,7 +47,6 @@ DISK_CHOICES = [ "ploop", ] - LOG = logging.getLogger(__name__) @@ -323,8 +316,10 @@ class CreateImage(command.ShowOne): else: # Read file from stdin if not sys.stdin.isatty(): - if msvcrt: - msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + if os.name == "nt": + import msvcrt + + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore if hasattr(sys.stdin, 'buffer'): kwargs['data'] = sys.stdin.buffer else: @@ -774,8 +769,10 @@ class SetImage(command.Command): # Read file from stdin if sys.stdin.isatty() is not True: if parsed_args.stdin: - if msvcrt: - msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + if os.name == "nt": + import msvcrt + + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore if hasattr(sys.stdin, 'buffer'): kwargs['data'] = sys.stdin.buffer else: diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index dfe80a9076..a45f3c39eb 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -37,12 +37,6 @@ from openstackclient.common import progressbar from openstackclient.i18n import _ from openstackclient.identity import common as identity_common -if os.name == "nt": - import msvcrt -else: - msvcrt = None - - CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"] DEFAULT_CONTAINER_FORMAT = 'bare' DEFAULT_DISK_FORMAT = 'raw' @@ -61,7 +55,6 @@ DISK_CHOICES = [ ] MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"] - LOG = logging.getLogger(__name__) @@ -155,8 +148,10 @@ def get_data_from_stdin(): image = sys.stdin if hasattr(sys.stdin, 'buffer'): image = sys.stdin.buffer - if msvcrt: - msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + if os.name == "nt": + import msvcrt + + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore return image else: