Skip to content

Commit 97a92b2

Browse files
authored
Fix a couple of bytes vs str issues in usagestats.py from subprocess output on python3. (#289)
Simply reuse the `force_native_str` fix on the subprocess output.
2 parents 79fef0b + 671b67d commit 97a92b2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mig/server/usagestats.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# usagestats - Collect and report various central usage stats for the site
7-
# Copyright (C) 2020-2021 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
88
#
99
# This file is part of MiG.
1010
#
@@ -35,7 +35,7 @@
3535
import sys
3636
import time
3737

38-
from mig.shared.base import extract_field
38+
from mig.shared.base import extract_field, force_native_str
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
@@ -297,7 +297,8 @@ def write_sitestats(configuration, stats, path_prefix, output_format):
297297
env=cmd_env)
298298
proc.wait()
299299
for line in proc.stdout.readlines():
300-
site_stats['disk']['use'].append(line.strip().split())
300+
# NOTE: output is system native encoding and we need native string
301+
site_stats['disk']['use'].append(force_native_str(line.strip()).split())
301302
if verbose:
302303
print("=== Disk Use ===")
303304
print('\n'.join(['\t'.join(i) for i in site_stats['disk']['use']]))
@@ -308,7 +309,8 @@ def write_sitestats(configuration, stats, path_prefix, output_format):
308309
proc = subprocess_popen(['mount'] + mount_opts, stdout=subprocess_pipe)
309310
proc.wait()
310311
for line in proc.stdout.readlines():
311-
site_stats['disk']['mounts'].append(line.strip().split())
312+
# NOTE: output is system native encoding and we need native string
313+
site_stats['disk']['mounts'].append(force_native_str(line.strip()).split())
312314
if verbose:
313315
print("=== Disk Mounts ===")
314316
print('\n'.join(['\t'.join(i) for i in site_stats['disk']['mounts']]))

0 commit comments

Comments
 (0)