# or func_output().
#
-import StringIO
-import commands
+from io import BytesIO
import fcntl
import getopt
import hashlib
import zipfile
from select import select
from signal import SIGTERM
-from subprocess import PIPE, Popen
+from subprocess import PIPE, Popen, check_output
from xml.dom.minidom import getDOMImplementation, parse
cap = v['cap']
if 'cmd_args' in v:
if 'output' not in v.keys():
- v['output'] = StringIOmtime()
+ v['output'] = BytesIOmtime()
if v['repeat_count'] > 0:
if cap not in process_lists:
process_lists[cap] = []
if 'filename' in v and v['filename'].startswith('/proc/'):
# proc files must be read into memory
try:
- f = open(v['filename'], 'r')
+ f = open(v['filename'], 'rb')
s = f.read()
f.close()
if check_space(cap, v['filename'], len(s)):
- v['output'] = StringIOmtime(s)
+ v['output'] = BytesIOmtime(s)
except:
pass
elif 'func' in v:
try:
s = v['func'](cap)
except Exception as e:
- s = str(e)
+ s = str(e).encode()
if check_space(cap, k, len(s)):
- v['output'] = StringIOmtime(s)
+ if isinstance(s, str):
+ v['output'] = BytesIOmtime(s.encode())
+ else:
+ v['output'] = BytesIOmtime(s)
def main(argv=None):
# permit the user to filter out data
# We cannot use iteritems, since we modify 'data' as we pass through
- for (k, v) in sorted(data.items()):
+ for (k, v) in data.items():
cap = v['cap']
if 'filename' in v:
key = k[0]
# include inventory
data['inventory.xml'] = {'cap': None,
- 'output': StringIOmtime(make_inventory(data, subdir))}
+ 'output': BytesIOmtime(make_inventory(data, subdir))}
# create archive
if output_fd == -1:
def module_info(cap):
- output = StringIO.StringIO()
+ output = BytesIO()
modules = open(PROC_MODULES, 'r')
procs = []
def dp_list():
- output = StringIO.StringIO()
+ output = BytesIO()
procs = [ProcOutput([OVS_DPCTL, 'dump-dps'],
caps[CAP_NETWORK_STATUS][MAX_TIME], output)]
if os.path.isfile(OPENVSWITCH_COMPACT_DB):
os.unlink(OPENVSWITCH_COMPACT_DB)
- output = StringIO.StringIO()
+ output = BytesIO()
max_time = 5
procs = [ProcOutput(['ovsdb-tool', 'compact',
OPENVSWITCH_CONF_DB, OPENVSWITCH_COMPACT_DB],
def dump_rdac_groups(cap):
- output = StringIO.StringIO()
+ output = BytesIO()
procs = [ProcOutput([MPPUTIL, '-a'], caps[cap][MAX_TIME], output)]
run_procs([procs])
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc += node.data
- return rc.encode()
+ return rc
def getBoolAttr(el, attr, default=False):
ret = default
s = os.stat(v['filename'])
ti.mtime = s.st_mtime
ti.size = s.st_size
- tf.addfile(ti, open(v['filename']))
+ tf.addfile(ti, open(v['filename'], 'rb'))
except:
pass
finally:
s.setAttribute('date', time.strftime('%c'))
s.setAttribute('hostname', platform.node())
s.setAttribute('uname', ' '.join(platform.uname()))
- s.setAttribute('uptime', commands.getoutput(UPTIME))
+ s.setAttribute('uptime', check_output(UPTIME).decode())
document.getElementsByTagName(INVENTORY_XML_ROOT)[0].appendChild(s)
map(lambda k_v: inventory_entry(document, subdir, k_v[0], k_v[1]),
inventory.items())
- return document.toprettyxml()
+ return document.toprettyxml().encode()
def inventory_entry(document, subdir, k, v):
line = self.proc.stdout.readline()
else:
line = self.proc.stdout.read(self.bufsize)
- if line == '':
+ if line == b'':
# process exited
self.proc.stdout.close()
self.status = self.proc.wait()
return s.f_frsize * s.f_bfree
-class StringIOmtime(StringIO.StringIO):
- def __init__(self, buf=''):
- StringIO.StringIO.__init__(self, buf)
+class BytesIOmtime(BytesIO):
+ def __init__(self, buf=b''):
+ BytesIO.__init__(self, buf)
self.mtime = time.time()
def write(self, s):
- StringIO.StringIO.write(self, s)
+ BytesIO.write(self, s)
self.mtime = time.time()