Handle exception from os when attempting to determine console sizes.
[pyutils.git] / src / pyutils / misc_utils.py
1 #!/usr/bin/env python3
2
3 # © Copyright 2021-2022, Scott Gasch
4
5 """Miscellaneous utilities."""
6
7 import os
8 import sys
9
10
11 def is_running_as_root() -> bool:
12     """
13     Returns:
14         True if running as root, False otherwise.
15
16     >>> is_running_as_root()
17     False
18     """
19     return os.geteuid() == 0
20
21
22 def debugger_is_attached() -> bool:
23     """
24     Returns:
25         True if a debugger is attached, False otherwise.
26     """
27     gettrace = getattr(sys, 'gettrace', lambda: None)
28     return gettrace() is not None
29
30
31 if __name__ == '__main__':
32     import doctest
33
34     doctest.testmod()