From a16693f0c514435d05e73bdf6b25686349d55534 Mon Sep 17 00:00:00 2001 From: Hubert Tournier Date: Wed, 25 Aug 2021 11:44:25 +0200 Subject: [PATCH] 2021.8.25 update --- _template/License | 2 +- _template/Makefile | 10 ++++++---- _template/README.md | 9 ++++++--- _template/man/COMMAND.1 | 12 +++++++----- _template/setup.cfg | 31 ++++++++++++++++++------------- _template/src/COMMAND/Makefile | 13 +++++++------ _template/src/COMMAND/main.py | 28 ++++++++++++++++++++++++++-- 7 files changed, 71 insertions(+), 34 deletions(-) diff --git a/_template/License b/_template/License index 6cb6d6d..8dabc6b 100644 --- a/_template/License +++ b/_template/License @@ -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: diff --git a/_template/Makefile b/_template/Makefile index 76005ff..68e09b2 100644 --- a/_template/Makefile +++ b/_template/Makefile @@ -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: @@ -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: @@ -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 + diff --git a/_template/README.md b/_template/README.md index bdba603..f372677 100644 --- a/_template/README.md +++ b/_template/README.md @@ -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) diff --git a/_template/man/COMMAND.1 b/_template/man/COMMAND.1 index fe09a83..72560c1 100644 --- a/_template/man/COMMAND.1 +++ b/_template/man/COMMAND.1 @@ -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 diff --git a/_template/setup.cfg b/_template/setup.cfg index 420119a..bb2ed77 100644 --- a/_template/setup.cfg +++ b/_template/setup.cfg @@ -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 @@ -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... diff --git a/_template/src/COMMAND/Makefile b/_template/src/COMMAND/Makefile index 89c94b9..60e5547 100644 --- a/_template/src/COMMAND/Makefile +++ b/_template/src/COMMAND/Makefile @@ -1,4 +1,5 @@ NAME=COMMAND +SECTION=1 SOURCES=main.py DESTROOTDIR=/usr/local @@ -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 @@ -60,7 +61,7 @@ love: @echo "Not war!" clean: - @rm -f ${NAME}.1.gz + @rm -f ${NAME}.${SECTION}.gz distclean: clean diff --git a/_template/src/COMMAND/main.py b/_template/src/COMMAND/main.py index 26908cd..18b1748 100644 --- a/_template/src/COMMAND/main.py +++ b/_template/src/COMMAND/main.py @@ -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", } @@ -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) @@ -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__":