Converted all string formatting to new style.
Austin S. Hemmelgarn committed
Jun 5, 2018 at 14:47 UTC
4f040de3c416acb1cb09feae4e355b0533b85aad
1 file changed
+18
-23
python.d/python_modules/third_party/boinc_client.py
+18
-23
@@ -82,8 +82,7 @@ class Rpc(object):
82
83
# pack request
84
end = '\003'
85
- req = "<boinc_gui_rpc_request>\n%s\n</boinc_gui_rpc_request>\n%s" \
86
- % (ElementTree.tostring(request).replace(' />','/>'), end)
85
+ req = "<boinc_gui_rpc_request>\n{0}\n</boinc_gui_rpc_request>\n{1}".format(ElementTree.tostring(request).replace(' />', '/>'), end)
86
87
try:
88
self.sock.sendall(req)
@@ -169,7 +168,7 @@ def parse_str(e):
168
169
170
def parse_list(e):
172
- ''' Helper to convert ElementTree.Element to list. For now, simply return
171
+ ''' Helper to convert ElementTree.Element to list. For now, simply return
172
the list of root element's children
173
'''
174
return list(e)
@@ -332,15 +331,15 @@ class _Struct(object):
331
return setattrs_from_xml(cls(), xml)
332
333
def __str__(self, indent=0):
335
- buf = '%s%s:\n' % ('\t' * indent, self.__class__.__name__)
334
+ buf = '{0}{1}:\n'.format('\t' * indent, self.__class__.__name__)
335
for attr in self.__dict__:
336
value = getattr(self, attr)
337
if isinstance(value, list):
339
- buf += '%s\t%s [\n' % ('\t' * indent, attr)
340
- for v in value: buf += '\t\t%s\t\t,\n' % v
338
+ buf += '{0}\t{1} [\n'.format('\t' * indent, attr)
339
+ for v in value: buf += '\t\t{0}\t\t,\n'.format(v)
340
buf += '\t]\n'
341
else:
343
- buf += '%s\t%s\t%s\n' % ('\t' * indent,
342
+ buf += '{0}\t{1}\t{2}\n'.format('\t' * indent,
343
attr,
344
value.__str__(indent+2)
345
if isinstance(value, _Struct)
@@ -371,10 +370,10 @@ class VersionInfo(_Struct):
370
return self._tuple > other._tuple
371
372
def __str__(self):
374
- return "%d.%d.%d" % (self.major, self.minor, self.release)
373
+ return "{0}.{1}.{2}".format(self.major, self.minor, self.release)
374
375
def __repr__(self):
377
- return "%s%r" % (self.__class__.__name__, self._tuple)
376
+ return "{0}{1}".format(self.__class__.__name__, self._tuple)
377
378
379
class CcStatus(_Struct):
@@ -598,12 +597,12 @@ class Result(_Struct):
597
return result
598
599
def __str__(self):
601
- buf = '%s:\n' % self.__class__.__name__
600
+ buf = '{0}:\n'.format(self.__class__.__name__)
601
for attr in self.__dict__:
602
value = getattr(self, attr)
603
if attr in ['received_time', 'report_deadline']:
604
value = time.ctime(value)
606
- buf += '\t%s\t%r\n' % (attr, value)
605
+ buf += '\t{0}\t{1}\n'.format(attr, value)
606
return buf
607
608
@@ -651,8 +650,8 @@ class BoincClient(object):
650
if password is None and not self.hostname:
651
password = read_gui_rpc_password() or ""
652
nonce = self.rpc.call('<auth1/>').text
654
- hash = hashlib.md5('%s%s' % (nonce, password)).hexdigest().lower()
655
- reply = self.rpc.call('<auth2><nonce_hash>%s</nonce_hash></auth2>' % hash)
653
+ authhash = hashlib.md5('{0}{1}'.format(nonce, password).encode()).hexdigest().lower()
654
+ reply = self.rpc.call('<auth2><nonce_hash>{0}</nonce_hash></auth2>'.format(authhash))
655
656
if reply.tag == 'authorized':
657
return True
@@ -688,8 +687,7 @@ class BoincClient(object):
687
Use CC_STATE::lookup_result() to find this result in the current static state;
688
if it's not there, call get_state() again.
689
'''
691
- reply = self.rpc.call("<get_results><active_only>%d</active_only></get_results>"
692
- % (1 if active_only else 0))
690
+ reply = self.rpc.call("<get_results><active_only>{0}</active_only></get_results>".format(1 if active_only else 0))
691
if not reply.tag == 'results':
692
return []
693
@@ -704,15 +702,12 @@ class BoincClient(object):
702
This method is not part of the original API.
703
Valid components are 'run' (or 'cpu'), 'gpu', 'network' (or 'net')
704
'''
707
- component = component.replace('cpu','run')
708
- component = component.replace('net','network')
705
+ component = component.replace('cpu', 'run')
706
+ component = component.replace('net', 'network')
707
try:
710
- reply = self.rpc.call("<set_%s_mode>"
711
- "<%s/><duration>%f</duration>"
712
- "</set_%s_mode>"
713
- % (component,
714
- RunMode.name(mode).lower(), duration,
715
- component))
708
+ reply = self.rpc.call("<set_{0}_mode>"
709
+ "<{1}/><duration>{2]</duration>"
710
+ "</set_{0}_mode>".format(component, RunMode.name(mode).lower(), duration))
711
return (reply.tag == 'success')
712
except socket.error:
713
return False