Easier and more self documenting patterns for loading/saving Persistent
[python_utils.git] / 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     """Returns True if running as root.
13
14     >>> is_running_as_root()
15     False
16     """
17     return os.geteuid() == 0
18
19
20 def debugger_is_attached() -> bool:
21     """Return if the debugger is attached"""
22
23     gettrace = getattr(sys, 'gettrace', lambda: None)
24     return gettrace() is not None
25
26
27 if __name__ == '__main__':
28     import doctest
29
30     doctest.testmod()