Skip to content

Commit 7ec746c

Browse files
authored
Rework fix from PR289 to use new text arg instead (#294)
Adjust subprocess calls to use new `text` arg in `usagestats.py`.
2 parents c9112bf + b5053f8 commit 7ec746c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mig/server/usagestats.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import sys
3636
import time
3737

38-
from mig.shared.base import extract_field, force_native_str
38+
from mig.shared.base import extract_field
3939
from mig.shared.defaults import freeze_meta_filename, keyword_auto
4040
from mig.shared.fileio import unpickle, walk
4141
from mig.shared.notification import send_email
@@ -293,24 +293,25 @@ def write_sitestats(configuration, stats, path_prefix, output_format):
293293
# NOTE: df expects multiple file system types as individual options
294294
for fs_type in only_fs_types:
295295
df_opts += ['-t', fs_type]
296+
# NOTE: we want utf8-encoded output as text str for concat below
296297
proc = subprocess_popen(['/bin/df'] + df_opts, stdout=subprocess_pipe,
297-
env=cmd_env)
298+
text=True, env=cmd_env)
298299
proc.wait()
299300
for line in proc.stdout.readlines():
300-
# NOTE: output is system native encoding and we need native string
301-
site_stats['disk']['use'].append(force_native_str(line.strip()).split())
301+
site_stats['disk']['use'].append(line.strip().split())
302302
if verbose:
303303
print("=== Disk Use ===")
304304
print('\n'.join(['\t'.join(i) for i in site_stats['disk']['use']]))
305305

306306
# NOTE: mount expects multiple file system types as single comma-sep arg
307307
mount_opts = []
308308
mount_opts += ['-t', ','.join(only_fs_types)]
309-
proc = subprocess_popen(['mount'] + mount_opts, stdout=subprocess_pipe)
309+
# NOTE: we want utf8-encoded output as text str for concat below
310+
proc = subprocess_popen(['mount'] + mount_opts, stdout=subprocess_pipe,
311+
text=True)
310312
proc.wait()
311313
for line in proc.stdout.readlines():
312-
# NOTE: output is system native encoding and we need native string
313-
site_stats['disk']['mounts'].append(force_native_str(line.strip()).split())
314+
site_stats['disk']['mounts'].append(line.strip().split())
314315
if verbose:
315316
print("=== Disk Mounts ===")
316317
print('\n'.join(['\t'.join(i) for i in site_stats['disk']['mounts']]))

0 commit comments

Comments
 (0)