walib package

Subpackages

Submodules

walib.configManager module

class walib.configManager.waServiceConfig(defaultcfgpath, servicecfgpath=None)

base service configuration object to handle configuration files

>>> Class structure:
    self.defaultcfgpath --> path of the default configuration file
    self.servicecfgpath --> path of the service configuration file
    self.sections = --> list of available sections
    self.* = {} --> dictionary of the options for the * section

@note: Each section is an attribute of the waServiceConfig object and is a dictionary of option names (key) and value. Additionally each section dictionary has a special key “default” that is a boolean variable indicating if the section is set in the default or specific service configuration file.

>>> Example of section attribute
    myconfig = waServiceConfig("/services","/services/myservice")
    print myconfig.serviceurl
    {'default': True, 'post': 'http://localhost:8099', 'get': 'http://localhost:8099'}
delete(section)

returns the requested section as a dictionary

@param section: configuration section @type section: C{string}

get(section)

returns the requested section as a dictionary

@param section: configuration section @type section: C{string}

put(section, option, value)

put new value to given option in given section

@param section: configuration section @type section: C{string} @param option: configuration option @type option: C{string} @param value: configuration value @type section: C{value}

save()

save current configuration to appropriate files

walib.databaseManager module

class walib.databaseManager.Database

Connect to a database

closeConnection()

Close a database connection

dbName = None
getConnection()

Return a database connection

host = None
password = None
port = None
user = None
class walib.databaseManager.PgDB(user, password, dbName, host='localhost', port='5433')

Bases: walib.databaseManager.Database

Connect to a PostgreSQL database

commitTransaction()

Commit current transaction

execute(sql, par=None)

Execute an sql statement

executeInTransaction(sql, par=None)

Execute an sql statement in an open session

host = None
insertMany(sql, dict)

Insert many values at once

mogrify(sql, par=None)

Mogrify an sql statement (print >> sys.stderr, the actual sql query that will be executed)

rollbackTransaction()

Rollback current transaction

select(sql, par=None)

Execute a select statement

setTimeTZ(tz)

Set the database Time Zone for this connection:

@param tz: object that define the Time Zone

Note

