Beispiel #1
0
def start(args, kill = None):

    from pywps import configuration
    # TODO: the config file should be "global" to a single server instance and not across all
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pywps.cfg")
    configuration.load_configuration(config_file)
    rest_url = '/wpsadmin'

    processes = [
        FeatureCount(),
        SayHello(),
        Centroids(),
        UltimateQuestion(),
        Sleep(),
        Buffer(),
        Area(),
        Box()
    ]

    # List of servers to start up
    server_list = [
        Server(processes=processes, host='0.0.0.0', port=5001, config_file=config_file),
        Server(processes=processes, host='0.0.0.0', port=5002)
    ]

    platform_name = ""
    try:
        import platform
        platform_name = platform.system()
    except ImportError, ie:
        platform_name = "Windows"
Beispiel #2
0
def start(args, kill = None):
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pywps.cfg")

    processes = [
        FeatureCount(),
        SayHello(),
        Centroids(),
        UltimateQuestion(),
        Sleep(),
        Buffer(),
        Area(),
        Box(),
        Warp()
    ]

    s = Server(processes=processes, config_file=config_file)

    # TODO: need to spawn a different process for different server
    if args.waitress:
        import waitress
        from pywps import configuration

        configuration.load_configuration(config_file)
        host = configuration.get_config_value('wps', 'serveraddress').split('://')[1]
        port = int(configuration.get_config_value('wps', 'serverport'))

        waitress.serve(s.app, host=host, port=port)
    else:
        s.run()
Beispiel #3
0
def start(args, kill=None):
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               "pywps.cfg")

    processes = [
        FeatureCount(),
        SayHello(),
        Centroids(),
        UltimateQuestion(),
        Sleep(),
        Buffer(),
        Area(),
        Box(),
        Warp()
    ]

    s = Server(processes=processes, config_file=config_file)

    # TODO: need to spawn a different process for different server
    if args.waitress:
        import waitress
        from pywps import configuration

        configuration.load_configuration(config_file)
        host = configuration.get_config_value('wps',
                                              'serveraddress').split('://')[1]
        port = int(configuration.get_config_value('wps', 'serverport'))

        waitress.serve(s.app, host=host, port=port)
    else:
        s.run()
Beispiel #4
0
 def setUp(self):
     configuration.load_configuration()
     configuration.CONFIG.set('server', 'language', 'en-US,fr-CA')
     self.client = client_for(
         Service(processes=[
             Process(
                 lambda: None,
                 "pr1",
                 "Process 1",
                 abstract="Process 1",
                 translations={
                     "fr-CA": {
                         "title": "Processus 1",
                         "abstract": "Processus 1"
                     }
                 },
             ),
             Process(
                 lambda: None,
                 "pr2",
                 "Process 2",
                 abstract="Process 2",
                 translations={"fr-CA": {
                     "title": "Processus 2"
                 }},
             ),
         ]))
Beispiel #5
0
    def __init__(self, host=None, port=None, debug=False, processes=[], config_file=None):
        self.app = flask.Flask(__name__)

        # Load config files and override settings if any file specified
        if config_file:
            configuration.load_configuration(config_file)
            self.host = configuration.get_config_value('wps', 'serveraddress').split('://')[1]
            self.port = int(configuration.get_config_value('wps', 'serverport'))

        # Override config host and port if they are passed to the constructor
        if host:
            self.host = host
        if port:
            self.port = port
        self.debug = debug

        self.output_url = configuration.get_config_value('server', 'outputUrl')
        self.output_path = configuration.get_config_value('server', 'outputPath')
        self.temp_path = configuration.get_config_value('server', 'tempPath')

        # check if in the configuration file specified directory exists otherwise create it
        try:
            if not os.path.exists(self.temp_path):
                os.makedirs(self.temp_path)
                print('%s does not exist. Creating it.' % self.temp_path)
            if not os.path.exists(self.output_path):
                os.makedirs(self.output_path)
                print('%s does not exist. Creating it.' % self.output_path)
        except Exception as e:
            raise NoApplicableCode('File error: Could not create folder. %s' % e)

        self.processes = processes
        self.service = Service(processes=self.processes)
