Skip to content

Commit 166e05a

Browse files
committed
NV-CONTROL: small code refactoring
1 parent 7753247 commit 166e05a

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

‎Xlib/ext/nvcontrol.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def get_gpu_utilization(self, target):
140140
result = {}
141141
if string is not None and string != '':
142142
for line in string.split(','):
143-
key_value = line.split('=')
144-
result[key_value[0].strip()] = int(key_value[1]) if key_value[1].isdigit else key_value[1]
143+
[key, value] = line.split('=')[:2]
144+
result[key.strip()] = int(value) if value.isdigit() else value
145145
return result
146146

147147

@@ -152,8 +152,8 @@ def get_performance_modes(self, target):
152152
for perf in string.split(';'):
153153
perf_dict = {}
154154
for line in perf.split(','):
155-
key_value = line.split('=')
156-
perf_dict[key_value[0].strip()] = int(key_value[1]) if key_value[1].isdigit else key_value[1]
155+
[key, value] = line.split('=')[:2]
156+
perf_dict[key.strip()] = int(value) if value.isdigit() else value
157157
result.append(perf_dict)
158158
return result
159159

@@ -288,11 +288,11 @@ def get_fan_rpm(self, target):
288288

289289

290290
def get_max_displays(self, target):
291-
"""return the maximum number of display devices that can be driven
292-
simultaneously on a GPU (e.g., that can be used in a MetaMode at once).
293-
Note that this does not indicate the maximum number of bits that can be
294-
set in NV_CTRL_CONNECTED_DISPLAYS, because more display devices can be
295-
connected than are actively in use."""
291+
"""return the maximum number of display devices that can be driven simultaneously on a GPU.
292+
293+
Note that this does not indicate the maximum number of bits that can be set in
294+
NV_CTRL_CONNECTED_DISPLAYS, because more display devices can be connected than are actively
295+
in use."""
296296
return query_int_attribute(self, target, 0, NV_CTRL_MAX_DISPLAYS)
297297

298298

@@ -5159,7 +5159,7 @@ def type(self):
51595159
return self._type
51605160

51615161
def __str__(self):
5162-
return '<nVidia %s #%d>' % (self._name, self.id())
5162+
return '<nVidia {} #{}>'.format(self._name, self.id())
51635163

51645164

51655165
class Gpu(Target):

‎examples/nvcontrol.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
display = Display()
4141
# Check for extension
4242
if not display.has_extension('NV-CONTROL'):
43-
sys.stderr.write('%s: server does not have the NV-CONTROL extension\n'
44-
% sys.argv[0])
45-
print(display.query_extension('NV-CONTROL'))
43+
sys.stderr.write('{}: server does not have the NV-CONTROL extension\n'.format(sys.argv[0]))
44+
ext = display.query_extension('NV-CONTROL')
45+
print(ext)
4646
sys.stderr.write("\n".join(display.list_extensions()))
47-
if display.query_extension('NV-CONTROL') is None:
47+
if ext is None:
4848
sys.exit(1)
4949

5050
gpu = Gpu(0)

‎examples/xinerama.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def __init__(self, display):
4242

4343
# Check for extension
4444
if not self.d.has_extension('XINERAMA'):
45-
sys.stderr.write('%s: server does not have the XINERAMA extension\n'
46-
% sys.argv[0])
47-
print(self.d.query_extension('XINERAMA'))
45+
sys.stderr.write('{}: server does not have the XINERAMA extension\n'.format(sys.argv[0]))
46+
ext = self.d.query_extension('XINERAMA')
47+
print(ext)
4848
sys.stderr.write("\n".join(self.d.list_extensions()))
49-
if self.d.query_extension('XINERAMA') is None:
49+
if ext is None:
5050
sys.exit(1)
5151

5252
# print version

‎examples/xrandr.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def __init__(self, display):
4242

4343
# Check for extension
4444
if not self.d.has_extension('RANDR'):
45-
sys.stderr.write('%s: server does not have the RANDR extension\n'
46-
% sys.argv[0])
47-
print(self.d.query_extension('RANDR'))
45+
sys.stderr.write('{}: server does not have the RANDR extension\n'.format(sys.argv[0]))
46+
ext = self.d.query_extension('RANDR')
47+
print(ext)
4848
sys.stderr.write("\n".join(self.d.list_extensions()))
49-
if self.d.query_extension('RANDR') is None:
49+
if ext is None:
5050
sys.exit(1)
5151

5252
# print(version)

0 commit comments

Comments
 (0)