Skip to content

Commit 69e0720

Browse files
committed
refactor: Replace deprecated module optparse with optparse, code cleanup, closes #206
1 parent 8c65661 commit 69e0720

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

examples/slurm_node_xml.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Display Slurm node information in XML
44
"""
55

6+
import argparse
67
import os
78
import os.path
89
import pwd
910
import re
1011
import socket
1112
import sys
1213
import time
13-
from optparse import OptionParser
1414

1515
import pyslurm
1616

@@ -89,37 +89,34 @@ def meminfo():
8989

9090
if __name__ == "__main__":
9191

92-
USAGE = "Usage: %prog [options] arg"
93-
parser = OptionParser(USAGE)
94-
95-
parser.add_option(
92+
parser = argparse.ArgumentParser(description="Slurm Node XML Output")
93+
parser.add_argument(
9694
"-o",
9795
"--stdout",
9896
dest="output",
9997
action="store_true",
10098
default=False,
10199
help="Write to standard output",
102100
)
103-
parser.add_option(
101+
parser.add_argument(
104102
"-d",
105103
"--dir",
106104
dest="directory",
107105
action="store",
108-
default=os.getcwd(),
106+
default=os.getcwd,
109107
help="Directory to write data to",
110108
)
111-
parser.add_option(
109+
parser.add_argument(
112110
"-r",
113111
"--rrd",
114112
dest="rrd",
115-
default=False,
116113
action="store_true",
114+
default=False,
117115
help="Write rrd data",
118116
)
117+
options = parser.parse_args()
119118

120-
(options, args) = parser.parse_args()
121-
122-
hosts = socket.gethostbyaddr(socket.gethostname())[1]
119+
hosts = socket.gethostbyaddr(socket.gethostname())
123120
my_host = hosts[0]
124121

125122
LOCK_FILE = "/var/tmp/slurm_node_xml.lck"
@@ -162,7 +159,7 @@ def meminfo():
162159
sys.stdout.write("\t<slurmd>\n")
163160
for key, value in data.items():
164161
sys.stdout.write(f"\t\t<{key}>{value}</{key}>\n")
165-
sys.stdout.write("\t</slurmd>\n")
162+
sys.stdout.write("\t</slurmd>\n")
166163

167164
a = pyslurm.job()
168165
jobs = a.get()

0 commit comments

Comments
 (0)