Changeset 773
- Timestamp:
- 03/29/13 12:40:39 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/jobarchived/jobarchived.py
r772 r773 48 48 def processArgs( args ): 49 49 50 51 52 53 50 SHORT_L = 'p:hvc:' 51 LONG_L = [ 'help', 'config=', 'pidfile=', 'version' ] 52 53 config_filename = '/etc/jobarchived.conf' 54 54 55 55 global PIDFILE … … 57 57 PIDFILE = None 58 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 59 try: 60 61 opts, args = getopt.getopt( args, SHORT_L, LONG_L ) 62 63 except getopt.error, detail: 64 65 print detail 66 sys.exit(1) 67 68 for opt, value in opts: 69 70 if opt in [ '--config', '-c' ]: 71 72 config_filename = value 73 73 74 74 if opt in [ '--pidfile', '-p' ]: … … 175 175 ARCHIVE_XMLSOURCE = cfg.get( 'DEFAULT', 'ARCHIVE_XMLSOURCE' ) 176 176 177 177 ARCHIVE_DATASOURCES = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_DATASOURCES' ) ) 178 178 179 179 ARCHIVE_EXCLUDE_METRICS = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_EXCLUDE_METRICS' ) ) … … 209 209 210 210 try: 211 from pyPgSQL import PgSQL211 import psycopg2 212 212 213 213 except ImportError, details: 214 214 215 print "FATAL ERROR: p yPgSQLpython module not found"215 print "FATAL ERROR: psycopg2 python module not found" 216 216 sys.exit( 1 ) 217 218 # Orginal from Andre van der Vlies <andre@vandervlies.xs4all.nl> for MySQL. Changed219 # and added some more functions for postgres.220 #221 #222 # Changed by: Bas van der Vlies <basv@sara.nl>223 #224 # SARA API for Postgres Database225 #226 # Changed by: Ramon Bastiaans for Job Monarch227 #228 217 229 218 class InitVars: … … 274 263 # 275 264 class DB: 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 self.db = 'uva_cluster_db'299 300 301 dsn = "%s::%s:%s:%s" %(self.host, self.db, self.user, self.passwd)302 303 304 self.SQL = PgSQL.connect(dsn)305 except PgSQL.Error, details:306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 except PgSQL.Error, details:330 331 332 333 334 335 336 337 338 339 340 341 342 343 except PgSQL.Error, details:344 345 346 347 348 349 350 351 352 265 def __init__(self, db_vars): 266 267 self.dict = db_vars 268 269 if self.dict.has_key('User'): 270 self.user = self.dict['User'] 271 else: 272 self.user = 'postgres' 273 274 if self.dict.has_key('Host'): 275 self.host = self.dict['Host'] 276 else: 277 self.host = 'localhost' 278 279 if self.dict.has_key('Password'): 280 self.passwd = self.dict['Password'] 281 else: 282 self.passwd = '' 283 284 if self.dict.has_key('DataBaseName'): 285 self.db = self.dict['DataBaseName'] 286 else: 287 self.db = 'jobarchive' 288 289 # connect_string = 'host:port:database:user:password: 290 dsn = "host='%s' dbname='%s' user='%s' password='%s'" %(self.host, self.db, self.user, self.passwd) 291 292 try: 293 self.SQL = psycopg2.connect(dsn) 294 except psycopg2.Error, details: 295 str = "%s" %details 296 raise DBError(str) 297 298 def __repr__(self): 299 return repr(self.result) 300 301 def __nonzero__(self): 302 return not(self.result == None) 303 304 def __len__(self): 305 return len(self.result) 306 307 def __getitem__(self,i): 308 return self.result[i] 309 310 def __getslice__(self,i,j): 311 return self.result[i:j] 312 313 def Get(self, q_str): 314 c = self.SQL.cursor() 315 try: 316 c.execute(q_str) 317 result = c.fetchall() 318 except psycopg2.Error, details: 319 c.close() 320 str = "%s" %details 321 raise DBError(str) 322 323 c.close() 324 return result 325 326 def Set(self, q_str): 327 c = self.SQL.cursor() 328 try: 329 c.execute(q_str) 330 result = c.oidValue 331 332 except psycopg2.Error, details: 333 c.close() 334 str = "%s" %details 335 raise DBError(str) 336 337 c.close() 338 return result 339 340 def Commit(self): 341 self.SQL.commit() 353 342 354 343 class DataSQLStore: … … 1186 1175 continue 1187 1176 1188 1177 try: 1189 1178 1190 1179 self.s.connect( sa ) 1191 1180 1192 1181 except ( socket.error, socket.gaierror, socket.herror, socket.timeout ), msg: 1193 1182 1194 1183 self.disconnect() 1195 1184 continue 1196 1185 1197 1186 break 1198 1187 1199 1188 if self.s is None: … … 1207 1196 1208 1197 my_fp = self.s.makefile( 'r' ) 1209 my_data 1210 my_data 1198 my_data = my_fp.readlines() 1199 my_data = string.join( my_data, '' ) 1211 1200 1212 1201 self.data = my_data 1213 1202 1214 self.LAST_UPDATE 1203 self.LAST_UPDATE = time.time() 1215 1204 1216 1205 self.slot.release()
Note: See TracChangeset
for help on using the changeset viewer.