Beispiel #6
0
 def _run_job(self, filename):
     job = Job.load(filename)
     # init config
     if 'PYWPS_CFG' in os.environ:
         config.load_configuration(os.environ['PYWPS_CFG'])
     # update PATH
     os.environ['PATH'] = "{0}:{1}".format(
         config.get_config_value('processing', 'path'),
         os.environ.get('PATH'))
     # cd into workdir
     os.chdir(job.workdir)
     # init logger ... code copied from app.Service
     if config.get_config_value('logging',
                                'file') and config.get_config_value(
                                    'logging', 'level'):
         LOGGER.setLevel(
             getattr(logging, config.get_config_value('logging', 'level')))
         if not LOGGER.handlers:  # hasHandlers in Python 3.x
             fh = logging.FileHandler(
                 config.get_config_value('logging', 'file'))
             fh.setFormatter(
                 logging.Formatter(
                     config.get_config_value('logging', 'format')))
             LOGGER.addHandler(fh)
     else:  # NullHandler
         if not LOGGER.handlers:
             LOGGER.addHandler(logging.NullHandler())
     job.run()
Beispiel #7
0
def main():
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('-w', '--waitress', action='store_true')
    args = parser.parse_args()

    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pywps.cfg")

    processes = [
        FeatureCount(),
        SayHello(),
        Centroids(),
        UltimateQuestion(),
        Sleep(),
        Buffer(),
        Area(),
        Viewshed()
    ]

    s = Server(processes=processes, config_file=config_file)

    # TODO: need to spawn a different process for different server
    if args.waitress:
        import waitress
        from pywps import configuration

        configuration.load_configuration(config_file)
        host = configuration.get_config_value('wps', 'serveraddress').split('://')[1]
        port = int(configuration.get_config_value('wps', 'serverport'))

        waitress.serve(s.app, host=host, port=port)
    else:
        s.run()
Beispiel #8
0
def test_s3_html_chart_upload():
    config.load_configuration(TEST_CFG)
    bucket = config.get_config_value("s3", "bucket")
    region = config.get_config_value("s3", "region")
    location = {'LocationConstraint': region}
    client = boto3.client("s3", region_name=region)
    client.create_bucket(Bucket=bucket, CreateBucketConfiguration=location)
    upload_chart_html_to_S3(TEST_CHART, "abcd")
Beispiel #9
0
def config_grass(gisbase):
    """Configure PyWPS to allow GRASS commands."""
    conf = configparser.ConfigParser()
    conf.add_section('grass')
    conf.set('grass', 'gisbase', gisbase)
    conf.set('grass', 'gui', 'text')

    _, conf_path = tempfile.mkstemp()
    with open(conf_path, 'w') as c:
        conf.write(c)

    config.load_configuration(conf_path)
Beispiel #10
0
def config_grass(gisbase):
    """Configure PyWPS to allow GRASS commands."""
    conf = configparser.ConfigParser()
    conf.add_section('grass')
    conf.set('grass', 'gisbase', gisbase)
    conf.set('grass', 'gui', 'text')

    _, conf_path = tempfile.mkstemp()
    with open(conf_path, 'w') as c:
        conf.write(c)

    config.load_configuration(conf_path)
Beispiel #11
0
    def __init__(self, cfgfiles=None):
        global LOGGER

        config.load_configuration(cfgfiles)

        LOGGER = get_logger(file=config.get_config_value('logging', 'file'),
                            level=config.get_config_value('logging', 'level'),
                            format=config.get_config_value(
                                'logging', 'format'))

        self.max_time = int(config.get_config_value('jobqueue', 'pause'))
        self.maxparallel = int(
            config.get_config_value('server', 'parallelprocesses'))
Beispiel #12
0
    def __init__(self, processes=[], cfgfile=None):
        self.processes = {p.identifier: p for p in processes}

        if cfgfile:
            config.load_configuration(cfgfile)

        if config.get_config_value('server', 'logfile') and config.get_config_value('server', 'loglevel'):
            LOGGER.setLevel(getattr(logging, config.get_config_value('server', 'loglevel')))
            msg_fmt = '%(asctime)s] [%(levelname)s] file=%(pathname)s line=%(lineno)s module=%(module)s function=%(funcName)s %(message)s'
            fh = logging.FileHandler(config.get_config_value('server', 'logfile'))
            fh.setFormatter(logging.Formatter(msg_fmt))
            LOGGER.addHandler(fh)
        else:  # NullHandler
            LOGGER.addHandler(logging.NullHandler())
Beispiel #13
0
    def __init__(self, processes=[], cfgfiles=None):
        self.processes = {p.identifier: p for p in processes}

        if cfgfiles:
            config.load_configuration(cfgfiles)

        if config.get_config_value('server', 'logfile') and config.get_config_value('server', 'loglevel'):
            LOGGER.setLevel(getattr(logging, config.get_config_value('server', 'loglevel')))
            msg_fmt = '%(asctime)s] [%(levelname)s] file=%(pathname)s line=%(lineno)s module=%(module)s function=%(funcName)s %(message)s'
            fh = logging.FileHandler(config.get_config_value('server', 'logfile'))
            fh.setFormatter(logging.Formatter(msg_fmt))
            LOGGER.addHandler(fh)
        else:  # NullHandler
            LOGGER.addHandler(logging.NullHandler())
