Changeset 35097 for trunk/ippToPsps/jython/ipptopsps.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/ipptopsps.py
r33790 r35097 1 1 #!/usr/bin/env jython 2 # EAM : config -> skychunk DONE 2 3 3 4 import signal … … 9 10 10 11 from config import Config 12 from skychunk import Skychunk 11 13 from pslogger import PSLogger 12 14 from ipptopspsdb import IppToPspsDb … … 23 25 def __init__(self, argv, logToStdout=1, logToFile=0): 24 26 25 # are the arsg ok? all programs require a config name 27 # set up config object (global config information, also parse command-line options, eg -test / -t) 28 self.config = Config() 29 30 # are the args ok? all programs require a config name 26 31 if len(sys.argv) < 2: 27 32 self.printUsage() 28 33 self.exitProgram("Wrong args") 29 34 30 35 # some class constants 31 self.PROGNAME = sys.argv[0]32 CONFIGNAME = sys.argv[1]33 36 self.HOST = socket.gethostname() 34 37 self.PID = os.getpid() … … 38 41 self.SECONDS = None 39 42 40 self.createNewConfig = False 41 self.rotateConfigs = False 42 # a new config? 43 if CONFIGNAME == "edit": self.createNewConfig = True 44 # should we rotate configs for this program? 45 elif CONFIGNAME == "all": self.rotateConfigs = True 43 self.logger = self.config.getLogger(self.HOST, self.PID, logToStdout, logToFile) 46 44 47 # set up config object 48 self.config = Config(self.PROGNAME, CONFIGNAME) 49 self.logger = self.config.getLogger(self.HOST, self.PID, logToStdout, logToFile) 45 # argv[1] -> self.skychunk.name 46 self.skychunk = Skychunk(self.logger) 50 47 51 48 # create connection to databases database 52 49 try: 53 self.ippToPspsDb = IppToPspsDb(self.logger, self.config )50 self.ippToPspsDb = IppToPspsDb(self.logger, self.config, self.skychunk) 54 51 except: 55 52 self.exitProgram("Could not connect to ipptopsps Db") … … 63 60 # title for log 64 61 self.logger.infoSeparator() 65 self.logger.infoTitle("ippToPsps '" + self. PROGNAME+ "' started")62 self.logger.infoTitle("ippToPsps '" + self.config.programName + "' started") 66 63 self.logger.infoPair("Host", self.HOST) 67 64 self.logger.infoPair("PID", "%d" % self.PID) 68 self.logger.infoPair(" Config", self.config.name)65 self.logger.infoPair("Skychunk", self.skychunk.name) 69 66 70 67 ''' … … 104 101 105 102 # write message to log or stdout if no logger set up 106 msg = sys.argv[0] + " < configName|all|edit> " + extra103 msg = sys.argv[0] + " <skychunkName|all|edit> " + extra 107 104 try: 108 105 self.logger.errorPair("Usage:", msg) … … 111 108 112 109 ''' 113 Refreshes the configthen recreates objects with new settings110 Refreshes the skychunk then recreates objects with new settings 114 111 ''' 115 def refresh Config(self):112 def refreshSkychunk(self): 116 113 117 # new config?118 if self. createNewConfig:119 self.ippToPspsDb.edit Config()120 self.ippToPspsDb.set ConfigForThisClient(self.config.name, self.HOST, self.PID)121 self. createNewConfig= False114 # new skychunk? 115 if self.skychunk.createNewSkychunk: 116 self.ippToPspsDb.editSkychunk() 117 self.ippToPspsDb.setSkychunkForThisClient(self.skychunk.name, self.HOST, self.PID) 118 self.skychunk.createNewSkychunk = False 122 119 123 # if we are rotating configs, then look for next active one in list124 if self. rotateConfigs:125 self.ippToPspsDb.get ConfigForThisClient(self.HOST, self.PID)126 configs = self.ippToPspsDb.getActiveConfigList()120 # if we are rotating skychunks, then look for next active one in list 121 if self.skychunk.rotateSkychunks: 122 self.ippToPspsDb.getSkychunkForThisClient(self.HOST, self.PID) 123 skychunks = self.ippToPspsDb.getActiveSkychunkList() 127 124 128 125 i = 1 129 for config in configs:130 if config == self.config.name: break126 for skychunk in skychunks: 127 if skychunk == self.skychunk.name: break 131 128 i += 1 132 129 133 if i >= len( configs): newConfig = configs[0]134 else: new Config = configs[i]130 if i >= len(skychunks): newSkychunk = skychunks[0] 131 else: newSkychunk = skychunks[i] 135 132 136 self.ippToPspsDb.set ConfigForThisClient(newConfig, self.HOST, self.PID)133 self.ippToPspsDb.setSkychunkForThisClient(newSkychunk, self.HOST, self.PID) 137 134 138 return self.ippToPspsDb.read Config(self.HOST, self.PID)135 return self.ippToPspsDb.readSkychunk(self.HOST, self.PID) 139 136 140 137 ''' 141 All implementing subclasses (programs) should call this method once in a while to see if it should be paused or killed, otherwise this updates the clients table with current time and reloads the configdata138 All implementing subclasses (programs) should call this method once in a while to see if it should be paused or killed, otherwise this updates the clients table with current time and reloads the skychunk data 142 139 ''' 143 140 def checkClientStatus(self): 144 141 145 self.ippToPspsDb.updateClient(self. PROGNAME, self.HOST, self.PID)142 self.ippToPspsDb.updateClient(self.config.programName, self.HOST, self.PID) 146 143 147 144 if self.ippToPspsDb.isKilled(self.HOST, self.PID): 148 145 self.exitProgram("killed via Db") 149 146 150 # this loop pauses the process if we have no configor we have set it to pause147 # this loop pauses the process if we have no skychunk or we have set it to pause 151 148 firstTimeIn = True 152 while not self.refresh Config() or self.ippToPspsDb.isPaused(self.HOST, self.PID):149 while not self.refreshSkychunk() or self.ippToPspsDb.isPaused(self.HOST, self.PID): 153 150 154 self.ippToPspsDb.updateClient(self. PROGNAME, self.HOST, self.PID)151 self.ippToPspsDb.updateClient(self.config.programName, self.HOST, self.PID) 155 152 if self.ippToPspsDb.isKilled(self.HOST, self.PID): 156 153 self.exitProgram("killed while paused") … … 175 172 # write message to log or stdout if no logger set up 176 173 try: 177 self.logger.infoPair(self. PROGNAME+ " exited", exitReason)174 self.logger.infoPair(self.config.programName + " exited", exitReason) 178 175 except: 179 176 print "*** Program exited: " + exitReason … … 186 183 187 184 sys.exit(0) 188 189
Note:
See TracChangeset
for help on using the changeset viewer.
