fabric / fabric
1 1
import logging
2 1
import sys
3

4

5
# Ape the half-assed logging junk from Invoke, but ensuring the logger reflects
6
# our name, not theirs. (Assume most contexts will rely on Invoke itself to
7
# literally enable/disable logging, for now.)
8 1
log = logging.getLogger("fabric")
9 1
for x in ("debug",):
10 1
    globals()[x] = getattr(log, x)
11

12

13 1
win32 = sys.platform == "win32"
14

15

16 1
def get_local_user():
17
    """
18
    Return the local executing username, or ``None`` if one can't be found.
19

20
    .. versionadded:: 2.0
21
    """
22
    # TODO: I don't understand why these lines were added outside the
23
    # try/except, since presumably it means the attempt at catching ImportError
24
    # wouldn't work. However, that's how the contributing user committed it.
25
    # Need an older Windows box to test it out, most likely.
26 1
    import getpass
27

28 1
    username = None
29
    # All Unix and most Windows systems support the getpass module.
30 1
    try:
31 1
        username = getpass.getuser()
32
    # Some SaaS platforms raise KeyError, implying there is no real user
33
    # involved. They get the default value of None.
34 1
    except KeyError:
35 1
        pass
36
    # Older (?) Windows systems don't support getpass well; they should
37
    # have the `win32` module instead.
38
    except ImportError:  # pragma: nocover
39
        if win32:
40
            import win32api
41
            import win32security  # noqa
42
            import win32profile  # noqa
43

44
            username = win32api.GetUserName()
45 1
    return username

Read our documentation on viewing source code .

Loading