Miscellaneous utilities.
[python_utils.git] / misc_utils.py
1 #!/usr/bin/env python3
2
3 import os
4
5 import string_utils
6
7
8 def is_running_as_root() -> bool:
9     return os.geteuid() == 0
10
11
12 def is_are(n: int) -> str:
13     if n == 1:
14         return "is"
15     return "are"
16
17
18 def pluralize(n: int) -> str:
19     if n == 1:
20         return ""
21     return "s"
22
23
24 def thify(n: int) -> str:
25     digit = str(n)
26     assert string_utils.is_integer_number(digit)
27     digit = digit[-1:]
28     if digit == "1":
29         return "st"
30     elif digit == "2":
31         return "nd"
32     elif digit == "3":
33         return "rd"
34     else:
35         return "th"