1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
Most of https://github.com/clarkbox/check_multiple/pull/2, without the
version bump or changed to README.md. Waited as long as I could, but
we need this for python-3.14.
diff --git a/bin/check_multiple b/bin/check_multiple
deleted file mode 100755
index e43a800..0000000
--- a/bin/check_multiple
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/python3
-import argparse
-import sys
-
-from check_multiple.check_multiple import (MODE_BEST,
- MODE_WORST,
- process_results,
- run_commands)
-
-
-parser = argparse.ArgumentParser(
- description='Run multiple Nagios checks and combine the results.')
-parser.add_argument(
- "--mode",
- default='worst',
- choices=['worst', 'best'],
- help="which individual check result should be the overall result; "
- "either the \"worst\" one or the \"best\" one (default: worst)")
-parser.add_argument(
- "command",
- nargs="+",
- help="check to run, enclosed in quotes")
-
-args = parser.parse_args()
-mode = MODE_WORST
-if args.mode == "best":
- mode = MODE_BEST
-exitcode,output = process_results(run_commands(args.command), mode)
-print(output)
-sys.exit(exitcode)
diff --git a/lib/check_multiple/__main__.py b/lib/check_multiple/__main__.py
new file mode 100644
index 0000000..f2ae908
--- /dev/null
+++ b/lib/check_multiple/__main__.py
@@ -0,0 +1,40 @@
+import sys
+
+def main():
+ import argparse
+
+ from check_multiple.check_multiple import (
+ MODE_BEST,
+ MODE_WORST,
+ process_results,
+ run_commands
+ )
+
+
+ parser = argparse.ArgumentParser(
+ description='Run multiple Nagios checks and combine the results.'
+ )
+ parser.add_argument(
+ "--mode",
+ default='worst',
+ choices=['worst', 'best'],
+ help="which individual check result should be the overall result; "
+ "either the \"worst\" one or the \"best\" one (default: worst)"
+ )
+ parser.add_argument(
+ "command",
+ nargs="+",
+ help="check to run, enclosed in quotes"
+ )
+
+ args = parser.parse_args()
+ mode = MODE_WORST
+ if args.mode == "best":
+ mode = MODE_BEST
+ exitcode,output = process_results(run_commands(args.command), mode)
+ print(output)
+ return exitcode
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/lib/check_multiple/check_multiple.py b/lib/check_multiple/check_multiple.py
index 7670690..e27401e 100644
--- a/lib/check_multiple/check_multiple.py
+++ b/lib/check_multiple/check_multiple.py
@@ -55,15 +55,7 @@ def run_command(c):
Returns a single CompletedProcess instance.
"""
- # The "capture_output=True" keyword argument that we would like to
- # pass to run() doesn't exist before python-3.7. Likewise, the
- # "universal_newlines" argument has been renamed to "text", but
- # only in python 3.7.
- return subprocess.run(c,
- shell=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- universal_newlines=True)
+ return subprocess.run(c, shell=True, capture_output=True, text=True)
def run_commands(command_list):
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..a6d4d0b
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,30 @@
+[build-system]
+requires = ["setuptools >= 61.0"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "nagios-check_multiple"
+version = "0.0.1"
+description = "Run multiple Nagios checks and combine the results"
+requires-python = ">=3.9"
+license = "MIT"
+classifiers = [
+ 'Environment :: Console',
+ 'Intended Audience :: System Administrators'
+]
+
+[project.readme]
+content-type = "text/markdown"
+file = "README.md"
+
+[project.scripts]
+check_multiple = "check_multiple.__main__:main"
+
+[project.urls]
+Homepage = "https://github.com/clarkbox/check_multiple"
+Documentation = "https://github.com/clarkbox/check_multiple/blob/master/README.md"
+Repository = "https://github.com/clarkbox/check_multiple.git"
+Issues = "https://github.com/clarkbox/check_multiple/issues"
+
+[tool.setuptools.packages.find]
+where = ["lib"]
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 8034e65..0000000
--- a/setup.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from distutils.core import setup
-
-setup(
- name = 'nagios-check_multiple',
- version = '0.0.1',
- maintainer = 'Clark A',
- maintainer_email = 'clarka@gmail.com',
- url = 'https://github.com/clarkbox/check_multiple',
- scripts = ['bin/check_multiple'],
- packages = ['check_multiple'],
- package_dir = {'check_multiple': 'lib/check_multiple'},
- description = 'Run multiple Nagios checks and combine the results',
- long_description=open('README.md').read(),
- classifiers = [
- 'Programming Language :: Python :: 3.5',
- 'Programming Language :: Python :: 3.6',
- 'Programming Language :: Python :: 3.7',
- 'Programming Language :: Python :: 3.8',
- 'Environment :: Console',
- 'Intended Audience :: System Administrators',
- 'License :: OSI Approved :: MIT License',
- ]
-)
|