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