source: TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/run_all_ingest.py @ 6128

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/run_all_ingest.py@6128
Revision 6128, 4.4 KB checked in by sdonegan, 10 years ago (diff)

Took out local directory references and put absolute paths where necessary

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""
3"""
4import os, sys, logging,time,string
5
6lineSeparator = "-----------------------------"
7
8# configure logging
9logging.basicConfig(level=logging.INFO,
10                    format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
11
12logging.info(lineSeparator)
13logging.info("RUNNING: run_all_ingest.py")
14logging.info(lineSeparator)
15
16from oai_document_ingester import oai_document_ingester
17
18
19run_counter = 0
20error_counter = 0
21
22#current_dir = os.getcwd() + "/"# this is the base dir that the script is ran from
23current_dir = '/home/badc/buildouts/oai_document_ingester/ingestAutomation-upgrade/OAIBatch/' # NOTE this is changed to the production buildout directory
24logging.info("Running ingest script for all config files in the current run directory (%s)" %current_dir)
25
26#create file for summary report on all ingests
27reportingDir = '/home/badc/discovery_docs/ingestDocs/' # base dir where production reporting and output should go
28summaryFileName = reportingDir + 'runAllIngestSummary.txt'       
29summaryFile = open(summaryFileName,'w')           
30
31#iterate over all files in the current directory and process any config ones
32config_suffix = '_config.properties'
33filenames = os.listdir(current_dir + 'datacentre_config/')
34
35ingester = oai_document_ingester()
36for filename in filenames:
37        if filename.endswith(config_suffix):
38            logging.info("Found config file: %s" %filename)
39         
40            # get the datacentre from the filename
41            datacentre = filename.replace(config_suffix, '')
42            summaryFile.write("\n=====================================================================\n")
43            summaryFile.write("Ingest report for data centre: " + datacentre + " at " + str(time.asctime()) + "\n")
44                   
45            if datacentre.find('backup') > -1:
46                continue
47           
48            # now invoke the ingest script
49            logging.info("Running the ingest script for datacentre: %s" %datacentre)
50            try:
51                run_counter += 1
52                #ingester.processDataCentre(datacentre)
53            except:
54                logging.error("Exception thrown - detail: ")
55                logging.error(sys.exc_info())
56                logging.info("Continue processing next datacentre config file...")
57                error_counter +=1
58
59            #summarise harvest info from report doc now produced by ingester program
60            recOpFileName = reportingDir + datacentre + "_ingestSummary.txt"
61
62            try:
63                ingest_report_file = open(recOpFileName, "r")
64
65                for line in ingest_report_file.readlines():
66                    words  = string.split(line)
67                    if len(words) == 0:
68                        continue
69                    if words[0] == 'TOTAL_PROCESSED':
70                        summaryFile.write("Number of processed files: " + words[1] + "\n")
71                    if words[0] == 'INGESTED_Created':
72                        summaryFile.write("Number of ingested (created) files: " + words[1] + "\n")
73                    if words[0] == 'INGESTED_Updated':
74                        summaryFile.write("Number of ingested (updated) files: " + words[1] + "\n")
75                    if words[0] == 'DELETED':
76                        summaryFile.write("Number of deleted files: " + words[1] + "\n")
77                    if words[0] == 'PROBLEM_FILES':
78                        summaryFile.write("Number of problem files: " + words[1] + "\n")
79                    if words[0] == 'PROBLEM_FILE':
80                        summaryFile.write("Problem file name: " + words[1] + "\n")
81
82                    ingest_report_file.close()
83                   
84                   
85            except:
86                summaryFile.write("Could not extract summary info for " + datacentre + " ingest!!\n")
87           
88summaryFile.close()
89
90if os.path.exists(summaryFileName):
91    commandline = "cat " + summaryFileName + " | mail -s 'TRITON discovery ingest report' steve.donegan@stfc.ac.uk"
92    os.system(commandline)
93
94logging.info("run_all_ingest.py complete - processed %s config files" %run_counter)
95logging.info("ingest report at: "  + summaryFileName)
96
97if error_counter > 0:
98    errorTxt = "WARNING: %s errors were encountered during the run - check logfiles for more details" %error_counter
99    logging.error(errorTxt)
100    commandline = "echo " + errorTxt + " | mail -s 'TRITON discovery ingest report:PROBLEM' steve.donegan@stfc.ac.uk"
101
Note: See TracBrowser for help on using the repository browser.