Completed
Push — master ( 15c423...616cf9 )
by Kale
64:00
created

get_free_space_on_windows()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2012 Anaconda, Inc
3
# SPDX-License-Identifier: BSD-3-Clause
4
from __future__ import absolute_import, division, print_function, unicode_literals
5
6
from logging import getLogger
7
8
from ..compat import on_win
9
10
11
_ctypes = None
12
if on_win:
13
    import ctypes as _ctypes
14
15
16
log = getLogger(__name__)
17
18
19
def get_free_space_on_windows(dir_name):
20
    result = None
21
    if _ctypes:
22
        free_bytes = _ctypes.c_ulonglong(0)
23
        _ctypes.windll.kernel32.GetDiskFreeSpaceExW(_ctypes.c_wchar_p(dir_name), None,
24
                                                    None, _ctypes.pointer(free_bytes))
25
        result = free_bytes.value
26
27
    return result
28
29
30
def is_admin_on_windows():  # pragma: unix no cover
31
    # http://stackoverflow.com/a/1026626/2127762
32
    result = False
33
    if _ctypes:
34
        try:
35
            result = _ctypes.windll.shell32.IsUserAnAdmin() != 0
36
        except Exception as e:  # pragma: no cover
37
            log.info('%r', e)
38
            result = 'unknown'
39
40
    return result
41