Skip to content

Commit 83155c0

Browse files
committed
Disable progress bars when not in a TTY
1 parent b9aaf1b commit 83155c0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

beets/ui/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ def add_all_common_options(self):
13371337

13381338

13391339
M = library.Album | library.Item | Any
1340+
1341+
13401342
def iprogress_bar(sequence: Sequence[M], **kwargs) -> Generator[M, None, None]:
13411343
"""Construct and manage an `enlighten.Counter` progress bar while iterating.
13421344
@@ -1371,14 +1373,18 @@ def iprogress_bar(sequence: Sequence[M], **kwargs) -> Generator[M, None, None]:
13711373
if "total" not in kwargs and hasattr(sequence, "__len__"):
13721374
kwargs["total"] = len(sequence)
13731375

1374-
# Disabled in windows environments. See above for details
1375-
with enlighten.Manager(enabled=not is_windows) as manager:
1376+
# Disabled in windows environments and when not attached to a TTY. See method docs
1377+
# for details.
1378+
with enlighten.Manager(
1379+
enabled=not is_windows
1380+
and (hasattr(sys.stdout, "isatty") and sys.stdout.isatty())
1381+
) as manager:
13761382
with manager.counter(**kwargs) as counter:
13771383
change_counter = counter.add_subcounter("blue")
13781384

13791385
for item in sequence:
13801386
revision = None
1381-
if hasattr(item, '_revision'):
1387+
if hasattr(item, "_revision"):
13821388
revision = item._revision
13831389

13841390
# Yield the item, allowing it to be modified, or not.

beetsplug/permissions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ def set_permissions(self, files=[], dirs=[]):
103103

104104
# Change permissions for the files.
105105
for path in ui.iprogress_bar(
106-
files,
107-
desc="Setting permissions",
108-
unit="files"):
106+
files, desc="Setting permissions", unit="files"
107+
):
109108
# Changing permissions on the destination file.
110109
self._log.debug(
111110
"setting file permissions on {}",
@@ -119,9 +118,8 @@ def set_permissions(self, files=[], dirs=[]):
119118

120119
# Change permissions for the directories.
121120
for dir in ui.iprogress_bar(
122-
dirs,
123-
desc="Setting permissions",
124-
unit="directories"):
121+
dirs, desc="Setting permissions", unit="directories"
122+
):
125123
# Changing permissions on the destination directory.
126124
self._log.debug(
127125
"setting directory permissions on {}",

0 commit comments

Comments
 (0)