The input parameter can be af differents types: 1. A String that can be handled by postgresql (see Time Zone at http://www.postgresql.org/docs/current/static/sql-set.html) 2. An integer, for instance -7. The time zone 7 hours west from UTC (equivalent to PDT / -07:00). Positive values are east from UTC. 3. A datetime with timezone information

walib.procedure module

class walib.procedure.Procedure(serviceconf=None)
loadDICT(describeSensorObj)

Create the the self.data object representing the istSOS SensorML from a json elemet

@param json: a json describeSensor object

loadJSON(describeSensorObj)

Create the the self.data object representing the istSOS SensorML from a json elemet

@param json: a json describeSensor object

loadXML(xml)

Create the the self.data object representing the istSOS SensorML from an XML elemet

@param json: a json describeSensor object (xml string or xml file full path)

toJSON()

Return the Json that represent the self.data object as L{string}

toRegisterSensor(indent=False)

Create a SOS register sensor request String from self.procedure object

toRegisterSensorDom(indent=False)

Create a SOS register sensor request DOM element from self.procedure object

toXML(indent=False)

Return the SensorML that represent the self.data object as L{string}

walib.procedure.parse_and_get_ns(file)

walib.resource module

exception walib.resource.ServiceNotFound(message, service)

Bases: exceptions.Exception

class walib.resource.waResource(waEnviron, loadjson=True)

Bases: object

Base class for istSOS Web Admin REST operations

checkAuthorization()
executeDelete()

base method to execute DELETE request

executeGet()

base method to execute GET request

executePost()

base method to execute POST request

executePut()

base method to execute PUT request

getMime()
getResponse()
setData(data)

Set data in response

setException(msg)

Set exception message in response

setLog(log)

set message in log

setMessage(msg)

Set message in response

validateDelete()

base method to validate DELETE request

validateGet()

base method to validate GET request

validatePost()

base method to validate POST request

validatePut()

base method to validate PUT request

class walib.resource.waResourceAdmin(waEnviron, loadjson=True)

Bases: walib.resource.waResource

Extension class of istSOS Web Admin REST operations that manages Wab Admin Configuration

class walib.resource.waResourceConfigurator(waEnviron, loadjson=True)

Bases: walib.resource.waResourceService

executeDelete()

Execute operation DELETE for on service configuration sections

@note: it does not work on default service

executeGet()

Execute operation GET for on service configuration sections

executePut(json=None)

Execute operation PUT for on service configuration sections and return new values

validate()
class walib.resource.waResourceService(waEnviron, service=None, loadjson=True)

Bases: walib.resource.waResourceAdmin

checkAuthorization()

walib.resourceFactory module

walib.resourceFactory.initResource(waEnviron)

walib.sqlschema module

walib.utils module

class walib.utils.FakeConfig

Bases: object

class walib.utils.Object

Bases: object

walib.utils.encodeobject(obj, encoding='utf-8')
walib.utils.getFoiNamesList(pgdb, service, offering=None)

Return the list of observed properties

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param offering: filter procedures by this offering name @type offering: C{string} or C{None} @return: C{list} of C{dict} with observed property C{id} and C{name} keys

>>> Return example:
    [
        { "id":1,"name":"urn:ogc:def:parameter:x-istsos:1.0:lake:water:height"},
        { "id":2,"name":"urn:ogc:def:parameter:x-istsos:1.0:meteo:air:rainfall"}
    ]
walib.utils.getGeoJSONFromProcedure(pgdb, service, procedure, epsg)
>>> Return example:
    {"type":"Point","coordinates":[8.961270000000001,46.027230000000003,344.100000000000023]}
walib.utils.getObsPropNamesList(pgdb, service, offering=None)

Return the list of observed properties

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param offering: filter procedures by this offering name @type offering: C{string} or C{None} @return: C{list} of C{dict} with observed property C{id} and C{name} keys

>>> Return example:
    [
        { "id":1,"name":"urn:ogc:def:parameter:x-istsos:1.0:lake:water:height"},
        { "id":2,"name":"urn:ogc:def:parameter:x-istsos:1.0:meteo:air:rainfall"}
    ]
walib.utils.getObservationPeriod(pgdb, service, procedures)

Return the list of procedures with observation periods

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param procedures: procedures @type procedure: C{list} of C{string} @return: C{list} of C{dict} with procedure, stime (start time) and etime (end time) keys

>>> Return example:
    [
        { "procedure":"P_TRE","stime":"2000-12-31T23:00:00Z", "etime":"2012-12-31T23:00:00Z"},
        { "procedure":"P_ BOD","stime":"1986-12-31T23:00:00Z", "etime":"2012-12-31T23:00:00Z"}
    ]
walib.utils.getObservedPropertiesFromProcedure(pgdb, service, procedure)

Return the list of observed properties related to the given procedure

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param procedureID: filter procedure id @type procedure: C{string} or C{None} @return: C{list} of C{dict} with observed property C{id} and C{name} keys

>>> Return example:
    [
        { "id":1,"def":"urn:ogc:def:parameter:x-istsos:1.0:lake:water:height", "name":"lake-water-height"},
        { "id":2,"def":"urn:ogc:def:parameter:x-istsos:1.0:meteo:air:rainfall", "name":"lake-air-rainfall"}
    ]
walib.utils.getOfferingDetailsList(pgdb, service)

Return the list of offerings details for a given istsos service connection

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @return: C{list} of C{dict} with offering C{id} and C{name} keys

>>> Return example:
    [
        {"name": "temperature","description": "descrizione 3","procedures": 12,"expiration": "22.12.2012","active": true},
        {"name": "water","description": "descrizione 3","procedures": 22,"expiration": "22.12.2012","active": true},
        {"name": "air","description": "descrizione 3","procedures": 3,"expiration": "22.12.2012","active": true}
    ]
walib.utils.getOfferingNamesList(pgdb, service)

Return the list of offerings for a give istsos service connection

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @return: C{list} of C{dict} with offering C{id} and C{name} keys

>>> Return example:
    [
        { "id":1,"name":"temporary"},
        { "id":2,"name":"water"},
        { "id":3,"name":"air"}
    ]
walib.utils.getOfferingsFromProcedure(pgdb, service, procedure)

Return the list of offerings related to the given procedure

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param procedureID: filter procedure id @type procedure: C{string} or C{None} @return: C{list} of C{dict} with observed property C{id} and C{name} keys

>>> Return example:
    [
        { "id":1,"name":"urn:ogc:def:parameter:x-istsos:1.0:lake:water:height"},
        { "id":2,"name":"urn:ogc:def:parameter:x-istsos:1.0:meteo:air:rainfall"}
    ]
walib.utils.getProcedureNamesList(pgdb, service, offering=None, observationType=None, procedure=None)

Return the list of procedures:

The list can be filtered by offering and/or observationType

@param pgdb: service connection @type pgdb: L{wa.databaseManager.PgDB} object @param service: service name @type service: L{string} @param offering: filter procedures by this offering name @type offering: C{string} or C{None} @type observationType: C{string} or C{None} @return: C{list} of C{dict} with procedure C{id} and C{name} keys

>>> Return example:
    [
        {
          "id":1,
          "name":"Chiasso",
          "description": "",
          "assignedid": "1234",
          "sensortype": "in-situ-fixed",
          "samplingTime": {
            "beginposition": "2015-10-08T02:56:16+01",
            "endposition": "2015-10-08T08:56:16+01"
          }
        },
        {...}
    ]
walib.utils.getServiceList(servicepath, listonly=False)

Return the list of istsos services

@param servicepath: path to service folder @param listonly: define if only service list is requested (optional - default L{False}) @param type: L{boolean} @return: return a list of services

>>> Return example with listonly==True :
    [name1,name2,...]
>>> Return example with listonly==False:
    [
        {"service":name1,"path":path1},
        {"service":name1,"path":path1},
        ...
    ]
walib.utils.preventInjection(sql)

Parse given sql with regex for possible malicious sql ignection

@param sql: text to parse @param type: L{string} @return: L{True} if no malicious sql ingnection was detected

walib.utils.to_unicode_or_bust(obj, encoding='utf-8')
walib.utils.valid_NCName(name)
walib.utils.validateJsonConstraint(constraint)
Permitted conigurations:
{“role”:”urn:ogc:def:classifiers:x-istsos:1.0:qualityIndexCheck:level0”,”min”:”10”} {“role”:”urn:ogc:def:classifiers:x-istsos:1.0:qualityIndexCheck:level0”,”max”:”10”} {“role”:”urn:ogc:def:classifiers:x-istsos:1.0:qualityIndexCheck:level0”,”interval”:[“-10”,”10”]} {“role”:”urn:ogc:def:classifiers:x-istsos:1.0:qualityIndexCheck:level0”,”valueList”:[“1”,”2”,”3”,”4”,”5”,”6”]}
walib.utils.validatedb(user, password, dbname, host, port=5432, service=None)

Validate a service db connection parameters

@param user: user name used to authenticate @param password: password used to authenticate @param dbname: the database name (only in dsn string) @param host: database host address @param port: onnection port number (optional - defaults to 5432) @param service: service name that correspond with associated database schema (optional) @return: L{True} if connection could be estabished and the schema found (only if schema is provided)

walib.utils.verifyxmlservice(url, waEnviron)

walib.wa_version module

Module contents