Beispiel #14
0
Datei: cli.py Projekt: tlvu/pywps
def get_host(cfgfiles=None):
    configuration.load_configuration(cfgfiles)
    url = configuration.get_config_value('server', 'url')
    url = url or 'http://localhost:5000/wps'

    click.echo("starting WPS service on {}".format(url))

    parsed_url = urlparse(url)
    if ':' in parsed_url.netloc:
        host, port = parsed_url.netloc.split(':')
        port = int(port)
    else:
        host = parsed_url.netloc
        port = 80
    return host, port
Beispiel #15
0
    def __init__(self, processes=[], cfgfiles=None):
        # ordered dict of processes
        self.processes = OrderedDict((p.identifier, p) for p in processes)

        if cfgfiles:
            config.load_configuration(cfgfiles)

        if config.get_config_value('logging', 'file') and config.get_config_value('logging', 'level'):
            LOGGER.setLevel(getattr(logging, config.get_config_value('logging', 'level')))
            if not LOGGER.handlers:  # hasHandlers in Python 3.x
                fh = logging.FileHandler(config.get_config_value('logging', 'file'))
                fh.setFormatter(logging.Formatter(config.get_config_value('logging', 'format')))
                LOGGER.addHandler(fh)
        else:  # NullHandler | StreamHandler
            if not LOGGER.handlers:
                LOGGER.addHandler(logging.NullHandler())
Beispiel #16
0
    def __init__(self, processes=[], cfgfiles=None):
        # ordered dict of processes
        self.processes = OrderedDict((p.identifier, p) for p in processes)

        if cfgfiles:
            config.load_configuration(cfgfiles)

        if config.get_config_value('logging', 'file') and config.get_config_value('logging', 'level'):
            LOGGER.setLevel(getattr(logging, config.get_config_value('logging', 'level')))
            if not LOGGER.handlers:  # hasHandlers in Python 3.x
                fh = logging.FileHandler(config.get_config_value('logging', 'file'))
                fh.setFormatter(logging.Formatter(config.get_config_value('logging', 'format')))
                LOGGER.addHandler(fh)
        else:  # NullHandler | StreamHandler
            if not LOGGER.handlers:
                LOGGER.addHandler(logging.NullHandler())
Beispiel #17
0
Datei: job.py Projekt: tlvu/pywps
    def _run_job(self, filename):
        global LOGGER

        job = Job.load(filename)
        # init config
        if 'PYWPS_CFG' in os.environ:
            config.load_configuration(os.environ['PYWPS_CFG'])
        # update PATH
        os.environ['PATH'] = "{0}:{1}".format(
            config.get_config_value('processing', 'path'),
            os.environ.get('PATH'))
        # cd into workdir
        os.chdir(job.workdir)
        # init logger ... code copied from app.Service
        LOGGER = get_logger(file=config.get_config_value('logging', 'file'),
                            level=config.get_config_value('logging', 'level'),
                            format=config.get_config_value(
                                'logging', 'format'))
        job.run()
Beispiel #18
0
    def __init__(self,
                 host=None,
                 port=None,
                 debug=False,
                 processes=[],
                 config_file=None):
        self.app = flask.Flask(__name__)

        # Load config files and override settings if any file specified
        if config_file:
            configuration.load_configuration(config_file)
            self.host = configuration.get_config_value(
                'wps', 'serveraddress').split('://')[1]
            self.port = int(configuration.get_config_value(
                'wps', 'serverport'))

        # Override config host and port if they are passed to the constructor
        if host:
            self.host = host
        if port:
            self.port = port
        self.debug = debug

        self.output_url = configuration.get_config_value('server', 'outputUrl')
        self.output_path = configuration.get_config_value(
            'server', 'outputPath')
        self.temp_path = configuration.get_config_value('server', 'workdir')

        # check if in the configuration file specified directory exists otherwise create it
        try:
            if not os.path.exists(self.temp_path):
                os.makedirs(self.temp_path)
                print('%s does not exist. Creating it.' % self.temp_path)
            if not os.path.exists(self.output_path):
                os.makedirs(self.output_path)
                print('%s does not exist. Creating it.' % self.output_path)
        except Exception as e:
            raise NoApplicableCode('File error: Could not create folder. %s' %
                                   e)

        self.processes = processes
        self.service = Service(processes=self.processes)
