Skip to content

Commit

Permalink
Merged develop to master
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Aug 10, 2016
2 parents e0a49bd + d7f358f commit 3bb4f3a
Show file tree
Hide file tree
Showing 406 changed files with 35,006 additions and 19,912 deletions.
51 changes: 24 additions & 27 deletions .travis.yml
@@ -1,3 +1,13 @@
services:
- docker

env:
global:
- ON_TRAVIS=true
matrix:
#- QGIS_VERSION_TAG=release-2_8
- QGIS_VERSION_TAG=release-2_14

language: python

cache:
Expand All @@ -23,42 +33,29 @@ addons:
- python-software-properties

before_install:
- sudo apt-get -qq -y update
#- docker pull elpaso/qgis-testing-environment:latest
#- docker pull elpaso/qgis-testing-environment:release-2_8
#- docker pull elpaso/qgis-testing-environment:release-2_14
- docker pull elpaso/qgis-testing-environment:${QGIS_VERSION_TAG}

install:
# - sudo apt-get install -y software-properties-common
# - sudo add-apt-repository http://qgis.org/debian-ltr # for QGIS LTR
- sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable # for QGIS
- sudo apt-get update
- sudo apt-get install -y --force-yes qgis python-qgis pyflakes python-scientific
- pip install coverage
- pip install nosexcover
- pip install nose
- pip install beautifulsoup
- pip install --upgrade pip
- pip install --upgrade pep8
- pip install --upgrade pylint
- pip install scrutinizer-ocular
- echo "Checking out test data at" `date`
- make testdata
- docker run -d --name qgis-testing-environment -v ${TRAVIS_BUILD_DIR}_data:/inasafe_data -v ${TRAVIS_BUILD_DIR}:/tests_directory -e ON_TRAVIS=${ON_TRAVIS} -e DISPLAY=:99 elpaso/qgis-testing-environment:${QGIS_VERSION_TAG}
- sleep 10
- docker exec -it qgis-testing-environment sh -c "qgis_setup.sh inasafe"
# TEMPORARY HACK
- docker exec -it qgis-testing-environment sh -c "cp /tests_directory/qgis_testrunner.sh /usr/bin/qgis_testrunner.sh"
- docker exec -it qgis-testing-environment sh -c "chmod 777 /usr/bin/qgis_testrunner.sh"

before_script:
- echo "Build starting on " `date`
- export QGIS_PREFIX_PATH=/usr
- export PYTHONPATH=${QGIS_PREFIX_PATH}/share/qgis/python/:${QGIS_PREFIX_PATH}/share/qgis/python/plugins:`pwd`
- echo "PYTHONPATH:" $PYTHONPATH
- export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib
- dpkg -s qgis | grep 'Version'
- echo "InaSAFE Headless configuration"
- export CELERY_ALWAYS_EAGER=True
- cp headless/celeryconfig_sample.py headless/celeryconfig.py
- docker exec -it qgis-testing-environment sh -c "ln -s /tests_directory /root/.qgis2/python/plugins/inasafe"

script:
- make pep8
# - make pylint # disable it until we make it works in Travis.
- xvfb-run --server-args="-screen 0, 1024x768x24" nosetests -A 'not slow' -v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe safe
# disable below tests until we make headless works in Travis
# - xvfb-run --server-args="-screen 0, 1024x768x24" nosetests --with-id --verbose headless
- docker exec -it qgis-testing-environment sh -c "qgis_testrunner.sh test_suite.test_package"
#- xvfb-run --server-args="-screen 0, 1024x768x24" nosetests -v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe safe

notifications:
irc:
Expand All @@ -71,7 +68,7 @@ notifications:
- https://webhooks.gitter.im/e/a021ad05fffeac7b0a92L
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: always # options: [always|never|change] default: always
on_start: always # options: [always|never|change] default: always

email:
- tim@kartoza.com
Expand Down
451 changes: 451 additions & 0 deletions CHANGELOG

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion Makefile
Expand Up @@ -24,7 +24,7 @@ ALL := $(NONGUI) $(GUI) # Would like to turn this into comma separated list usi

# LOCALES = space delimited list of iso codes to generate po files for
# Please dont remove en here
LOCALES = en id fr
LOCALES = en id fr vi es_ES

default: quicktest

Expand All @@ -50,6 +50,7 @@ test-translations:
@python scripts/missing_translations.py `pwd` fr
@python scripts/missing_translations.py `pwd` af
@python scripts/missing_translations.py `pwd` es_ES
@python scripts/missing_translations.py `pwd` vi


translation-stats:
Expand Down Expand Up @@ -297,6 +298,23 @@ indent:
python /usr/share/doc/python2.7/examples/Tools/scripts/reindent.py *.py


