Allow initializing specific database tables

This commit is contained in:
XANTRONIX 2025-02-25 16:09:39 -05:00
parent 8acce6d76a
commit 60f5093c63
3 changed files with 20 additions and 15 deletions

View file

@ -23,8 +23,8 @@ RUN sqlite3 -init /tmp/xmet.sql /var/lib/xmet/xmet.db .quit
RUN /var/opt/xmet/bin/xmet-db-init \
/var/lib/xmet/xmet.db \
/tmp/radars.tsv \
/tmp/wfo.tsv \
/tmp/igra2-station-list.txt
--radars-tsv /tmp/radars.tsv \
--wfo-tsv /tmp/wfo.tsv \
--igra-stations /tmp/igra2-station-list.txt
ENTRYPOINT ["/var/opt/xmet/bin/xmet-nexrad-archive", "/var/lib/xmet/xmet.db"]

View file

@ -9,7 +9,6 @@ DB_INIT = ./bin/xmet-db-init
DB_INIT_RADARS = doc/radars.tsv
DB_INIT_WFO = doc/wfo.tsv
DB_INIT_IGRA = doc/igra2-station-list.txt
DB_INIT_FILES = $(DB_INIT_RADARS) $(DB_INIT_WFO) $(DB_INIT_IGRA)
all:
$(DOCKER) image build --tag $(DOCKER_TAG) .
@ -17,7 +16,9 @@ all:
db-init:
$(RM) $(SQLITE_DB)
$(SQLITE) -init $(SQLITE_SCHEMA) $(SQLITE_DB) .quit
$(DB_INIT) $(SQLITE_DB) $(DB_INIT_FILES)
$(DB_INIT) $(SQLITE_DB) --radars-tsv $(DB_INIT_RADARS) \
--wfo-tsv $(DB_INIT_WFO) \
--igra-stations $(DB_INIT_IGRA)
clean:
$(DOCKER) rmi $(DOCKER_TAG)

View file

@ -12,9 +12,10 @@ parser = argparse.ArgumentParser(
)
parser.add_argument('db', help='Path to SQLite3 database')
parser.add_argument('radars-tsv', help='Path to NEXRAD radar station TSV file')
parser.add_argument('wfo-tsv', help='Path to forecast office TSV file')
parser.add_argument('igra-stations', help='Path to IGRA station list')
parser.add_argument('--radars-tsv', type=str, help='Path to NEXRAD radar station TSV file')
parser.add_argument('--wfo-tsv', type=str, help='Path to forecast office TSV file')
parser.add_argument('--igra-stations', type=str, help='Path to IGRA station list')
args = parser.parse_args()
@ -22,13 +23,16 @@ db = Database.connect(args.db)
db.execute('begin transaction')
for radar in Radar.each_from_tsv(getattr(args, 'radars-tsv')):
if args.radars_tsv is not None:
for radar in Radar.each_from_tsv(args.radars_tsv):
db.add(radar)
for wfo in WFO.each_from_tsv(getattr(args, 'wfo-tsv')):
if args.wfo_tsv is not None:
for wfo in WFO.each_from_tsv(args.wfo_tsv):
db.add(wfo)
for station in IGRAStation.each_from_file(getattr(args, 'igra-stations')):
if args.igra_stations is not None:
for station in IGRAStation.each_from_file(args.igra_stations):
db.add(station)
db.commit()