Skip to content

Commit

Permalink
--leave-server option, refs #156, #157
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 27, 2024
1 parent 8a1d3fa commit d276283
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions shot_scraper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ def _browser_context(
@skip_fail_options
@silent_option
@http_auth_options
@click.option(
"leave_server",
"--leave-server",
is_flag=True,
help="Leave servers running when script finishes",
)
def multi(
config,
auth,
Expand All @@ -496,6 +502,7 @@ def multi(
silent,
auth_username,
auth_password,
leave_server,
):
"""
Take multiple screenshots, defined by a YAML file
Expand Down Expand Up @@ -559,12 +566,14 @@ def multi(
if "server" in shot:
# Start that subprocess and remember the pid
server = shot["server"]
proc = None
if isinstance(server, str):
server_processes.append(subprocess.Popen(server, shell=True))
proc = subprocess.Popen(server, shell=True)
elif isinstance(server, list):
server_processes.append(subprocess.Popen(map(str, server)))
proc = subprocess.Popen(map(str, server))
else:
raise click.ClickException("server: must be a string or list")
server_processes.append((proc, server))
time.sleep(1)
if "url" in shot:
try:
Expand All @@ -583,10 +592,15 @@ def multi(
click.echo(str(e), err=True)
continue
finally:
context.close()
browser_obj.close()
if server_processes:
for process in server_processes:
process.kill()
if leave_server:
for process, details in server_processes:
print("Leaving server PID:", process.pid, " details:", details)
else:
if server_processes:
for process, _ in server_processes:
process.kill()


@cli.command()
Expand Down

0 comments on commit d276283

Please sign in to comment.