-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command
run
to run a user-defined command on each event
- Loading branch information
1 parent
227a546
commit 8ae6ace
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ Copyright (c) 2022-2024 Claudio Satriano <[email protected]> | |
a local SDS archive | ||
- New option for `seiscat initdb` and `seiscat updatedb`: `--fromfile` to | ||
initialize or update the database from a CSV file | ||
- New command `seiscat run` to run a user-defined command on each event | ||
|
||
## v0.8 - 2024-10-28 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf8 -*- | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
""" | ||
Run a user-defined command on a list of events. | ||
:copyright: | ||
2022-2024 Claudio Satriano <[email protected]> | ||
:license: | ||
GNU General Public License v3.0 or later | ||
(https://www.gnu.org/licenses/gpl-3.0-standalone.html) | ||
""" | ||
import os | ||
import subprocess | ||
from .database.dbfunctions import read_events_from_db | ||
from .utils import ExceptionExit | ||
|
||
|
||
def run_command(config): | ||
""" | ||
Run a user-defined command on a list of events. | ||
:param config: config object | ||
:type config: dict | ||
""" | ||
args = config['args'] | ||
command = args.command | ||
with ExceptionExit(): | ||
events = read_events_from_db(config) | ||
for event in events: | ||
print(f'Running {command} on event {event["evid"]}') | ||
event_str = {k: str(v) for k, v in event.items()} | ||
env = {**os.environ, **event_str} | ||
try: | ||
subprocess.run(command, shell=True, env=env, check=True) | ||
except subprocess.CalledProcessError as e: | ||
print(f'Command {command} failed with exit status {e.returncode}') |