Fix --dry-run to not touch database at all
This commit is contained in:
parent
3a8f5ae850
commit
fb078eb7c4
2 changed files with 15 additions and 9 deletions
|
@ -18,7 +18,9 @@ parser.add_argument('igra-sounding-file', nargs='+', help='IGRA sounding file')
|
|||
args = parser.parse_args()
|
||||
|
||||
db = Database.connect(args.db)
|
||||
db.execute('begin transaction')
|
||||
|
||||
if not args.dry_run:
|
||||
db.execute('begin transaction')
|
||||
|
||||
for path in getattr(args, 'igra-sounding-file'):
|
||||
if not args.quiet:
|
||||
|
@ -34,4 +36,5 @@ for path in getattr(args, 'igra-sounding-file'):
|
|||
sample.sounding_id = sounding.id
|
||||
db.add(sample)
|
||||
|
||||
db.commit()
|
||||
if not args.dry_run:
|
||||
db.commit()
|
||||
|
|
|
@ -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)
|
||||
db.execute('begin transaction')
|
||||
|
||||
for path in getattr(args, 'igra-sounding-file'):
|
||||
if not args.dry_run:
|
||||
db.execute('begin transaction')
|
||||
|
||||
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)
|
||||
|
||||
db.commit()
|
||||
if not args.dry_run:
|
||||
db.commit()
|
||||
|
|
Loading…
Add table
Reference in a new issue