2019-05-29 16:47:03 +00:00
|
|
|
import argparse
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
def main(secondsAgo=None, year=None, exclude=None, reinit=False):
|
|
|
|
manager = SessionManager()
|
|
|
|
manager.generateEngine()
|
|
|
|
manager.initializeDatabase(reinit)
|
|
|
|
manager.createSession()
|
|
|
|
|
|
|
|
loadFromTime = None
|
|
|
|
startTime = datetime.now()
|
|
|
|
if secondsAgo is not None:
|
|
|
|
loadFromTime = startTime - timedelta(seconds=secondsAgo)
|
2020-05-08 02:15:35 +00:00
|
|
|
if exclude != 'cce':
|
|
|
|
loadCCE(manager, loadFromTime, year)
|
|
|
|
if exclude != 'ccr':
|
|
|
|
loadCCR(manager, loadFromTime, year)
|
2019-07-08 20:55:30 +00:00
|
|
|
indexUpdates(manager, loadFromTime)
|
2019-05-29 16:47:03 +00:00
|
|
|
|
|
|
|
manager.closeConnection()
|
|
|
|
|
|
|
|
|
|
|
|
def loadCCE(manager, loadFromTime, selectedYear):
|
|
|
|
cceReader = CCEReader(manager)
|
|
|
|
cceReader.loadYears(selectedYear)
|
|
|
|
cceReader.getYearFiles(loadFromTime)
|
|
|
|
cceReader.importYearData()
|
|
|
|
|
|
|
|
|
|
|
|
def loadCCR(manager, loadFromTime, selectedYear):
|
|
|
|
ccrReader = CCRReader(manager)
|
|
|
|
ccrReader.loadYears(selectedYear, loadFromTime)
|
|
|
|
ccrReader.importYears()
|
|
|
|
|
|
|
|
def indexUpdates(manager, loadFromTime):
|
|
|
|
esIndexer = ESIndexer(manager, None)
|
2020-05-08 02:16:23 +00:00
|
|
|
esIndexer.indexRecords(recType='cce')
|
2019-05-29 16:47:03 +00:00
|
|
|
esIndexer.indexRecords(recType='ccr')
|
|
|
|
|
|
|
|
|
|
|
|
def parseArgs():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Load CCE XML and CCR TSV into PostgresQL'
|
|
|
|
)
|
|
|
|
parser.add_argument('-t', '--time', type=int, required=False,
|
|
|
|
help='Time ago in seconds to check for file updates'
|
|
|
|
)
|
|
|
|
parser.add_argument('-y', '--year', type=str, required=False,
|
|
|
|
help='Specific year to load CCE entries and/or renewals from'
|
|
|
|
)
|
|
|
|
parser.add_argument('-x', '--exclude', type=str, required=False,
|
|
|
|
choices=['cce', 'ccr'],
|
|
|
|
help='Specify to exclude either entries or renewals from this run'
|
|
|
|
)
|
|
|
|
parser.add_argument('--REINITIALIZE', action='store_true')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def loadConfig():
|
2020-05-06 02:32:28 +00:00
|
|
|
with open('config.yaml-dist', 'r') as yamlFile:
|
2019-05-29 16:47:03 +00:00
|
|
|
config = yaml.safe_load(yamlFile)
|
|
|
|
for section in config:
|
|
|
|
sectionDict = config[section]
|
|
|
|
for key, value in sectionDict.items():
|
|
|
|
os.environ[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
args = parseArgs()
|
2019-07-08 16:18:37 +00:00
|
|
|
try:
|
|
|
|
loadConfig()
|
|
|
|
except FileNotFoundError:
|
2020-05-06 02:32:28 +00:00
|
|
|
print("Unable to set environment variables")
|
2019-07-08 16:18:37 +00:00
|
|
|
pass
|
2019-07-08 20:55:30 +00:00
|
|
|
|
|
|
|
from sessionManager import SessionManager
|
|
|
|
from builder import CCEReader, CCEFile
|
|
|
|
from renBuilder import CCRReader, CCRFile
|
|
|
|
from esIndexer import ESIndexer
|
2020-05-08 02:16:23 +00:00
|
|
|
|
2019-05-29 16:47:03 +00:00
|
|
|
main(
|
|
|
|
secondsAgo=args.time,
|
|
|
|
year=args.year,
|
|
|
|
exclude=args.exclude,
|
|
|
|
reinit=args.REINITIALIZE
|
2020-05-08 02:15:35 +00:00
|
|
|
)
|