Beispiel #19
0
 def _run_job(self, filename):
     job = Job.load(filename)
     # init config
     if 'PYWPS_CFG' in os.environ:
         config.load_configuration(os.environ['PYWPS_CFG'])
     # update PATH
     os.environ['PATH'] = "{0}:{1}".format(
         config.get_config_value('processing', 'path'),
         os.environ.get('PATH'))
     # cd into workdir
     os.chdir(job.workdir)
     # init logger ... code copied from app.Service
     if config.get_config_value('logging', 'file') and config.get_config_value('logging', 'level'):
         LOGGER.setLevel(getattr(logging, config.get_config_value('logging', 'level')))
         fh = logging.FileHandler(config.get_config_value('logging', 'file'))
         fh.setFormatter(logging.Formatter(config.get_config_value('logging', 'format')))
         LOGGER.addHandler(fh)
     else:  # NullHandler
         LOGGER.addHandler(logging.NullHandler())
     job.run()
Beispiel #20
0
    def __init__(self, processes=None, cfgfiles=None):
        global LOGGER

        processes = processes or []
        config.load_configuration(cfgfiles)

        LOGGER = get_logger(file=config.get_config_value('logging', 'file'),
                            level=config.get_config_value('logging', 'level'),
                            format=config.get_config_value(
                                'logging', 'format'))

        if not processes:
            # load processes from processes_module.processes_list
            pname = config.get_config_value('server', 'processes')
            if pname:
                pmodule, plist = pname.rsplit('.', 1)
                processes = getattr(importlib.import_module(pmodule), plist)

        # ordered dict of processes
        self.processes = OrderedDict((p.identifier, p) for p in processes)
