Skip to content

Commit ec90252

Browse files
committed
Implement methods for 'with' in python
1 parent bf02dfc commit ec90252

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

lldb/bindings/interface/SBProgressExtensions.i

Whitespace-only changes.

lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ def get_short_help(self):
6767
def get_long_help(self):
6868
return self.help_string
6969

70+
def __get__progress(self, debugger, total):
71+
if total is None:
72+
progress = lldb.SBProgress(
73+
"Progress tester", "Initial Indeterminate Detail", debugger
74+
)
75+
else:
76+
progress = lldb.SBProgress(
77+
"Progress tester", "Initial Detail", total, debugger
78+
)
79+
7080
def __init__(self, debugger, unused):
7181
self.parser = self.create_options()
7282
self.help_string = self.parser.format_help()
@@ -80,26 +90,18 @@ def __call__(self, debugger, command, exe_ctx, result):
8090
return
8191

8292
total = cmd_options.total
83-
if total is None:
84-
progress = lldb.SBProgress(
85-
"Progress tester", "Initial Indeterminate Detail", debugger
86-
)
87-
else:
88-
progress = lldb.SBProgress(
89-
"Progress tester", "Initial Detail", total, debugger
90-
)
91-
9293
# Check to see if total is set to None to indicate an indeterminate progress
9394
# then default to 10 steps.
94-
if total is None:
95-
total = 10
96-
97-
for i in range(1, total):
98-
if cmd_options.no_details:
99-
progress.Increment(1)
100-
else:
101-
progress.Increment(1, f"Step {i}")
102-
time.sleep(cmd_options.seconds)
95+
with self.__get_progress(debugger, total) as progress:
96+
if total is None:
97+
total = 10
98+
99+
for i in range(1, total):
100+
if cmd_options.no_details:
101+
progress.Increment(1)
102+
else:
103+
progress.Increment(1, f"Step {i}")
104+
time.sleep(cmd_options.seconds)
103105

104106
# Not required for deterministic progress, but required for indeterminate progress.
105107
progress.Finalize()

0 commit comments

Comments
 (0)