projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Detect a debugger.
[python_utils.git]
/
misc_utils.py
diff --git
a/misc_utils.py
b/misc_utils.py
index 62e579846b52bed06ade1a37b3e1959bc5c3fa0c..669b3ef98a20d2b4144da67299c463f73ee46851 100644
(file)
--- a/
misc_utils.py
+++ b/
misc_utils.py
@@
-1,35
+1,30
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
-import os
+# © Copyright 2021-2022, Scott Gasch
+
+"""Miscellaneous utilities."""
-import string_utils
+import os
+import sys
def is_running_as_root() -> bool:
def is_running_as_root() -> bool:
+ """Returns True if running as root.
+
+ >>> is_running_as_root()
+ False
+ """
return os.geteuid() == 0
return os.geteuid() == 0
-def is_are(n: int) -> str:
- if n == 1:
- return "is"
- return "are"
+def debugger_is_attached() -> bool:
+ """Return if the debugger is attached"""
+ gettrace = getattr(sys, 'gettrace', lambda: None)
+ return gettrace() is not None
-def pluralize(n: int) -> str:
- if n == 1:
- return ""
- return "s"
+if __name__ == '__main__':
+ import doctest
-def thify(n: int) -> str:
- digit = str(n)
- assert string_utils.is_integer_number(digit)
- digit = digit[-1:]
- if digit == "1":
- return "st"
- elif digit == "2":
- return "nd"
- elif digit == "3":
- return "rd"
- else:
- return "th"
+ doctest.testmod()