summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-04-23 17:13:34 -0700
committerScott Gasch <[email protected]>2021-04-23 17:13:34 -0700
commitcb686fb1f457ce1f55534b94c6565c98f2c69f47 (patch)
tree67e7f6f2f6b86d96d9629bc451f6f950540fd6ec
parente0973abee4c917127169795a56fd9c5c5412913c (diff)
Miscellaneous utilities.
-rw-r--r--misc_utils.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/misc_utils.py b/misc_utils.py
new file mode 100644
index 0000000..62e5798
--- /dev/null
+++ b/misc_utils.py
@@ -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"