##########################################################
#
# A little helper to trigger a nightly build and an
# experimental build on the InaSAFE server.
#
# You need to have the correct ssh configs and keys set
# up in order for this to work.
#
##########################################################

build-nightlies:
@echo "Building nightlies"
@ssh inasafe-docker /home/data/experimental.inasafe.org/build_nightly_from_host.sh
@ssh inasafe-docker /home/data/nightly.inasafe.org/build_nightly_from_host.sh
@rsync -av inasafe-docker:/home/data/experimental.inasafe.org ../
@rsync -av inasafe-docker:/home/data/nightly.inasafe.org ../

##########################################################
#
# Make targets specific to Docker go below this point
Expand Down
15 changes: 8 additions & 7 deletions README.md
@@ -1,7 +1,7 @@
InaSAFE
=======

[![InaSAFE Screenshot](http://inasafe.org/wp-content/uploads/2015/02/about-screenshot14.png)](http://inasafe.org)
[![InaSAFE Screenshot](http://inasafe.org/wp-content/uploads/2015/02/about-screenshot14.png)](http://www.inasafe.org)

InaSAFE is free software that allows disaster managers to study realistic
natural hazard impact scenarios for better planning, preparedness and
Expand All @@ -10,7 +10,7 @@ response activities. InaSAFE is a plugin for [QGIS](http://qgis.org).
For more information about InaSAFE and its documentation please visit [inasafe.org] (http://www.inasafe.org).

The latest source code is available at
[https://github.com/AIFDR/inasafe](https://github.com/AIFDR/inasafe),
[https://github.com/inasafe/inasafe](https://github.com/inasafe/inasafe),
which contains modules for risk calculations, GIS functionality and
functions for impact modelling.

Expand Down Expand Up @@ -39,7 +39,7 @@ Quick Installation Guide
========================

You first need to have [QGIS](http://qgis.org/) installed. Grab your free
copy from [the QGIS download page](http://download/qgis.org).
copy from [the QGIS download page](http://download.qgis.org).

To install the InaSAFE plugin, use the plugin manager in
[QGIS](http://qgis.org):
Expand All @@ -58,7 +58,7 @@ We work under the philosophy that stakeholders should have access to the
development and source code, and be able to participate in every level of the
project - we invite comments, suggestions and contributions. See
[our milestones list](https://github.com/AIFDR/inasafe/issues/milestones) and
[our open issues list](https://github.com/AIFDR/inasafe/issues?page=1&state=open)
[our open issues list](https://github.com/inasafe/inasafe/issues?q=is%3Aopen+is%3Aissue+no%3Amilestone)
for known bugs and outstanding tasks. You can also chat live with our developers
and community members using the link below.

Expand All @@ -84,7 +84,7 @@ History
http://www.unisdr.org/we/inform/events/23540) where it was demonstrated to
the then president of Indonesia, Susilo Bambang Yudhoyono who praised the project.
* On 30 Jan 2013, InaSAFE was awarded the prestigious [Black Duck Open Source.
Rookie of the Year Award] (https://www.blackducksoftware.com/news/releases/black-duck-announces-2012-open-source-rookies-year-winners).
Rookie of the Year Award] (https://www.blackducksoftware.com/open-source-rookies).
* Version 2.0 of InaSAFE was released in January, 2014.
* Version 3.0 was released in March 2015 which added support
for using the QGIS API within impact functions.
Expand Down Expand Up @@ -138,9 +138,10 @@ such damages.

Thank you
=========
[![PyCharm](https://cloud.githubusercontent.com/assets/1421861/16826865/4cde910c-49ab-11e6-95ae-48cf21f3a69f.png)]
(https://www.jetbrains.com/pycharm)

We use [![PyCharm](https://www.jetbrains.com/pycharm/docs/logo_pycharm.png)]
(https://www.jetbrains.com/pycharm) for our python development work
We use [PyCharm] (https://www.jetbrains.com/pycharm) for our python development work

JetBrains kindly sponsor the licenses for InaSAFE under their 'free for
open source projects' programme. Please support them by buying a professional
Expand Down
70 changes: 44 additions & 26 deletions bin/inasafe.py
Expand Up @@ -15,6 +15,7 @@
cli: command line interface
.. versionadded:: 3.2
"""
import shutil

__author__ = 'Jannes Engelbrecht'
__date__ = '16/04/15'
Expand All @@ -32,11 +33,15 @@
QgsMapLayerRegistry,
QgsCoordinateReferenceSystem)

from safe.impact_functions import register_impact_functions

from safe.test.utilities import get_qgis_app
# make sure this line executes first
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app()

from safe.impact_functions.loader import register_impact_functions
from safe.impact_functions.impact_function_manager import ImpactFunctionManager
from safe.report.impact_report import ImpactReport
from safe.storage.utilities import safe_to_qgis_layer
from safe.test.utilities import get_qgis_app
from safe.utilities.gis import qgis_version, validate_geo_array
from safe.utilities.keyword_io import KeywordIO
from safe.utilities.osm_downloader import download
Expand All @@ -49,7 +54,6 @@
for delta in usage_file:
usage += delta
LOGGER = logging.getLogger('InaSAFE')
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app()


class CommandLineArguments(object):
Expand Down Expand Up @@ -177,13 +181,16 @@ def join_if_relative(path_argument):
return os.path.abspath(path_argument)


def get_layer(layer_path):
def get_layer(layer_path, layer_base=None):
"""Get layer from path.
.. versionadded:: 3.2
.. versionadded:: 3.3
:param layer_path: User inputs.
:type layer_path: CommandLineArguments
:param layer_path: layer full name
:type layer_path: str
:param layer_base: layer base name (title)
:type layer_base: str
:returns: Vector or Raster layer depending on input arguments.
:rtype: QgsVectorLayer, QgsRasterLayer
Expand All @@ -192,17 +199,18 @@ def get_layer(layer_path):
"""
layer = None
try:
if os.path.splitext(layer_path)[1] == '.shp':
layer_base = join_if_relative(layer_path)
layer_path = join_if_relative(layer_path)
basename, ext = os.path.splitext(os.path.basename(layer_path))
if not layer_base:
layer_base = basename
if ext == '.shp':
layer = QgsVectorLayer(
layer_base, 'cli_vector_hazard', 'ogr')
elif os.path.splitext(layer_path)[1] in \
['.asc', '.tif', '.tiff']:
layer_base = join_if_relative(layer_path)
layer_path, layer_base, 'ogr')
elif ext in ['.asc', '.tif', '.tiff']:
layer = QgsRasterLayer(
layer_base, 'cli_raster_hazard')
layer_path, layer_base)
else:
print "Unknown filetype " + layer_path
print "Unknown filetype " + layer_base
if layer is not None and layer.isValid():
print "layer is VALID"
else:
Expand All @@ -227,7 +235,7 @@ def get_hazard(arguments):
:raises: Exception
"""
return get_layer(arguments.hazard)
return get_layer(arguments.hazard, 'Hazard Layer')


def get_exposure(arguments):
Expand All @@ -243,7 +251,7 @@ def get_exposure(arguments):
:raises: Exception
"""
return get_layer(arguments.exposure)
return get_layer(arguments.exposure, 'Exposure Layer')


def impact_function_setup(
Expand Down Expand Up @@ -334,20 +342,19 @@ def build_report(cli_arguments):
"""
try:
LOGGER.info('Building a report')
basename, ext = os.path.splitext(cli_arguments.output_file)
if ext == '.shp':
impact_layer = QgsVectorLayer(
cli_arguments.output_file, 'Impact Layer', 'ogr')
elif ext == '.tif':
impact_layer = QgsRasterLayer(
cli_arguments.output_file, 'Impact Layer')
impact_layer = get_layer(cli_arguments.output_file, 'Impact Layer')
hazard_layer = get_layer(cli_arguments.hazard, 'Hazard Layer')
layer_registry = QgsMapLayerRegistry.instance()
layer_registry.removeAllMapLayers()
extra_layers = [hazard_layer]
layer_registry.addMapLayer(impact_layer)
layer_registry.addMapLayers(extra_layers)
CANVAS.setExtent(impact_layer.extent())
CANVAS.refresh()
report = ImpactReport(
IFACE, cli_arguments.report_template, impact_layer)
IFACE, cli_arguments.report_template, impact_layer,
extra_layers=extra_layers)
report.extent = CANVAS.fullExtent()
LOGGER.debug(os.path.splitext(cli_arguments.output_file)[0] + '.pdf')
map_path = report.print_map_to_pdf(
os.path.splitext(cli_arguments.output_file)[0] + '.pdf')
Expand All @@ -372,7 +379,7 @@ def write_results(cli_arguments, impact_layer):
:type cli_arguments: CommandLineArguments
:param impact_layer: Analysis result used to produce file.
:type impact_layer: QgsVectorLayer
:type impact_layer: Vector
:raises: Exception
"""
Expand All @@ -388,7 +395,18 @@ def write_results(cli_arguments, impact_layer):
else:
ext = '.shp'
abs_path += ext

# RMN: copy impact data json
# new feature in InaSAFE 3.4
source_base_name, _ = os.path.splitext(impact_layer.filename)
impact_data_json_source = '%s.json' % source_base_name
if os.path.exists(impact_data_json_source):
shutil.copy(
impact_data_json_source,
'%s.json' % basename)

impact_layer.write_to_file(abs_path)

except Exception as exception:
print exception.message
raise RuntimeError(exception.message)
Expand Down

0 comments on commit 3bb4f3a

Please sign in to comment.