- Timestamp:
- Jan 31, 2013, 4:13:09 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20121219/ippToPsps/jython/config.py
r35075 r35076 1 1 #!/usr/bin/env jython 2 2 3 import sys 4 import os 3 5 import logging 4 6 from xml.etree.ElementTree import ElementTree, Element, tostring … … 6 8 from pslogger import PSLogger 7 9 8 9 10 ''' 10 A class encapsulating a ippToPsps configuration. This information is stored in the 'config' table11 of the ipptopsps database, but there are some higher level config details in the 'settings.xml' file 11 A class encapsulating the globald ippToPsps configuration information. 12 This is stored in the 'settings.xml' file in the config directory 12 13 ''' 13 14 class Config(object): … … 18 19 Basically reads the entire config and stores values to class variables 19 20 ''' 20 def __init__(self , programName, name, configDir):21 def __init__(self): 21 22 22 self.programName = programName 23 self.name = name 24 self.configDir = configDir 23 self.test = False 24 for arg in sys.argv: 25 if arg == "-test": 26 self.test = True 27 sys.argv.remove(arg) 28 if arg == "-t": 29 self.test = True 30 sys.argv.remove(arg) 31 32 ## name of the top-level jython script 33 self.programName = os.path.basename(sys.argv[0]) 34 35 ## this is somewhat crude: ipptopsps programs are called like this: 36 ## ippjython foo.py [chunk] [other options] 37 ## the logging code (called below by getLogger) wants to include 'name' in the 38 ## output file. we blindly set name == argv[1] 39 ## programs which are called without argv[1] will use 'none' in the log file 40 if len(sys.argv) >= 2: 41 self.name = sys.argv[1] 42 43 # XXX this probably goes in 'config.py' 44 self.configDir = os.getenv("IPPTOPSPS_DATA") 45 if self.configDir is None: 46 self.configDir = "../config/" 47 else: 48 self.configDir = self.configDir + "/" 25 49 26 50 # self.configdir is set in ipptopsps.jy on init based on env(IPPTOPSPS_DATA) 27 51 # for test purposes, an uninstalled system may use the config information from 28 52 # a relative path 29 if self.configDir is None: 30 self.settingsPath = "../config/settings.xml" # TODO 31 else: 32 self.settingsPath = self.configDir + "settings.xml" 53 self.settingsPath = self.configDir + "settings.xml" 33 54 34 55 self.logger = None … … 37 58 self.logPath = self.settingsDoc.find("logPath").text 38 59 39 # XXX this is poor -- the czartool stuff is not related to 40 # ipptopsps and should be moved elsewhere 41 self.czarPlotsPath = self.settingsDoc.find("czarPlotsPath").text 42 43 # this is the border (in degrees) that we place around any loading box of 44 # PS1 pointings to ensure we pull a large enough area out of DVO 45 # XXX this is a poor place to put this information -- it is completely gpc-specific. 46 # probably should go elsewhere 47 self.BORDER = 1.65 48 self.isLoaded = False 49 50 ''' 51 Prints everything for this config 52 ''' 53 def printAll(self): 54 55 self.logger.infoTitle("Config") 56 57 try: 58 self.logger.infoSeparator() 59 self.logger.infoPair("Config name", self.name) 60 self.logger.infoPair("Survey", self.survey) 61 self.logger.infoPair("Publishing to PSPS as survey", self.pspsSurvey) 62 self.logger.infoPair("Loading epoch", self.epoch) 63 self.logger.infoPair("Data release", "%d" % self.dataRelease) 64 for batchType in self.batchTypes: self.logger.infoPair("Queuing batch type", batchType) 65 except: 66 pass 67 68 self.printDvoInfo() 69 self.printDatastoreInfo() 70 self.printBoxCoords() 71 self.printDeletionPolicy() 72 try: self.logger.infoSeparator() 73 except: pass 74 75 ''' 76 Queuing this batch type? 77 ''' 78 def queuingThisBatchType(self, batchType): 79 if batchType in self.batchTypes: return 1 80 return 0 60 print "config.programName: ", self.programName 61 print "config.configDir: ", self.configDir 62 print "config.settingsPath: ", self.settingsPath 63 print "config.logPath: ", self.logPath 64 print "config.test: ", self.test 81 65 82 66 ''' … … 85 69 def getLogger(self, host, pid, stdout=1, sendToFile=0): 86 70 71 print "get Logger: ", host, pid 87 72 logging.setLoggerClass(PSLogger) 73 print "done Logger 1" 88 74 self.logger = logging.getLogger(self.programName) 89 self.logger.setup(self.programName, self.logPath, self.name, host, pid, stdout, sendToFile) 75 print "done Logger 2" 76 if (self.name is None): 77 self.logger.setup(self.programName, self.logPath, "none", host, pid, stdout, sendToFile) 78 else: 79 self.logger.setup(self.programName, self.logPath, self.name, host, pid, stdout, sendToFile) 80 print "done Logger 3" 90 81 91 82 return self.logger 92 93 '''94 Prints the currently set DVO info95 '''96 def printDvoInfo(self):97 98 try:99 self.logger.infoPair("DVO label", self.dvoLabel)100 self.logger.infoPair("DVO location", self.dvoLocation)101 except:102 pass103 104 '''105 Prints datastore info106 '''107 def printDatastoreInfo(self):108 109 try:110 self.logger.infoBool("Datastore publishing?", self.datastorePublishing)111 if self.datastorePublishing:112 self.logger.infoPair("Datastore type", self.datastoreProduct)113 self.logger.infoPair("Datastore product", self.datastoreType)114 except:115 pass116 117 '''118 Prints the current deletion policy119 '''120 def printDeletionPolicy(self):121 122 try:123 self.logger.infoBool("Deleting local?", self.deleteLocal)124 self.logger.infoBool("Deleting datastore?", self.deleteDatastore)125 self.logger.infoBool("Deleting DXLayer?", self.deleteDxLayer)126 except:127 pass128 129 '''130 Prints the currently set RA/Dec bounding box131 '''132 def printBoxCoords(self):133 134 try:135 self.logger.infoPair("RA limits", "%.1f -> %.1f" % (self.minRa, self.maxRa))136 self.logger.infoPair("Dec limits", "%.1f -> %.1f" % (self.minDec, self.maxDec))137 self.logger.infoPair("Loading box size", "%.1f degrees" % self.boxSize)138 except:139 pass140 141 83 142 84 ''' … … 147 89 def getDbUser(self, dbType): return self.settingsDoc.find(dbType +"/user").text 148 90 def getDbPassword(self, dbType): return self.settingsDoc.find(dbType +"/password").text 149
Note:
See TracChangeset
for help on using the changeset viewer.
