Fix --dry-run to not touch database at all

This commit is contained in:
XANTRONIX 2025-03-02 17:07:24 -05:00
parent 3a8f5ae850
commit fb078eb7c4
2 changed files with 15 additions and 9 deletions

View file

@ -18,6 +18,8 @@ parser.add_argument('igra-sounding-file', nargs='+', help='IGRA sounding file')
args = parser.parse_args()
db = Database.connect(args.db)
if not args.dry_run:
db.execute('begin transaction')
for path in getattr(args, 'igra-sounding-file'):
@ -34,4 +36,5 @@ for path in getattr(args, 'igra-sounding-file'):
sample.sounding_id = sounding.id
db.add(sample)
if not args.dry_run:
db.commit()

View file

@ -3,28 +3,30 @@
import argparse
from xmet.db import Database
from xmet.igra import IGRAReader
from xmet.raob import RAOBReader
parser = argparse.ArgumentParser(
description = 'Ingest IGRA soundings'
description = 'Ingest RAOB soundings'
)
parser.add_argument('--quiet', action='store_true', help='Suppress output')
parser.add_argument('--dry-run', action='store_true', help='Do not actually ingest data')
parser.add_argument('db', help='XMET SQLite3 database')
parser.add_argument('igra-sounding-file', nargs='+', help='IGRA sounding file')
parser.add_argument('raob-sounding-file', nargs='+', help='RAOB sounding file')
args = parser.parse_args()
db = Database.connect(args.db)
if not args.dry_run:
db.execute('begin transaction')
for path in getattr(args, 'igra-sounding-file'):
for path in getattr(args, 'raob-sounding-file'):
if not args.quiet:
print(f"Ingesting sounding file {path}")
for sounding in IGRAReader.each_sounding_from_file(path):
for sounding in RAOBReader.each_sounding_from_file(path):
if args.dry_run:
continue
@ -34,4 +36,5 @@ for path in getattr(args, 'igra-sounding-file'):
sample.sounding_id = sounding.id
db.add(sample)
if not args.dry_run:
db.commit()