Changeset 35097 for trunk/ippToPsps/jython/config.py
- Timestamp:
- Feb 6, 2013, 3:16:35 PM (13 years ago)
- Location:
- trunk/ippToPsps
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps
- Property svn:mergeinfo changed
-
trunk/ippToPsps/jython
- Property svn:ignore
-
old new 1 1 *.class 2 Makefile 3 Makefile.in
-
- Property svn:ignore
-
trunk/ippToPsps/jython/config.py
r33728 r35097 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): 14 15 15 16 16 ''' … … 19 19 Basically reads the entire config and stores values to class variables 20 20 ''' 21 def __init__(self , programName, name):21 def __init__(self): 22 22 23 self.programName = programName 24 self.name = name 25 self.settingsPath = "../config/settings.xml" # TODO 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 + "/" 49 50 # self.configdir is set in ipptopsps.jy on init based on env(IPPTOPSPS_DATA) 51 # for test purposes, an uninstalled system may use the config information from 52 # a relative path 53 self.settingsPath = self.configDir + "settings.xml" 54 26 55 self.logger = None 27 56 28 57 self.settingsDoc = ElementTree(file=self.settingsPath) 29 58 self.logPath = self.settingsDoc.find("logPath").text 30 self.czarPlotsPath = self.settingsDoc.find("czarPlotsPath").text31 59 32 # this is the border (in degrees) that we place around any loading box of 33 # PS1 pointings to ensure we pull a large enough area out of DVO 34 self.BORDER = 1.65 35 self.isLoaded = False 36 37 ''' 38 Prints everything for this config 39 ''' 40 def printAll(self): 41 42 self.logger.infoTitle("Config") 43 44 try: 45 self.logger.infoSeparator() 46 self.logger.infoPair("Config name", self.name) 47 self.logger.infoPair("Survey", self.survey) 48 self.logger.infoPair("Publishing to PSPS as survey", self.pspsSurvey) 49 self.logger.infoPair("Loading epoch", self.epoch) 50 self.logger.infoPair("Data release", "%d" % self.dataRelease) 51 for batchType in self.batchTypes: self.logger.infoPair("Queuing batch type", batchType) 52 except: 53 pass 54 55 self.printDvoInfo() 56 self.printDatastoreInfo() 57 self.printBoxCoords() 58 self.printDeletionPolicy() 59 try: self.logger.infoSeparator() 60 except: pass 61 62 ''' 63 Queuing this batch type? 64 ''' 65 def queuingThisBatchType(self, batchType): 66 if batchType in self.batchTypes: return 1 67 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 68 65 69 66 ''' … … 72 69 def getLogger(self, host, pid, stdout=1, sendToFile=0): 73 70 71 print "get Logger: ", host, pid 74 72 logging.setLoggerClass(PSLogger) 73 print "done Logger 1" 75 74 self.logger = logging.getLogger(self.programName) 76 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" 77 81 78 82 return self.logger 79 80 '''81 Prints the currently set DVO info82 '''83 def printDvoInfo(self):84 85 try:86 self.logger.infoPair("DVO label", self.dvoLabel)87 self.logger.infoPair("DVO location", self.dvoLocation)88 except:89 pass90 91 '''92 Prints datastore info93 '''94 def printDatastoreInfo(self):95 96 try:97 self.logger.infoBool("Datastore publishing?", self.datastorePublishing)98 if self.datastorePublishing:99 self.logger.infoPair("Datastore type", self.datastoreProduct)100 self.logger.infoPair("Datastore product", self.datastoreType)101 except:102 pass103 104 '''105 Prints the current deletion policy106 '''107 def printDeletionPolicy(self):108 109 try:110 self.logger.infoBool("Deleting local?", self.deleteLocal)111 self.logger.infoBool("Deleting datastore?", self.deleteDatastore)112 self.logger.infoBool("Deleting DXLayer?", self.deleteDxLayer)113 except:114 pass115 116 '''117 Prints the currently set RA/Dec bounding box118 '''119 def printBoxCoords(self):120 121 try:122 self.logger.infoPair("RA limits", "%.1f -> %.1f" % (self.minRa, self.maxRa))123 self.logger.infoPair("Dec limits", "%.1f -> %.1f" % (self.minDec, self.maxDec))124 self.logger.infoPair("Loading box size", "%.1f degrees" % self.boxSize)125 except:126 pass127 128 83 129 84 ''' … … 134 89 def getDbUser(self, dbType): return self.settingsDoc.find(dbType +"/user").text 135 90 def getDbPassword(self, dbType): return self.settingsDoc.find(dbType +"/password").text 136
Note:
See TracChangeset
for help on using the changeset viewer.
