def get_product_out_info(allrecs=False, productcode='', subproductcode='', version='undefined'): db = connectdb.ConnectDB().db try: if allrecs: product_out_info = db.product.order_by(asc( db.product.productcode)).all() else: where = and_(db.product.productcode == productcode, db.product.subproductcode == subproductcode, db.product.version == version) product_out_info = db.product.filter(where).all() return product_out_info except: exceptiontype, exceptionvalue, exceptiontraceback = sys.exc_info() # Exit the script and print an error telling what happened. logger.error( "get_product_out_info: Database query error!\n -> {}".format( exceptionvalue)) #raise Exception("get_product_out_info: Database query error!\n ->%s" % exceptionvalue) finally: if db.session: db.session.close() db = None
def test_connection_postgresql(self): # Force NOT in Testing mode #es_constants.es2globals['db_test_mode'] = False # Connect and test schema connect_db = connectdb.ConnectDB() schema = ("%s." % connect_db.schema) if connect_db.schema else "" self.assertEquals(schema, 'products.')
def test_connection_sqlite(self): # Force Testing mode #es_constants.es2globals['db_test_mode'] = True # Connect and test schema connect_db = connectdb.ConnectDB(use_sqlite=True) schema = ("%s." % connect_db.schema) if connect_db.schema else "" self.assertEquals(schema, '')
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB(use_sqlite=True).db) self.kwargs = {'product_code':"vgt_ndvi"} self.mapsets = ('WGS84_Africa_1km', 'WGS84_Sahel_1km') self.subproducts = ('sm', 'ndv') self.files_mapsets = [os.path.join(es_constants.es2globals['data_dir'], self.kwargs['product_code'], mapset) for mapset in self.mapsets] self.files_subproducts = [os.path.join(file_mapset, subproduct_type, subproduct) for file_mapset in self.files_mapsets for subproduct_type in functions.dict_subprod_type_2_dir.values() for subproduct in self.subproducts] self.old_glob = glob.glob glob.glob = glob_monkey
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB().db) self.kwargs = {'product_code': "vgt-ndvi", 'version': "sv2-pv2.2"} self.mapsets = ('SPOTV-Africa-1km', 'SPOTV-Africa-1km') self.subproducts = ('sm', 'ndv') self.files_mapsets = [os.path.join(es_constants.es2globals['data_dir'], self.kwargs['product_code'], mapset) for mapset in self.mapsets] self.files_subproducts = [os.path.join(file_mapset, subproduct_type, subproduct) for file_mapset in self.files_mapsets for subproduct_type in list(functions.dict_subprod_type_2_dir.values()) for subproduct in self.subproducts] self.old_glob = glob.glob glob.glob = glob_monkey
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB().db) self.kwargs = { 'version': '2.0', 'product_code': "fewsnet-rfe", 'sub_product_code': "10d", 'mapset': 'FEWSNET-Africa-8km' } self.files_dekad = [ "20180101_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180111_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180121_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180201_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180211_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", # Here 2 missings "20180221_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.missing", "20180301_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.missing", "20180311_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180321_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180401_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180411_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180421_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180501_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180511_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180521_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180601_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180611_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180621_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", # Here 3 holes - July "20180801_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180811_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180821_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180901_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180911_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20180921_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181001_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181011_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181021_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181101_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181111_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181121_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181201_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181211_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif", "20181221_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif" ]
def __init__(self, schema='products', echo=False): self.schema = schema or es_constants.es2globals['schema_products'] self.connect_db = connectdb.ConnectDB(schema=self.schema, usesqlsoup=False) db = self.connect_db.db db.echo = echo self.table_map = {} self.session = None # new session # self.Session = Session() # set the search path # db.execute("SET search_path TO products") # Initialize DB and create a hashmap of table name and associated ORM mapper class metadata = sqlalchemy.MetaData(db, schema=self.schema) # retrieve database table information dynamically metadata.reflect() metadata.schema = None # metadata.schema = self.schema for table_name in metadata.tables: # create a class that inherits basetable class and maps the class to table table_class = type(str(table_name), (BaseTable, ), {}) try: mapper(table_class, sqlalchemy.Table(table_name, metadata, autoload=True)) self.table_map[table_name] = table_class except SQLAlchemyError: exceptiontype, exceptionvalue, exceptiontraceback = sys.exc_info( ) # print "could not map table ", table_name # Exit the script and print an error telling what happened. logger.error("CrudDB: could not map table %s!" % table_name) logger.error("CrudDB: Exceptiontype: " % exceptiontype) logger.error("CrudDB: Exceptionvalue: " % exceptionvalue) logger.error("CrudDB: Exceptiontraceback: " % exceptiontraceback) # create a Session template that requires commit to be called explicit # self.session = sessionmaker(bind=db, autoflush=True) metadata.schema = self.schema
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB(use_sqlite=True).db) self.kwargs = {'product_code':"fewsnet_rfe", 'sub_product_code': "rfe", 'mapset': 'FEWSNET_Africa_8km'} self.files_dekad = [ "20140101_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140111_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140121_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140201_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140211_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140221_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140301_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140311_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140321_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140401_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140411_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140421_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140501_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140511_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140521_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140601_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.missing", "20140611_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.missing", "20140621_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.missing", "20140701_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140711_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140721_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", # Here 3 holes "20140901_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140911_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20140921_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141001_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141011_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141021_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141101_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141111_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141121_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141201_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141211_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", "20141221_FEWSNET_RFE_RFE_FEWSNET_Africa_8km.tif", ]
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB().db)
def setUp(self): setattr(querydb, 'db', connectdb.ConnectDB(use_sqlite=True).db)
from past.utils import old_div import os import xml.etree.cElementTree as ET import subprocess import pipes import sys from sqlalchemy.orm import aliased from database import querydb from lib.python import functions from apps.es2system.GeoPortal import geoserverREST from lib.python import es_logging as log from database import connectdb db = connectdb.ConnectDB(schema='products').db standard_library.install_aliases() TranslateLayerNames = False tempDir = '/tmp/eStation2/tempStationTools/' translator = { 'vgt-ndvi_vci': { 'category': 'AMESD_SADC', 'region': 'SAfri', 'version': 'v2', 'product': 'VCI_______', 'stringType': 0 }, 'fewsnet-rfe_10davg': {
def test_connection_sqlsoup(self): # Connect and test schema connect_db = connectdb.ConnectDB(schema='analysis', usesqlsoup=True) schema = ("%s." % connect_db.schema) if connect_db.schema else "" self.assertEqual(schema, 'analysis.')
def test_connection_no_sqlsoup(self): # Connect and test schema connect_db = connectdb.ConnectDB(usesqlsoup=False) schema = ("%s." % connect_db.schema) if connect_db.schema else "" self.assertEqual(schema, 'products.')
b = 0 if b < 0 else 255 if b > 255 else b b = "%x" % b color = '00' if len(r) < 2 else '' + r color += '00' if len(g) < 2 else '' + g color += '00' if len(b) < 2 else '' + b return '#' + color import sys, traceback from sqlalchemy.orm import aliased from database import connectdb db = connectdb.ConnectDB().db def get_activated_geoserver(): global db try: session = db.session geoserver = aliased(db.geoserver) # The columns on the subquery "processinput" are accessible through an attribute called "c" # e.g. es.c.productcode active_geoserver = session.query(geoserver.geoserver_id, geoserver.productcode, geoserver.subproductcode, geoserver.version, geoserver.defined_by,