-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcc_100_100_helper_functions.py
129 lines (100 loc) · 3.82 KB
/
pcc_100_100_helper_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""Helper functions for the Paylocity Coding Challenge."""
import os
import re
import sys
__all__ = ["ExtractModuleNameFromFileName", "normalize_path", "BannerPrint"]
_FILE_EXTENSION = "py"
# def BannerPrint(
# MarquisStr: str,
# BannerChar: str = "*",
# BannerWidth: int = "80",
# *,
# PrintTopBorder: bool = True,
# LinesAboveTopBorder: int = 1,
# LinesBelowTopBorder: int = 0,
# LinesAboveMarquisStr: int = 1,
# LinesBelowMarquisStr: int = 1,
# PrintBottomBorder: bool = True,
# LinesAboveBottomBorder: int = 0,
# LinesBelowBottomBorder: int = 1,
# ) -> str:
# """
# Print a banner to make a text string standout.
# LinesAboveTopBorder == 1
# ****************************** PrintTopBorder == True
# My Sample Text MarquisStr == "My Sample Text"
# ****************************** PrintBottomBorder == True
# LinesBelowBottomBorder == 1
# """
# if PrintTopBorder:
# if int(LinesAboveTopBorder) > 0:
# print("\n" * int(LinesAboveTopBorder - 1))
# if int(LinesBelowTopBorder) > 0:
# print("\n" * int(LinesBelowTopBorder - 1))
# if int(LinesAboveMarquisStr) > 0:
# print("\n" * int(LinesAboveMarquisStr - 1))
# if int(BannerWidth - len(MarquisStr)) > 2:
# print(MarquisStr.center(BannerWidth - 2, " "))
# else:
# print(MarquisStr)
# if int(LinesBelowMarquisStr) > 0:
# print("\n" * int(LinesBelowMarquisStr - 1))
# if PrintBottomBorder:
# if int(LinesAboveBottomBorder) > 0:
# print("\n" * int(LinesAboveBottomBorder - 1))
# if int(LinesBelowBottomBorder) > 0:
# print("\n" * int(LinesBelowBottomBorder - 1))
def BannerPrint(
MarquisStr: str, BannerChar: str = "*", BannerWidth: int = 80
) -> str: # noqa: E501
"""
Print a banner to make a text string standout.
"""
print("")
print("".ljust(BannerWidth, "*"))
if int(BannerWidth) - len(MarquisStr) > 2:
print(f" {MarquisStr} ".center(int(BannerWidth) - 2, " "))
else:
print(MarquisStr)
print("".ljust(BannerWidth, "*"))
print("")
def normalize_path(path: str) -> str:
"""
Normalize a file system path regardless of OS.
CREDITS:
https://stackoverflow.com/a/20713238/4507836
"""
return os.path.normpath(os.sep.join(re.split(r"\\|/", path)))
def ExtractModuleNameFromFileName(filename: str) -> str:
"""
Extract the basename portion of a Python module file.
EXAMPLES:
>>> from pcc_100_100_helper_functions import *
>>> ExtractModuleNameFromFileName('C:\\python\\py_mod.py')
'py_mod'
>>> ExtractModuleNameFromFileName('/usr/home/eric/python/py_mod.py')
'py_mod'
"""
if filename is None or filename == "":
raise ValueError("'filename' must not be empty")
baseFileName = os.path.basename(normalize_path(filename))
if baseFileName.rpartition(".")[2] != _FILE_EXTENSION:
errMsg = (
f"'filename' must terminate with '.{_FILE_EXTENSION}' "
"(case sensitive)\n"
)
raise ValueError(errMsg)
moduleName = baseFileName.rpartition(".")[0]
return moduleName
def main():
"""main() function for module."""
MODULE_NAME = ExtractModuleNameFromFileName(__file__)
if len(sys.argv) > 1:
warnMsg = (
f"'{MODULE_NAME}' does not accept any command line parameters.\n"
"See help documentation for more information.\n"
f" >>> help({MODULE_NAME})\n"
)
raise UserWarning(warnMsg)
if __name__ == "__main__":
main()