Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7396 from goanpeca/enh/organize-common-os-utils
Rename common.platform to common.os and split among windows, linux and unix utils
- Loading branch information
Showing
9 changed files
with
92 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2012 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from logging import getLogger | ||
|
||
from ..compat import on_win | ||
|
||
|
||
if on_win: | ||
from .windows import get_free_space_on_windows as get_free_space | ||
from .windows import is_admin_on_windows as is_admin | ||
else: | ||
from .unix import get_free_space_on_unix as get_free_space # noqa | ||
from .unix import is_admin_on_unix as is_admin # noqa | ||
|
||
|
||
log = getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2012 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import os | ||
|
||
from logging import getLogger | ||
|
||
|
||
log = getLogger(__name__) | ||
|
||
|
||
def get_free_space_on_unix(dir_name): | ||
st = os.statvfs(dir_name) | ||
return st.f_bavail * st.f_frsize | ||
|
||
|
||
def is_admin_on_unix(): | ||
# http://stackoverflow.com/a/1026626/2127762 | ||
return os.geteuid() == 0 or os.getegid() == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2012 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from logging import getLogger | ||
|
||
from ..compat import on_win | ||
|
||
|
||
_ctypes = None | ||
if on_win: | ||
import ctypes as _ctypes | ||
|
||
|
||
log = getLogger(__name__) | ||
|
||
|
||
def get_free_space_on_windows(dir_name): | ||
result = None | ||
if _ctypes: | ||
free_bytes = _ctypes.c_ulonglong(0) | ||
_ctypes.windll.kernel32.GetDiskFreeSpaceExW(_ctypes.c_wchar_p(dir_name), None, | ||
None, _ctypes.pointer(free_bytes)) | ||
result = free_bytes.value | ||
|
||
return result | ||
|
||
|
||
def is_admin_on_windows(): # pragma: unix no cover | ||
# http://stackoverflow.com/a/1026626/2127762 | ||
result = False | ||
if _ctypes: | ||
try: | ||
result = _ctypes.windll.shell32.IsUserAnAdmin() != 0 | ||
except Exception as e: # pragma: no cover | ||
log.info('%r', e) | ||
result = 'unknown' | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters