Skip to content

Commit

Permalink
Update to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Mar 27, 2022
1 parent 6d719f4 commit 26c1683
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import **libpnu**

*libpnu*.**handle_interrupt_signals**(Function *handler_function*)

String *libpnu*.**get_home_directory**()

List *libpnu*.**locate_directory**(String *directory*)

## DESCRIPTION
Expand All @@ -23,6 +25,9 @@ for example with the *logging.NOTSET* parameter to get DEBUG or more logging lev
The **handle_interrupt_signals()** function calls the specified *handler_function* to process the SIGINT and SIGPIPE signals,
usually to avoid an ugly trace dump to the console in case of interrupt (Control-C pressed or broken pipe).

The **get_home_directory()** function returns the location of the user's home directory in a string
depending on the operating system used (Unix, Windows).

The **locate_directory()** function searches the specified *directory* in a variety of possible other directories,
depending on the operating system used (Unix, Windows) and the fact that a package can be user or system installed.
It is intended to be used when the directory can't be directly found, and returns a list of paths where the directory searched has been found.
Expand All @@ -37,7 +42,7 @@ The following environment variables can be used to identify the user identity an

On Unix: *HOME*, *LOGNAME*, *USER*, *LNAME* and *USERNAME*.

On Windows: *APPDATA*, *HOMEPATH* and *USERPROFILE*.
On Windows: *APPDATA*, *HOME*, *HOMEPATH* and *USERPROFILE*.

## STANDARDS
The **libpnu** library is not a standard UNIX one.
Expand Down
11 changes: 10 additions & 1 deletion man/libpnu.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd February 28, 2022
.Dd March 27, 2022
.Dt LIBPNU 3
.Os
.Sh NAME
Expand All @@ -13,6 +13,9 @@
.Fo libpnu.handle_interrupt_signals
.Fa "Function handler_function"
.Fc
.Ft String
.Fo libpnu.get_home_directory
.Fc
.Ft List
.Fo libpnu.locate_directory
.Fa "String directory"
Expand All @@ -36,6 +39,11 @@ usually to avoid an ugly trace dump to the console
in case of interrupt (Control-C pressed or broken pipe).
.Pp
The
.Fn get_home_directory
function returns the location of the user's home directory in a string
depending on the operating system used (Unix, Windows).
.Pp
The
.Fn locate_directory
function searches the specified
.Fa directory
Expand Down Expand Up @@ -66,6 +74,7 @@ and
.Pp
On Windows:
.Ev APPDATA ,
.Ev HOME ,
.Ev HOMEPATH
and
.Ev USERPROFILE .
Expand Down
2 changes: 1 addition & 1 deletion 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.0.0
version = 1.1.0
license = BSD 3-Clause License
license_files = License
author = Hubert Tournier
Expand Down
30 changes: 29 additions & 1 deletion src/libpnu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys

# Version string used by the what(1) and ident(1) commands:
ID = "@(#) $Id: libpnu - Common utility functions for the PNU project v1.0.0 (February 28, 2022) by Hubert Tournier $"
ID = "@(#) $Id: libpnu - Common utility functions for the PNU project v1.1.0 (March 27, 2022) by Hubert Tournier $"


################################################################################
Expand All @@ -30,6 +30,34 @@ def handle_interrupt_signals(handler_function):
signal.signal(signal.SIGPIPE, handler_function)


################################################################################
def get_home_directory():
"""Return the path to the user's home directory"""
home_directory = ""
if os.name == "posix":
if "HOME" in os.environ:
if os.path.isdir(os.environ["HOME"]):
home_directory = os.environ["HOME"]
else:
user = getpass.getuser()
if user:
if os.path.isdir(pwd.getpwnam(user)[5]):
home_directory = pwd.getpwnam(user)[5]

elif os.name == "nt":
if "HOME" in os.environ:
if os.path.isdir(os.environ["HOME"]):
home_directory = os.environ["HOME"]
elif "HOMEPATH" in os.environ:
if os.path.isdir(os.environ["HOMEPATH"]):
home_directory = os.environ["HOMEPATH"]
elif "USERPROFILE" in os.environ:
if os.path.isdir(os.environ["USERPROFILE"]):
home_directory = os.environ["USERPROFILE"]

return home_directory


################################################################################
def locate_directory(directory):
"""Return a list of paths containing the specified directory"""
Expand Down

0 comments on commit 26c1683

Please sign in to comment.