-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #213 initial commit of script and config files
- Loading branch information
Showing
3 changed files
with
166 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
# Configuration file used to load MET ASCII data into | ||
# a database. | ||
|
||
dbname: mv_test | ||
username: mvadmin | ||
password: 160GiltVa0D5M | ||
host: localhost | ||
port: 3306 | ||
|
||
# Location (full path and schema file) to the sql schema. Replace with the location | ||
# of your METdataio source code. | ||
schema_location: /d2/personal/mwin/METdataio_loadingDB/METdataio/METdbLoad/sql/mv_mysql.sql | ||
|
||
# Name and location of the XML specification file | ||
xml_specification: db_load_specification.xml | ||
|
||
# Databases are grouped, select an existing group or create a new one. | ||
group: Testing | ||
|
||
# Directory (full path) to where the MET data resides. | ||
data_dir: /scratch/mwin | ||
|
||
# Set the appropriate setting to True to indicate what type of data is | ||
# being loaded. | ||
load_stat: True | ||
load_mode: False | ||
load_mtd: False | ||
load_mpr: False | ||
load_orank: False |
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,35 @@ | ||
<load_spec> | ||
<connection> | ||
<management_system>mysql</management_system> | ||
<host>localhost:3306</host> | ||
<database>mv_integrating_fire</database> | ||
<user>mvadmin</user> | ||
<password>160GiltVa0D5M</password> | ||
</connection> | ||
|
||
<folder_tmpl>/scratch/vdunham/</folder_tmpl> | ||
|
||
<verbose>true</verbose> | ||
<insert_size>1</insert_size> | ||
<stat_header_db_check>true</stat_header_db_check> | ||
<mode_header_db_check>false</mode_header_db_check> | ||
<mtd_header_db_check>false</mtd_header_db_check> | ||
<drop_indexes>false</drop_indexes> | ||
<apply_indexes>false</apply_indexes> | ||
|
||
<load_stat>true</load_stat> | ||
<load_mode>false</load_mode> | ||
<load_mtd>false</load_mtd> | ||
<load_mpr>false</load_mpr> | ||
<load_orank>false</load_orank> | ||
|
||
<load_val> | ||
<field name="met_tool"> | ||
<val>point_stat</val> | ||
</field> | ||
</load_val> | ||
|
||
<group>RAL Projects</group> | ||
<description>MET output generated for SOARS research.</description> | ||
|
||
</load_spec> |
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,101 @@ | ||
''' | ||
Creates the METviewer database to store MET output. | ||
''' | ||
|
||
import yaml | ||
import argparse | ||
from dataclasses import dataclass | ||
import logging | ||
import xml.etree.ElementTree as et | ||
|
||
logging.basicConfig(encoding='utf-8', level=logging.DEBUG) | ||
|
||
|
||
@dataclass | ||
class DatabaseLoadingInfo: | ||
''' | ||
Data class for keeping the relevant information for loading the | ||
METviewer database. | ||
''' | ||
|
||
db_name: str | ||
user_name: str | ||
password: str | ||
host_name: str | ||
port_number: int | ||
group: str | ||
schema_path: str | ||
data_dir: str | ||
xml_spec_file: str | ||
load_stat: bool | ||
load_mode: bool | ||
load_mtd: bool | ||
load_mpr: bool | ||
load_orank: bool | ||
|
||
def __init__(self, config_obj: dict): | ||
''' | ||
Args: | ||
config_obj: A dictionary containing the | ||
settings to be used in creating the database. | ||
''' | ||
|
||
self.db_name = config_obj['dbname'] | ||
self.user_name = config_obj['username'] | ||
self.password = config_obj['password'] | ||
self.host_name = config_obj['host'] | ||
self.port_number = config_obj['port'] | ||
self.group = config_obj['group'] | ||
self.schema_path = config_obj['schema_location'] | ||
self.data_dir = config_obj['data_dir'] | ||
self.xml_spec_file = config_obj['xml_specification'] | ||
self.load_stat = config_obj['load_stat'] | ||
self.load_mode = config_obj['load_mode'] | ||
self.load_mtd = config_obj['load_mtd'] | ||
self.load_mpr = config_obj['load_mpr'] | ||
self.load_orank = config_obj['load_orank'] | ||
|
||
|
||
def update_spec_file(self): | ||
''' | ||
Edit the XML specification file to reflect the settings in the | ||
YAML configuration file. | ||
''' | ||
|
||
specification_tree = et.parse(self.xml_spec_file) | ||
myroot = specification_tree.getroot() | ||
host = | ||
host.txt = str(self.host_name) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
# Create a parser | ||
parser = argparse.ArgumentParser() | ||
|
||
# Add arguments to the parser | ||
parser.add_argument('action') | ||
parser.add_argument('config_file') | ||
|
||
# Parse the arguments | ||
args = parser.parse_args() | ||
|
||
# Get arguments value | ||
action = args.action | ||
config_file = args.config_file | ||
|
||
action_requested = str(action).lower() | ||
logging.debug(f'Action requested: {action_requested}') | ||
logging.debug(f'Config file to use: {str(config_file)}') | ||
|
||
with open(config_file, 'r') as cf: | ||
db_config_info = yaml.safe_load(cf) | ||
db_loader = DatabaseLoadingInfo(db_config_info) | ||
if action_requested == 'create': | ||
db_loader.update_spec_file() | ||
elif action_requested == 'delete': | ||
pass | ||
else: | ||
logging.warning(f'{action_requested} is not a supported option.') |