Miscellaneous utilities.
authorScott Gasch <[email protected]>
Sat, 24 Apr 2021 00:13:34 +0000 (17:13 -0700)
committerScott Gasch <[email protected]>
Sat, 24 Apr 2021 00:13:34 +0000 (17:13 -0700)
misc_utils.py [new file with mode: 0644]

diff --git a/misc_utils.py b/misc_utils.py
new file mode 100644 (file)
index 0000000..62e5798
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+
+import os
+
+import string_utils
+
+
+def is_running_as_root() -> bool:
+    return os.geteuid() == 0
+
+
+def is_are(n: int) -> str:
+    if n == 1:
+        return "is"
+    return "are"
+
+
+def pluralize(n: int) -> str:
+    if n == 1:
+        return ""
+    return "s"
+
+
+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"