1 | #!/usr/bin/python |
---|
2 | |
---|
3 | import zoo |
---|
4 | |
---|
5 | import logging |
---|
6 | import logging.config |
---|
7 | import sys |
---|
8 | import errno |
---|
9 | import os |
---|
10 | import json |
---|
11 | import geojson |
---|
12 | import csv |
---|
13 | import argparse |
---|
14 | |
---|
15 | from publicamundi.data.api import * |
---|
16 | |
---|
17 | ERROR_OK = 0 |
---|
18 | ERROR_UNKNOWN = 1 |
---|
19 | |
---|
20 | def configure_logging(filename): |
---|
21 | if filename is None: |
---|
22 | print 'Logging is not configured.' |
---|
23 | else: |
---|
24 | logging.config.fileConfig(filename) |
---|
25 | |
---|
26 | def parse_query(filename, text): |
---|
27 | if not filename is None and os.path.isfile(filename): |
---|
28 | with open(filename) as query_file: |
---|
29 | return json.load(query_file, cls=ShapelyJsonDecoder, encoding='utf-8') |
---|
30 | if not text is None: |
---|
31 | return json.loads(text, cls=ShapelyJsonDecoder, encoding='utf-8') |
---|
32 | |
---|
33 | return {} |
---|
34 | |
---|
35 | def query(conf,inputs,outputs): |
---|
36 | config = { |
---|
37 | CONFIG_SQL_CATALOG : conf["data-api"]["catalog"], |
---|
38 | CONFIG_SQL_DATA : conf["data-api"]["vectorstore"], |
---|
39 | CONFIG_SQL_TIMEOUT : int(conf["data-api"]["timeout"]) * 1000 |
---|
40 | } |
---|
41 | |
---|
42 | if inputs.keys().count("timeout")>0: |
---|
43 | config["CONFIG_SQL_TIMEOUT"]=int(inputs["timeout"]["value"]) * 1000 |
---|
44 | |
---|
45 | metadata = {} |
---|
46 | |
---|
47 | configure_logging(conf["lenv"]["cwd"]+"/"+conf["lenv"]["metapath"]+"/service.ini") |
---|
48 | |
---|
49 | query_executor = QueryExecutor() |
---|
50 | result = query_executor.execute(config, parse_query(None,inputs["query"]["value"]) ) |
---|
51 | |
---|
52 | outputs["Result"]["value"]=geojson.dumps(result['data'][0], cls=ShapelyGeoJsonEncoder, encoding='utf-8') |
---|
53 | return zoo.SERVICE_SUCCEEDED |
---|
54 | |
---|