Skip to content

Commit

Permalink
2021.8.25 update
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Aug 25, 2021
1 parent 3f0a5fd commit a16693f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 34 deletions.
2 changes: 1 addition & 1 deletion _template/License
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright YEAR YOU
Copyright 2021+ YOU

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
10 changes: 6 additions & 4 deletions _template/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NAME=COMMAND
SECTION=1
SOURCES=src/${NAME}/__init__.py src/${NAME}/main.py

# Default action is to show this help message:
Expand Down Expand Up @@ -43,10 +44,10 @@ format: /usr/local/bin/black
love:
@echo "Not war!"

man/${NAME}.1.gz: man/${NAME}.1
@gzip -k9c man/${NAME}.1 > man/${NAME}.1.gz
man/${NAME}.${SECTION}.gz: man/${NAME}.${SECTION}
@gzip -k9c man/${NAME}.${SECTION} > man/${NAME}.${SECTION}.gz

package: man/${NAME}.1.gz
package: man/${NAME}.${SECTION}.gz
python -m build

upload-test:
Expand All @@ -56,4 +57,5 @@ upload:
python -m twine upload dist/*

distclean:
rm -rf build dist man/${NAME}.1.gz src/*.egg-info
rm -rf build dist man/${NAME}.${SECTION}.gz src/*.egg-info

9 changes: 6 additions & 3 deletions _template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ The **COMMAND** utility exits 0 on success, and >0 if an error occurs.

## STANDARDS
The **COMMAND** utility is a standard UNIX/POSIX command.
The **COMMAND** utility is a standard UNIX command, though not a POSIX one.
The **COMMAND** utility is not a standard UNIX command.

It tries to follow the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide for [Python](https://www.python.org/) code.
This re-implementation tries to follow the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide for [Python](https://www.python.org/) code.

## PORTABILITY
To be tested under Windows.
Tested OK under Windows.

## HISTORY
This utility was made for [The PNU project / PyNIX](https://github.com/HubTou/PNU).
This re-implementation was made for the [PNU project](https://github.com/HubTou/PNU).

## LICENSE
This utility is available under the [3-clause BSD license](https://opensource.org/licenses/BSD-3-Clause).
It is available under the [3-clause BSD license](https://opensource.org/licenses/BSD-3-Clause).

## AUTHORS
[YOU](https://github.com/YOU)
Expand Down
12 changes: 7 additions & 5 deletions _template/man/COMMAND.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ environment variable can also be set to any value to enable debug mode.
The
.Nm
utility is a standard UNIX/POSIX command.
utility is a standard UNIX command, though not a POSIX one.
utility is not a standard UNIX command.
.Pp
It tries to follow the PEP 8 style guide for Python code.
This re-implementation tries to follow the PEP 8 style guide for Python code.
.Sh PORTABILITY
To be tested under Windows.
Tested OK under Windows.
.Sh HISTORY
This utility was made for
.Lk https://github.com/HubTou/PNU [The PNU project / PyNIX]
in order to test the rewritten commands against the installed ones.
This re-implementation was made for the
.Lk https://github.com/HubTou/PNU PNU project
.Sh LICENSE
This utility is available under the 3-clause BSD license.
It is available under the 3-clause BSD license.
.Sh AUTHORS
.An YOU
.Sh CAVEATS
Expand Down
31 changes: 18 additions & 13 deletions _template/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pnu_COMMAND
description = ONE LINE DESCRIPTION
description = ONE_LINE_DESCRIPTION
long_description = file: README.md
long_description_content_type = text/markdown
version = 1.0.0
Expand All @@ -13,34 +13,39 @@ project_urls =
Bug Tracker = https://github.com/YOU/COMMAND/issues
keywords = pnu-project
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.x
Development Status :: 5 - Production/Stable <= if you are sufficiently confident...
Environment :: Console
Intended Audience :: Developers <= if you offer libraries functions
Intended Audience :: End Users/Desktop
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: OS Independent
Operating System :: POSIX :: BSD :: FreeBSD
Operating System :: Microsoft :: Windows
Environment :: Console
Development Status :: 5 - Production/Stable
Natural Language :: English
Topic :: System
Programming Language :: Python :: 3
Programming Language :: Python :: 3.x <= Get this from make check-version
Topic :: Software Development :: Libraries :: Python Modules <= if you offer libraries functions
Topic :: System <= for standard Unix utilities or system tools
Topic :: Utilities

[options]
package_dir =
= src
packages = find:
python_requires = >=3.x
install_requires =
OTHER_PACKAGE
python_requires = >=3.x <= Get this from make check-version
install_requires = <= only if there are packages needed as dependencies
OTHER_PACKAGE <= only if there are packages needed as dependencies

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
COMMAND = COMMAND:main
COMMAND = COMMAND:main <= the main name by which your utility will be called
OTHER_NAME = COMMAND:main <= another name by which your utility can be called if needed

[options.data_files]
man/man1 =
man/COMMAND.1.gz
man/man1 = <= beware the section number
man/COMMAND.1.gz <= beware the section number
man/OTHER_NAME.1.gz <= if needed...

13 changes: 7 additions & 6 deletions _template/src/COMMAND/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NAME=COMMAND
SECTION=1
SOURCES=main.py
DESTROOTDIR=/usr/local

Expand Down Expand Up @@ -42,16 +43,16 @@ checks: check-code check-security check-unused check-version check-sloc
format: /usr/local/bin/black
black ${SOURCES}

${NAME}.1.gz: ../../man/${NAME}.1
@gzip -k9c ../../man/${NAME}.1 > ${NAME}.1.gz
${NAME}.${SECTION}.gz: ../../man/${NAME}.${SECTION}
@gzip -k9c ../../man/${NAME}.${SECTION} > ${NAME}.${SECTION}.gz

install: ${NAME}.1.gz
install: ${NAME}.${SECTION}.gz
install -m 0755 -o root -g wheel main.py ${DESTROOTDIR}/bin/${NAME}
install -m 0644 -o root -g wheel ${NAME}.1.gz ${DESTROOTDIR}/man/man1
install -m 0644 -o root -g wheel ${NAME}.${SECTION}.gz ${DESTROOTDIR}/man/man${SECTION}

uninstall:
rm -f ${DESTROOTDIR}/bin/${NAME}
rm -f ${DESTROOTDIR}/man/man1/${NAME}.1.gz
rm -f ${DESTROOTDIR}/man/man${SECTION}/${NAME}.${SECTION}.gz

whatis:
makewhatis
Expand All @@ -60,7 +61,7 @@ love:
@echo "Not war!"

clean:
@rm -f ${NAME}.1.gz
@rm -f ${NAME}.${SECTION}.gz

distclean: clean

28 changes: 26 additions & 2 deletions _template/src/COMMAND/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Default parameters. Can be overcome by environment variables, then command line options
parameters = {
"Some meaninggul label": False,
"Command flavour": "bsd:freebsd",
}


Expand All @@ -41,6 +41,26 @@ def process_environment_variables():
if "COMMAND_DEBUG" in os.environ.keys():
logging.disable(logging.NOTSET)

if "FLAVOUR" in os.environ.keys():
parameters["Command flavour"] = os.environ["FLAVOUR"].lower()
if "COMMAND_FLAVOUR" in os.environ.keys():
parameters["Command flavour"] = os.environ["COMMAND_FLAVOUR"].lower()

# From "man environ":
# POSIXLY_CORRECT
# When set to any value, this environment variable
# modifies the behaviour of certain commands to (mostly)
# execute in a strictly POSIX-compliant manner.
if "POSIXLY_CORRECT" in os.environ.keys():
parameters["Command flavour"] = "posix"

# Command variants supported:
if parameters["Command flavour"] not in (
"bsd", "bsd:freebsd",
):
logging.critical("Unimplemented command FLAVOUR: %s", parameters["Command flavour"])
sys.exit(1)

logging.debug("process_environment_variables(): parameters:")
logging.debug(parameters)

Expand Down Expand Up @@ -95,17 +115,21 @@ def process_command_line():
def main():
"""The program's main entry point"""
program_name = os.path.basename(sys.argv[0])

console_log_format = program_name + ": %(levelname)s: %(message)s"
logging.basicConfig(format=console_log_format, level=logging.DEBUG)
logging.disable(logging.INFO)

exit_status = 0

process_environment_variables()
arguments = process_command_line()

for argument in arguments:
# Do something
pass

sys.exit(0)
sys.exit(exit_status)


if __name__ == "__main__":
Expand Down

0 comments on commit a16693f

Please sign in to comment.