import os import re ## get the name of the OS __OS: str = os.name # define the path spec pattern depending on OS __REGEX_PAT = re.compile(r'^(.+)[\\]([^\\]+)\\*$') \ if __OS == "nt" else re.compile(r'^(.+)[\/]([^\/]+)$') class LogLevel: """Enumerator structure to map an integer against a log level. Higher `int` value means higher severity of level for logging. """ NORMAL = 0 PASS = 1 DEBUG = 2 WARN = 3 ERROR = 4 def is_path_spec(path_spec: str) -> bool: """Evaluate if a given string is a valid pathspec identifier. Pathspec evaluation is matched against the following regular expression patterns: ```plaintext OS Pathspec NT: ^(.+)[\\]([^\\]+)\\*$ Other: ^(.+)[\/]([^\/]+)$ OR Valid names of CWD subdirectories ^[\w\d\-_]+$ ``` The following pathspecs are evaluated as valid pathspec identifiers (OS implicitly implied): - C:\\User\\user-1\\Documents\\my-project - $HOME/.local/bin/my_project - ".\\Python Examples\\my-project1" The following pathspecs are evaluated as invalid pathspec identifiers (OS implicitly implied) - ./this,_is-a(bad)+pathspec `@Params`: path_spec - `str` `@Return`: `bool` """ ## perform a regex match to ensure that the given path is a ## valid pathspec for the system. return bool(re.match( __REGEX_PAT, path_spec.strip(r"\"'")) or \ re.match(r'^[\w\d\-_]+$', path_spec.strip(r"\"'")) )