Beispiel #21
0
def load_pywps_config(container, config=None):
    # type: (AnySettingsContainer, Optional[Union[str, Dict[str, str]]]) -> ConfigParser
    """
    Loads and updates the PyWPS configuration using Weaver settings.
    """
    settings = get_settings(container)
    if settings.get("weaver.wps_configured"):
        LOGGER.debug("Using preloaded internal Weaver WPS configuration.")
        return pywps_config.CONFIG

    LOGGER.info("Initial load of internal Weaver WPS configuration.")
    pywps_config.load_configuration([])  # load defaults
    pywps_config.CONFIG.set("logging", "db_echo", "false")
    if logging.getLevelName(pywps_config.CONFIG.get("logging",
                                                    "level")) <= logging.DEBUG:
        pywps_config.CONFIG.set("logging", "level", "INFO")

    # update metadata
    LOGGER.debug("Updating WPS metadata configuration.")
    for setting_name, setting_value in settings.items():
        if setting_name.startswith("weaver.wps_metadata"):
            pywps_setting = setting_name.replace("weaver.wps_metadata_", "")
            pywps_config.CONFIG.set("metadata:main", pywps_setting,
                                    setting_value)
    # add weaver configuration keyword if not already provided
    wps_keywords = pywps_config.CONFIG.get("metadata:main",
                                           "identification_keywords")
    weaver_mode = get_weaver_configuration(settings)
    if weaver_mode not in wps_keywords:
        wps_keywords += ("," if wps_keywords else "") + weaver_mode
        pywps_config.CONFIG.set("metadata:main", "identification_keywords",
                                wps_keywords)
    # add additional config passed as dictionary of {'section.key': 'value'}
    if isinstance(config, dict):
        for key, value in config.items():
            section, key = key.split(".")
            pywps_config.CONFIG.set(section, key, value)
        # cleanup alternative dict "PYWPS_CFG" which is not expected elsewhere
        if isinstance(settings.get("PYWPS_CFG"), dict):
            del settings["PYWPS_CFG"]

    # set accepted languages aligned with values provided by REST API endpoints
    # otherwise, execute request could fail due to languages considered not supported
    languages = ", ".join(AcceptLanguage.values())
    LOGGER.debug("Setting WPS languages: [%s]", languages)
    pywps_config.CONFIG.set("server", "language", languages)

    LOGGER.debug("Updating WPS output configuration.")
    # find output directory from app config or wps config
    if "weaver.wps_output_dir" not in settings:
        output_dir = pywps_config.get_config_value("server", "outputpath")
        settings["weaver.wps_output_dir"] = output_dir
    # ensure the output dir exists if specified
    output_dir = get_wps_output_dir(settings)
    make_dirs(output_dir, exist_ok=True)
    # find output url from app config (path/url) or wps config (url only)
    # note: needs to be configured even when using S3 bucket since XML status is provided locally
    if "weaver.wps_output_url" not in settings:
        output_path = settings.get("weaver.wps_output_path", "").rstrip("/")
        if output_path and isinstance(output_path, str):
            output_url = os.path.join(get_weaver_url(settings),
                                      output_path.strip("/"))
        else:
            output_url = pywps_config.get_config_value("server", "outputurl")
        settings["weaver.wps_output_url"] = output_url
    # apply workdir if provided, otherwise use default
    if "weaver.wps_workdir" in settings:
        make_dirs(settings["weaver.wps_workdir"], exist_ok=True)
        pywps_config.CONFIG.set("server", "workdir",
                                settings["weaver.wps_workdir"])

    # configure S3 bucket if requested, storage of all process outputs
    # note:
    #   credentials and default profile are picked up automatically by 'boto3' from local AWS configs or env vars
    #   region can also be picked from there unless explicitly provided by weaver config
    # warning:
    #   if we set `(server, storagetype, s3)`, ALL status (including XML) are stored to S3
    #   to preserve status locally, we set 'file' and override the storage instance during output rewrite in WpsPackage
    #   we can still make use of the server configurations here to make this overridden storage auto-find its configs
    s3_bucket = settings.get("weaver.wps_output_s3_bucket")
    pywps_config.CONFIG.set("server", "storagetype", "file")
    # pywps_config.CONFIG.set("server", "storagetype", "s3")
    if s3_bucket:
        LOGGER.debug("Updating WPS S3 bucket configuration.")
        import boto3
        from botocore.exceptions import ClientError
        s3 = boto3.client("s3")
        s3_region = settings.get("weaver.wps_output_s3_region",
                                 s3.meta.region_name)
        LOGGER.info(
            "Validating that S3 [Bucket=%s, Region=%s] exists or creating it.",
            s3_bucket, s3_region)
        try:
            s3.create_bucket(
                Bucket=s3_bucket,
                CreateBucketConfiguration={"LocationConstraint": s3_region})
            LOGGER.info("S3 bucket for WPS output created.")
        except ClientError as exc:
            if exc.response.get("Error",
                                {}).get("Code") != "BucketAlreadyExists":
                LOGGER.error("Failed setup of S3 bucket for WPS output: [%s]",
                             exc)
                raise
            LOGGER.info("S3 bucket for WPS output already exists.")
        pywps_config.CONFIG.set("s3", "region", s3_region)
        pywps_config.CONFIG.set("s3", "bucket", s3_bucket)
        pywps_config.CONFIG.set(
            "s3", "public",
            "false")  # don't automatically push results as publicly accessible
        pywps_config.CONFIG.set(
            "s3", "encrypt",
            "true")  # encrypts data server-side, transparent from this side

    # enforce back resolved values onto PyWPS config
    pywps_config.CONFIG.set("server", "setworkdir", "true")
    pywps_config.CONFIG.set("server", "sethomedir", "true")
    pywps_config.CONFIG.set("server", "outputpath",
                            settings["weaver.wps_output_dir"])
    pywps_config.CONFIG.set("server", "outputurl",
                            settings["weaver.wps_output_url"])
    pywps_config.CONFIG.set("server", "url", get_wps_url(settings, load=False))
    settings["weaver.wps_configured"] = True
    return pywps_config.CONFIG
Beispiel #22
0
def server_url():
    config.load_configuration(cfgfiles=PYWPS_CFG)
    url = config.get_config_value("server", "url")
    return url
#!/usr/bin/env python3

import requests
import xml.etree.ElementTree as ET
from pywps.configuration import get_config_value, load_configuration
from osgeo import ogr, osr

load_configuration(['pywps.cfg'])


def parse_string(value):
    if len(value.split(sep=".")) != 3:
        raise Exception("Table name does not consist of 3 parts separated by dots.")

def get_value(node, identifier='response'):
    value = None
    try:
        xlink_key = '{http://www.w3.org/1999/xlink}href'
        po_node = node.find('{http://www.opengis.net/wps/1.0.0}ProcessOutputs')
        for n in po_node.findall('{http://www.opengis.net/wps/1.0.0}Output'):
            if n.find('{http://www.opengis.net/ows/1.1}Identifier').text == identifier:
                if identifier == 'response':
                    value = n.find('{http://www.opengis.net/wps/1.0.0}Data').text
                    break
                else:
                    ref_node = n.find('{http://www.opengis.net/wps/1.0.0}Reference')
                    value = ref_node.attrib['{http://www.w3.org/1999/xlink}href']
                    break
    except IndexError:
        raise Exception("No output value found (process probably failed)")