Skip to content

Commit

Permalink
Update to v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Mar 10, 2024
1 parent 330f334 commit f3b5790
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = pnu-libpnu
description = Common utility functions for the PNU project
long_description = file: README.md
long_description_content_type = text/markdown
version = 1.2.0
version = 1.2.1
license = BSD 3-Clause License
license_files = License
author = Hubert Tournier
Expand All @@ -21,7 +21,6 @@ classifiers =
Operating System :: OS Independent
Operating System :: POSIX :: BSD :: FreeBSD
Operating System :: Microsoft :: Windows
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Expand All @@ -31,6 +30,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Software Development :: Libraries :: Python Modules

[options]
Expand Down
69 changes: 40 additions & 29 deletions src/libpnu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@
import pwd

# Version string used by the what(1) and ident(1) commands:
ID = "@(#) $Id: libpnu - Common utility functions for the PNU project v1.2.0 (May 8, 2023) by Hubert Tournier $"
ID = "@(#) $Id: libpnu - Common utility functions for the PNU project v1.2.1 (March 10, 2024) by Hubert Tournier $"


################################################################################
####################################################################################################
def initialize_debugging(program_name):
""" Set up debugging """
""" Sets up debugging """
console_log_format = program_name + ": %(levelname)s: %(message)s"
logging.basicConfig(format=console_log_format, level=logging.DEBUG)
# Only log entries of level WARNING, ERROR or CRITICAL will be shown by default
logging.disable(logging.INFO)


################################################################################
####################################################################################################
def handle_interrupt_signals(handler_function):
""" Process interrupt signals """
""" Processes interrupt signals """
signal.signal(signal.SIGINT, handler_function)
if os.name == "posix":
signal.signal(signal.SIGPIPE, handler_function)


################################################################################
####################################################################################################
def get_home_directory():
""" Return the path to the user's home directory """
""" Returns the path to the user's home directory """
home_directory = ""

if os.name == "posix":
Expand Down Expand Up @@ -65,35 +66,35 @@ def get_home_directory():

####################################################################################################
def get_caching_directory(name):
""" Find and create a directory to save cached files """
directory = ''
""" Finds and creates a directory to save cached files """
directory = ""

if os.name == 'nt':
if 'LOCALAPPDATA' in os.environ:
directory = os.environ['LOCALAPPDATA'] + os.sep + "cache" + os.sep + name
elif 'TMP' in os.environ:
directory = os.environ['TMP'] + os.sep + "cache" + os.sep + name
if os.name == "nt":
if "LOCALAPPDATA" in os.environ:
directory = os.environ["LOCALAPPDATA"] + os.sep + "cache" + os.sep + name
elif "TMP" in os.environ:
directory = os.environ["TMP"] + os.sep + "cache" + os.sep + name

else: # os.name == 'posix':
if 'HOME' in os.environ:
directory = os.environ['HOME'] + os.sep + ".cache" + os.sep + name
elif 'TMPDIR' in os.environ:
directory = os.environ['TMPDIR'] + os.sep + ".cache" + os.sep + name
elif 'TMP' in os.environ:
directory = os.environ['TMP'] + os.sep + ".cache" + os.sep + name
if "HOME" in os.environ:
directory = os.environ["HOME"] + os.sep + ".cache" + os.sep + name
elif "TMPDIR" in os.environ:
directory = os.environ["TMPDIR"] + os.sep + ".cache" + os.sep + name
elif "TMP" in os.environ:
directory = os.environ["TMP"] + os.sep + ".cache" + os.sep + name

if directory:
try:
os.makedirs(directory, exist_ok=True)
except OSError:
directory = ''
directory = ""

return directory


################################################################################
####################################################################################################
def locate_directory(directory):
""" Return a list of paths containing the specified directory """
""" Returns a list of paths containing the specified directory """
directories_list = []

parts = []
Expand Down Expand Up @@ -152,18 +153,28 @@ def locate_directory(directory):
return directories_list


################################################################################
####################################################################################################
def load_strings_from_file(filename):
""" Load a list of strings from a file filtering out blank or commented lines """
""" Loads a list of strings from a file filtering out comments and empty lines """
lines = []
strings = []

if os.path.isfile(filename):
with open(filename, encoding='utf-8', errors='ignore') as file:
with open(filename, encoding="utf-8", errors="ignore") as file:
lines = file.read().splitlines()

# Return all non empty lines not starting with a '#' comment character
# Also strip comments at the end of lines
return [re.sub(r"[ ]*#.*", "", line) for line in lines if line and not line.startswith('#')]
# Remove comments (unless the comment character is escaped):
for line in lines:
line = line.strip()
line = re.sub(r"\\#", "²", line) # horrible kludge!
line = re.sub(r"[ ]*#.*", "", line) # remove comments
line = re.sub(r"²", "\\#", line)

# Only return non empty lines:
if line:
strings.append(line)

return strings


if __name__ == "__main__":
Expand Down

0 comments on commit f3b5790

Please sign in to comment.