def __init__(self, dbUser=None, dbName=None, dbHost=None, dbPwd=None, SQLiteDB=None, tablePerPlatform=False, chart=False): self.tablePerPlatform = tablePerPlatform #Flag that specifies whether or not we create a seperate HTML page per platform. True, each platform gets a seperate page, False all results on 1. self.chart = chart #Flag that specifies if we add a URL to a google chart for the observation. if (SQLiteDB == None): self.xeniaDB = xeniaPostGres() #Database object. if (self.xeniaDB.connect(None, dbUser, dbPwd, dbHost, dbName)): print("Successfully connected to Xenia DB: Name: %s at %s\n" % (dbName, dbHost)) else: print( "Failed to connect to Xenia DB: Host: %s Name: %s User: %s(%s)\nError: %s"\ %( dbHost, dbName, dbUser, dbPwd, self.xeniaDB.getErrorInfo() ) ) sys.exit(-1) else: self.xeniaDB = xeniaSQLite() #Database object. if (self.xeniaDB.connect(SQLiteDB)): print("Successfully connected to Xenia DB: Name: %s\n" % (SQLiteDB)) else: print( "Failed to connect to Xenia DB: %s\nError: %s"\ %( SQLiteDB, self.xeniaDB.getErrorInfo() ) ) sys.exit(-1) self.obsDataPoints = recursivedefaultdict( ) #Dictionary keyed on obs and sOrder for each data point. Used to collect the points to graph.
def __init__(self, dbUser=None, dbName=None, dbHost=None, dbPwd=None, SQLiteDB=None, tablePerPlatform=False,chart=False): self.tablePerPlatform = tablePerPlatform #Flag that specifies whether or not we create a seperate HTML page per platform. True, each platform gets a seperate page, False all results on 1. self.chart = chart #Flag that specifies if we add a URL to a google chart for the observation. if(SQLiteDB == None): self.xeniaDB = xeniaPostGres() #Database object. if( self.xeniaDB.connect( None, dbUser, dbPwd, dbHost, dbName ) ): print( "Successfully connected to Xenia DB: Name: %s at %s\n" % ( dbName, dbHost) ) else: print( "Failed to connect to Xenia DB: Host: %s Name: %s User: %s(%s)\nError: %s"\ %( dbHost, dbName, dbUser, dbPwd, self.xeniaDB.getErrorInfo() ) ) sys.exit(-1) else: self.xeniaDB = xeniaSQLite() #Database object. if( self.xeniaDB.connect( SQLiteDB ) ): print( "Successfully connected to Xenia DB: Name: %s\n" % ( SQLiteDB) ) else: print( "Failed to connect to Xenia DB: %s\nError: %s"\ %( SQLiteDB, self.xeniaDB.getErrorInfo() ) ) sys.exit(-1) self.obsDataPoints = recursivedefaultdict() #Dictionary keyed on obs and sOrder for each data point. Used to collect the points to graph.
def __init__(self, configSettings): alertsDBFile = configSettings.getEntry("//environment/database/alertsDB/name") xeniaDBSettings = configSettings.getDatabaseSettings() conversionXMLFile = configSettings.getEntry("//environment/unitsConversion/file") self.unsubURL = configSettings.getEntry("//environment/unsubscribeURL") self.georssURL = configSettings.getEntry("//environment/geoRSSURL") self.surveyURL = configSettings.getEntry("//environment/surveyURL") self.uomConverter = uomconversionFunctions( conversionXMLFile ) self.logger = logging.getLogger("emailalert_logger.alertsDB") self.logger.info("creating an instance of emailAlerts") self.alertsDB = alertsDB( alertsDBFile ) if( self.alertsDB.connectDB() == False ): self.logger.error( "Unable to connect to Alerts DB: %s" % ( alertsDBFile ) ) sys.exit(-1) else: self.logger.debug( "Connected to Alerts DB: %s" % ( alertsDBFile ) ) if( xeniaDBSettings['type'] == 'SQLite' ): self.obsDB = xeniaSQLite() if( self.obsDB.connect( xeniaDBSettings['dbName'] ) == False ): self.logger.error( "Unable to connect to xenia DB: %s Error: %s" % ( xeniaDBSettings['dbName'], self.obsDB.lastErrorMsg ) ) sys.exit(-1) else: self.logger.debug( "Connected to xenia DB: %s" % ( xeniaDBSettings['dbName'] ) ) else: self.obsDB = xeniaPostGres() if( self.obsDB.connect( None, xeniaDBSettings['dbUser'], xeniaDBSettings['dbPwd'], xeniaDBSettings['dbHost'], xeniaDBSettings['dbName'] ) == False ): self.logger.error( "Unable to connect to xeniaDB: %s Host: %s User: %s\nError: %s" % (xeniaDBSettings['dbName'], xeniaDBSettings['dbHost'], xeniaDBSettings['dbUser'] ,self.obsDB.lastErrorMsg) ) sys.exit(-1) else: self.logger.debug( "Connected to Host: %s Name: %s User: %s", xeniaDBSettings['dbHost'],xeniaDBSettings['dbName'],xeniaDBSettings['dbUser'] )
sys.exit(-1) try: #Open the XML Config File for processing. configFile = xmlConfigFile(options.xmlConfigFile) #Are we having the buoys friend each other? if (options.createFriends): createFriends(configFile) #We are tweeting the buoy status. else: #Get the various settings we need from out xml config file. dbSettings = configFile.getDatabaseSettings() if (dbSettings['dbHost'] != None and dbSettings['dbName'] != None and dbSettings['dbUser'] != None and dbSettings['dbPwd'] != None): db = xeniaPostGres() if (db.connect(None, dbSettings['dbUser'], dbSettings['dbPwd'], dbSettings['dbHost'], dbSettings['dbName']) == False): print("Unable to connect to PostGres.") sys.exit(-1) else: print("Connect to PostGres: %s %s" % (dbSettings['dbHost'], dbSettings['dbName'])) else: print("Missing configuration info for PostGres setup.") sys.exit(-1) #Get the conversion xml file convertFile = configFile.getEntry( '//environment/unitsCoversion/file')
try: #Open the XML Config File for processing. configFile = xmlConfigFile( options.xmlConfigFile ) #Are we having the buoys friend each other? if( options.createFriends ): createFriends( configFile ) #We are tweeting the buoy status. else: #Get the various settings we need from out xml config file. dbSettings = configFile.getDatabaseSettings() if( dbSettings['dbHost'] != None and dbSettings['dbName'] != None and dbSettings['dbUser'] != None and dbSettings['dbPwd'] != None ): db = xeniaPostGres() if( db.connect( None, dbSettings['dbUser'], dbSettings['dbPwd'], dbSettings['dbHost'], dbSettings['dbName'] ) == False ): print( "Unable to connect to PostGres." ) sys.exit(-1) else: print( "Connect to PostGres: %s %s" % (dbSettings['dbHost'],dbSettings['dbName'])) else: print( "Missing configuration info for PostGres setup." ) sys.exit(-1) #Get the conversion xml file convertFile = configFile.getEntry( '//environment/unitsCoversion/file' ) if( convertFile != None ): uomConverter = uomconversionFunctions(convertFile) else: print( "Unable to find XML conversion file given in the configuration file.")
parser.add_option( "-S", "--SQLOutFilename", dest="sqlOutFilename", help="If set, a SQL file is output to the file given in this option. Otherwise statements written directly to DB" ) parser.add_option( "-x", "--WriteToXeniaDB", dest="writeToXeniaDB", help="If set, the data is written directly to the Xenia database described by the connection parameters above." ) (options, args) = parser.parse_args() if( options.xmlRainGaugeConfig is None or options.dbUser is None or options.dbName is None ): parser.print_usage() parser.print_help() sys.exit(-1) configSettings = dhecConfigSettings( options.xmlRainGaugeConfig ) xeniaDB = xeniaPostGres() if( xeniaDB.connect( None, options.dbUser, options.dbPwd, options.dbHost, options.dbName ) ): print( "Successfully connected to Xenia DB: Name: %s at %s\n" % ( options.dbName, options.dbHost) ) else: print( "Failed to connect to Xenia DB: Host: %s Name: %s User: %s(%s)\nError: %s" %( options.dbHost, options.dbName, options.dbUser, options.dbPwd, xeniaDB.lastErrorMsg ) ) sys.exit(-1) sqlFile = None if( options.sqlOutFilename != None ): try: sqlFile = open(options.sqlOutFilename,'w') print( "Opened SQL file: %s.\n" %(options.sqlOutFilename) ) except Exception, e: info = sys.exc_info() excNfo = traceback.extract_tb(info[2],1) items = excNfo[0]