From f010a20a093007468953641fe945d3e84b8ad074 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 11 Dec 2019 21:23:45 +0100 Subject: [PATCH 01/49] Add click to requirements-dev --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index bd869515..a857e625 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ +click==7.0 flake8 Paver==1.3.4 pylint From 4b23e9bf6ebe2ef534eea77237f0597a802b2909 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Thu, 12 Dec 2019 20:52:20 +0100 Subject: [PATCH 02/49] WIP: updat import statements The new CLI will call commands from outside the package. The import statements needed to be reworked. Not proud of the solution, but I cannot think of something better now. --- GeoHealthCheck/__init__.py | 5 ++++- GeoHealthCheck/models.py | 25 ++++++++++++++++++++----- GeoHealthCheck/plugin.py | 10 ++++++++-- GeoHealthCheck/resourceauth.py | 21 +++++++++++++++++---- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/GeoHealthCheck/__init__.py b/GeoHealthCheck/__init__.py index e1614da1..7f60751f 100644 --- a/GeoHealthCheck/__init__.py +++ b/GeoHealthCheck/__init__.py @@ -27,7 +27,10 @@ # # ================================================================= -from util import read +try: + from util import read +except ImportError: + from .util import read def get_package_version(file_): diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index 1ec7d7e5..137d557e 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -38,11 +38,26 @@ from sqlalchemy.orm import deferred from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound -import util -from enums import RESOURCE_TYPES -from factory import Factory -from init import App -from resourceauth import ResourceAuth +try: + import util +except ImportError: + from GeoHealthCheck import util +try: + from enums import RESOURCE_TYPES +except ImportError: + from GeoHealthCheck.enums import RESOURCE_TYPES +try: + from factory import Factory +except ImportError: + from GeoHealthCheck.factory import Factory +try: + from init import App +except ImportError: + from GeoHealthCheck.init import App +try: + from resourceauth import ResourceAuth +except ImportError: + from GeoHealthCheck.resourceauth import ResourceAuth from wtforms.validators import Email, ValidationError from owslib.util import bind_url diff --git a/GeoHealthCheck/plugin.py b/GeoHealthCheck/plugin.py index 3534c4b3..8f38dc21 100644 --- a/GeoHealthCheck/plugin.py +++ b/GeoHealthCheck/plugin.py @@ -1,9 +1,15 @@ -from factory import Factory +try: + from factory import Factory +except ImportError: + from GeoHealthCheck.factory import Factory import logging import inspect from collections.abc import Mapping import copy -from init import App +try: + from init import App +except ImportError: + from GeoHealthCheck.init import App LOGGER = logging.getLogger(__name__) diff --git a/GeoHealthCheck/resourceauth.py b/GeoHealthCheck/resourceauth.py index ba1982eb..c7446b11 100644 --- a/GeoHealthCheck/resourceauth.py +++ b/GeoHealthCheck/resourceauth.py @@ -1,9 +1,22 @@ import json import logging -from plugin import Plugin -from factory import Factory -from util import encode, decode -from init import App +try: + from plugin import Plugin +except ImportError: + from GeoHealthCheck.plugin import Plugin +try: + from factory import Factory +except ImportError: + from GeoHealthCheck.factory import Factory +try: + from util import encode, decode +except ImportError: + from GeoHealthCheck.util import encode, decode +try: + from init import App +except ImportError: + from GeoHealthCheck.init import App + APP = App.get_app() LOGGER = logging.getLogger(__name__) From 284b50b46b8ebcb00a478662019aed1a27522a3e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Thu, 12 Dec 2019 20:53:33 +0100 Subject: [PATCH 03/49] Add first CLI commands --- ghc_cli.py | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 ghc_cli.py diff --git a/ghc_cli.py b/ghc_cli.py new file mode 100644 index 00000000..3c5d068c --- /dev/null +++ b/ghc_cli.py @@ -0,0 +1,142 @@ +# ============================================================================ +# +# Authors: Rob van Loon +# +# Copyright (c) 2019 Rob van Loon +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# ================================================================= +import click +import os + +from GeoHealthCheck.__init__ import __version__ + + +@click.command() +def cli(): + """Example thingy""" + click.echo('Hello there!') + + +@click.group() +@click.pass_context +@click.option('--verbose', '-v', is_flag=True, help='Verbose') +def cli(ctx, verbose): + ctx.ensure_object(dict) + ctx.obj['VERBOSE'] = verbose + + +@cli.command() +@click.pass_context +def version(ctx): + """Show the current version of GHC + """ + verbose_echo(ctx, 'GeoHC: get version') + click.echo(__version__) + + +@cli.command() +@click.pass_context +def create_instance(ctx): + """Create an instance of GeoHealthCheck App + + This command is a copy of `paver setup` + """ + verbose_echo(ctx, 'GeoHC: create instance') + # calling paver for the setup + # TODO: phase out paver and switch to click + os.system('paver setup') + + +@cli.command() +@click.pass_context +@click.option('--host', '-h', default='0.0.0.0', help='IP to host the app') +@click.option('--port', '-p', default=8000, help='port number to host the app') +def serve(ctx, host, port): + """ + Run the app. Press 'ctrl-c' to exit again. + + This function is a wrapper around `python GeoHealthCheck/app.py` + """ + verbose_echo(ctx, 'GeoHC: serve') + click.echo('Press ctrl-c to exit.') + os.system(f"python GeoHealthCheck/app.py {host}:{port}") + + +@cli.command() +@click.pass_context +def db_create(ctx): + """Create the GHC database + + Note: you still need to add a user + """ + verbose_echo(ctx, 'GeoHC: create db') + from GeoHealthCheck.init import App + DB = App.get_db() + DB.create_all() + DB.session.remove() + + +@cli.command() +@click.pass_context +def db_adduser(ctx): + """Add an user to the database + """ + verbose_echo(ctx, 'GeoHC: add user to database') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import User, db_commit + DB = App.get_db() + user_to_add = User('rob', 'bor', 'rob.v.loon@gmail.com', role='admin') + DB.session.add(user_to_add) + db_commit() + DB.session.remove() + + +@cli.command() +@click.pass_context +def db_drop(ctx): + verbose_echo(ctx, 'GeoHC: drop db') + #drop_db() + +@cli.command() +@click.pass_context +def db_init(ctx): + verbose_echo(ctx, 'GeoHC: init db') + +@cli.command() +@click.pass_context +def db_upgrade(ctx): + verbose_echo(ctx, 'GeoHC: upgrade db') + +@cli.command() +@click.pass_context +def db_export(ctx): + pass + +def verbose_echo(ctx, verbose_text): + if ctx.obj['VERBOSE']: + click.echo(verbose_text) + + +if __name__ == '__main__': + cli() From 84112f4919fba5d80c772856ae790b1c10c5e097 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 07:45:18 +0100 Subject: [PATCH 04/49] Add setup.py With the setup file we can install the cli command `geohc` and build eggs and wheels. --- setup.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..3632e936 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +import io +import os +from setuptools import find_packages, setup + +def read(filename, encoding='utf-8'): + """read file contents""" + full_path = os.path.join(os.path.dirname(__file__), filename) + with io.open(full_path, encoding=encoding) as fh: + contents = fh.read().strip() + return contents + +def get_package_version(): + """get version from top-level package init""" + version_file = read('VERSION') + if version_file: + return version_file + raise RuntimeError("Unable to find version string.") + +setup( + name='geohealthcheck', + version=get_package_version(), + license='MIT', + install_requires=read('requirements.txt').splitlines(), + packages=find_packages(exclude=['tests']), + include_package_data=True, + entry_points={ + 'console_scripts': [ + 'geohc=ghc_cli:cli', + ] + } +) From b648a31dbee1b66050cb9af689c7607013a0a62c Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 09:47:21 +0100 Subject: [PATCH 05/49] CLI commands for models.py Move all the models.py ... commands to the geohc cli and add deprecation warnings. --- GeoHealthCheck/models.py | 16 ++++++- ghc_cli.py | 96 +++++++++++++++++++++++++++++++++------- 2 files changed, 94 insertions(+), 18 deletions(-) diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index 137d557e..fa998232 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -30,6 +30,7 @@ import json import logging +import warnings from flask_babel import gettext as _ from datetime import datetime, timedelta from itsdangerous import TimedJSONWebSignatureSerializer as Serializer @@ -908,6 +909,8 @@ def db_commit(): if len(sys.argv) > 1: if sys.argv[1] == 'create': + warnings.warn('models.py create is deprecated since 0.8.0. Please use cli: ' + '`geohc db-create` and `geohc db-adduser`', DeprecationWarning) print('Creating database objects') DB.create_all() @@ -930,11 +933,17 @@ def db_commit(): user_to_add = User(username, password1, email1, role='admin') DB.session.add(user_to_add) db_commit() + elif sys.argv[1] == 'drop': + warnings.warn('models.py drop is deprecated since 0.8.0. Please use cli: ' + '`geohc db-drop`', DeprecationWarning) print('Dropping database objects') DB.drop_all() db_commit() + elif sys.argv[1] == 'load': + warnings.warn('models.py load is deprecated since 0.8.0. Please use cli: ' + '`geohc db-load`', DeprecationWarning) print('Load database from JSON file (e.g. tests/fixtures.json)') if len(sys.argv) > 2: file_path = sys.argv[2] @@ -958,9 +967,12 @@ def db_commit(): print('Provide path to JSON file, e.g. tests/fixtures.json') elif sys.argv[1] == 'run': - print('NOTICE: models.py no longer here.') - print('Use: python healthcheck.py or upcoming cli.py') + warnings.warn('models.py run is deprecated. Please use `python healthcheck.py`', + DeprecationWarning) + elif sys.argv[1] == 'flush': + warnings.warn('models.py flush is deprecated since 0.8.0. Please use cli: ' + '`geohc db-flush`', DeprecationWarning) flush_runs() DB.session.remove() diff --git a/ghc_cli.py b/ghc_cli.py index 3c5d068c..b8b92409 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -27,15 +27,18 @@ # # ================================================================= import click -import os from GeoHealthCheck.__init__ import __version__ -@click.command() -def cli(): - """Example thingy""" - click.echo('Hello there!') +def verbose_echo(ctx, verbose_text): + if ctx.obj['VERBOSE']: + click.echo(verbose_text) + + +def abort_if_false(ctx, _, value): + if not value: + ctx.abort() @click.group() @@ -65,7 +68,9 @@ def create_instance(ctx): verbose_echo(ctx, 'GeoHC: create instance') # calling paver for the setup # TODO: phase out paver and switch to click - os.system('paver setup') + from os import system + system('paver setup') + verbose_echo(ctx, 'GeoHC: finished creating the instance.') @cli.command() @@ -80,7 +85,8 @@ def serve(ctx, host, port): """ verbose_echo(ctx, 'GeoHC: serve') click.echo('Press ctrl-c to exit.') - os.system(f"python GeoHealthCheck/app.py {host}:{port}") + from os import system + system(f"python GeoHealthCheck/app.py {host}:{port}") @cli.command() @@ -92,36 +98,98 @@ def db_create(ctx): """ verbose_echo(ctx, 'GeoHC: create db') from GeoHealthCheck.init import App + from GeoHealthCheck.models import db_commit + verbose_echo(ctx, 'GeoHC: get database') DB = App.get_db() + verbose_echo(ctx, 'GeoHC: create all tables') DB.create_all() + db_commit() DB.session.remove() + click.echo('Database is created. Use `geohc db-adduser` to add users to the database.') @cli.command() @click.pass_context -def db_adduser(ctx): +@click.option('-u', '--user', type=str, help='username', prompt=True) +@click.option('-e', '--email', type=str, help='email address', prompt=True) +@click.option('-p', '--password', type=str, help='password', prompt=True, hide_input=True, + confirmation_prompt=True) +@click.option('-r', '--role', type=click.Choice(['admin', 'user']), prompt=True, + help='role for this user') +def db_adduser(ctx, user, email, password, role): """Add an user to the database """ verbose_echo(ctx, 'GeoHC: add user to database') from GeoHealthCheck.init import App from GeoHealthCheck.models import User, db_commit + verbose_echo(ctx, 'GeoHC: get database') DB = App.get_db() - user_to_add = User('rob', 'bor', 'rob.v.loon@gmail.com', role='admin') + verbose_echo(ctx, 'GeoHC: create user') + user_to_add = User(user, password, email, role=role) + verbose_echo(ctx, 'GeoHC: adding user to database') DB.session.add(user_to_add) db_commit() DB.session.remove() + click.echo(f'User {user} is added.') @cli.command() @click.pass_context +@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, + expose_value=False, help='Confirm dropping tables', + prompt='This will drop the tables in the database. Are you sure?') def db_drop(ctx): + """Drop the current database + """ verbose_echo(ctx, 'GeoHC: drop db') - #drop_db() + click.confirm("This will drop the tables in the database. Are you sure?", abort=True) + verbose_echo(ctx, 'User confirmed dropping tables') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import db_commit + verbose_echo(ctx, 'GeoHC: get database') + DB = App.get_db() + verbose_echo(ctx, 'GeoHC: dropping all tables') + DB.drop_all() + db_commit() + DB.session.remove() + click.echo('Database dropped all tables.') + @cli.command() @click.pass_context -def db_init(ctx): - verbose_echo(ctx, 'GeoHC: init db') +@click.option('-f', '--file', type=click.Path(), multiple=False, required=True, + help='Path to the file to load into the database. MUST be JSON.') +@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, + expose_value=False, help='Confirm dropping old content.', + prompt='WARNING: all database data will be lost. Proceed?') +def db_load(ctx, file): + """Load JSON into the database + + e.g. test/data/fixtures.json + """ + verbose_echo(ctx, 'GeoHC: load data into db') + verbose_echo(ctx, 'User confirmed loading new data and losing old data.') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import load_data + DB = App.get_db() + if file[-5:].lower() != '.json': + click.echo("File must have '.json' file extension. Aborting import.") + ctx.exit() + verbose_echo(ctx, 'Start loading file.') + load_data(file) + verbose_echo(ctx, 'Data loaded!') + DB.session.remove() + click.echo('Finished loading data.') + +@cli.command() +@click.pass_context +def db_flush(ctx): + """Flush runs: remove old data over retention date. + """ + verbose_echo(ctx, 'GeoHC: flush old runs from database.') + from GeoHealthCheck.models import flush_runs + flush_runs() + click.echo('Finished flushing old runs from database.') @cli.command() @click.pass_context @@ -133,10 +201,6 @@ def db_upgrade(ctx): def db_export(ctx): pass -def verbose_echo(ctx, verbose_text): - if ctx.obj['VERBOSE']: - click.echo(verbose_text) - if __name__ == '__main__': cli() From 7aff5b17f76125bb55d3549629e911b7723b976c Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 15:54:28 +0100 Subject: [PATCH 06/49] Move all paver commands to click --- GeoHealthCheck/models.py | 2 +- ghc_cli.py | 220 ++++++++++++++++++++++++++++++++++++++- pavement.py | 47 ++++++--- 3 files changed, 252 insertions(+), 17 deletions(-) diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index fa998232..3c44665c 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -940,7 +940,7 @@ def db_commit(): print('Dropping database objects') DB.drop_all() db_commit() - + elif sys.argv[1] == 'load': warnings.warn('models.py load is deprecated since 0.8.0. Please use cli: ' '`geohc db-load`', DeprecationWarning) diff --git a/ghc_cli.py b/ghc_cli.py index b8b92409..4ff3c865 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -41,6 +41,14 @@ def abort_if_false(ctx, _, value): ctx.abort() +def sphinx_make(): + """return what command Sphinx is using for make""" + from os import name + if name == 'nt': + return 'make.bat' + return 'make' + + @click.group() @click.pass_context @click.option('--verbose', '-v', is_flag=True, help='Verbose') @@ -85,8 +93,9 @@ def serve(ctx, host, port): """ verbose_echo(ctx, 'GeoHC: serve') click.echo('Press ctrl-c to exit.') - from os import system - system(f"python GeoHealthCheck/app.py {host}:{port}") + from os import system, chdir + chdir('GeoHealthCheck') + system(f"python app.py {host}:{port}") @cli.command() @@ -181,6 +190,7 @@ def db_load(ctx, file): DB.session.remove() click.echo('Finished loading data.') + @cli.command() @click.pass_context def db_flush(ctx): @@ -191,10 +201,216 @@ def db_flush(ctx): flush_runs() click.echo('Finished flushing old runs from database.') + +@cli.command() +@click.pass_context +def create_secret_key(ctx): + """ + Create a secret key for the application. + """ + from codecs import encode + from os import urandom + click.echo('Secret key: \'%s\'' % encode(urandom(24), 'hex').decode()) + click.echo('Copy/paste this key to set the SECRET_KEY value in instance/config_site.py') + + +@cli.command() +@click.option('-p', '--password', prompt=True, hide_input=True, help='password') +@click.pass_context +def create_hash(ctx, password): + """Create a password hash + """ + from GeoHealthCheck.util import create_hash + token = create_hash(password) + click.echo('Copy/paste the entire token below for example to set password') + click.echo(token) + + @cli.command() @click.pass_context def db_upgrade(ctx): + """Upgrade the database + """ verbose_echo(ctx, 'GeoHC: upgrade db') + from os import system, chdir + chdir('GeoHealthCheck') + system('python manage.py db upgrade') + click.echo('Upgrade DB finished.') + + +@cli.command() +@click.pass_context +def create_wsgi(ctx): + """Create an apache wsgi and conf file""" + verbose_echo(ctx, 'GeoHC: creating apache wsgi and conf files.') + import os + basedir = os.path.abspath(os.path.dirname(__file__)) + instance = '%s%sinstance' % (basedir, os.sep) + verbose_echo(ctx, 'GeoHC: Files will be created in: %s' % instance) + + wsgi_script = '%s%sGeoHealthCheck.wsgi' % (instance, os.sep) + with open(wsgi_script, 'w') as ff: + ff.write('import sys\n') + ff.write('sys.path.insert(0, \'%s\')\n' % basedir) + ff.write('from GeoHealthCheck.app import APP as application') + verbose_echo(ctx, 'GeoHC: finished wsgi script.') + + wsgi_conf = '%s%sGeoHealthCheck.conf' % (instance, os.sep) + with open(wsgi_conf, 'w') as ff: + ff.write('WSGIScriptAlias / %s%sGeoHealthCheck.wsgi\n' % (instance, os.sep)) + ff.write('\n' % (basedir, os.sep)) + ff.write('Order deny,allow\n') + ff.write('Allow from all\n') + ff.write('') + verbose_echo(ctx, 'GeoHC: finished conf file.') + + +@cli.command() +@click.pass_context +def update_docs(ctx): + """Update the spinx build of the documentation.""" + verbose_echo(ctx, 'GeoHC: start building documentation.') + + import os + import shutil + + basedir = os.path.abspath(os.path.dirname(__file__)) + static_docs = os.path.normpath('%s/GeoHealthCheck/static/docs' % basedir) + docs = os.path.normpath('%s/docs' % basedir) + + if os.path.exists(static_docs): + verbose_echo(ctx, 'GeoHC: deleting previous doc directory.') + shutil.rmtree(static_docs) + + os.chdir(docs) + make = sphinx_make() + verbose_echo(ctx, 'GeoHC: cleaning old documentation.') + os.system('%s clean' % make) + verbose_echo(ctx, 'GeoHC: building new documentation.') + os.system('%s html' % make) + os.chdir(basedir) + + verbose_echo(ctx, 'GeoHC: copying documentation to build folder.') + source_html_dir = os.path.normpath('%s/docs/_build/html' % basedir) + shutil.copytree(source_html_dir, static_docs) + click.echo('GeoHC: finished refreshing documentation.') + + +@cli.command() +@click.pass_context +def clean(ctx): + """Clean Environment + """ + import os + import shutil + import tempfile + + basedir = os.path.abspath(os.path.dirname(__file__)) + static_docs = os.path.normpath('%s/GeoHealthCheck/static/docs' % basedir) + static_lib = os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir) + tmp = os.path.normpath(tempfile.mkdtemp()) + + try: + shutil.rmtree(static_lib) + verbose_echo(ctx, 'GeoHC: removed %s' % static_lib) + except FileNotFoundError: + pass + try: + shutil.rmtree(tmp) + verbose_echo(ctx, 'GeoHC: removed temp directory: %s' % tmp) + except FileNotFoundError: + pass + try: + shutil.rmtree(static_docs) + verbose_echo(ctx, 'GeoHC: removed %s' % static_docs) + except FileNotFoundError: + pass + + click.echo('GeoHC: finished cleaning environment.') + + +@cli.command() +@click.pass_context +def extract_translations(ctx): + """extract translations wrapped in _() or gettext()""" + verbose_echo(ctx, 'GeoHC: extracting translations') + import os + + pot_dir = os.path.normpath('GeoHealthCheck/translations/en/LC_MESSAGES') + verbose_echo(ctx, 'GeoHC: Translations directory: %s' % pot_dir) + if not os.path.exists(pot_dir): + pot_dir.makedirs() + + basedir = os.path.abspath(os.path.dirname(__file__)) + base_pot = os.path.normpath('%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % basedir) + verbose_echo(ctx, 'GeoHC: starting translation') + os.system('pybabel extract -F babel.cfg -o %s GeoHealthCheck' % base_pot) + click.echo('GeoHC: finished extracting translations.') + + +@cli.command() +@click.option('-l', '--lang', required=True, help='2-letter language code') +@click.pass_context +def add_language_catalogue(ctx, lang): + """adds new language profile""" + verbose_echo(ctx, 'GeoHC: Adding language catalogue.') + import os + basedir = os.path.abspath(os.path.dirname(__file__)) + base_pot = os.path.normpath( + '%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % basedir) + translations = os.path.normpath('%s/GeoHealthCheck/translations' % basedir) + verbose_echo(ctx, 'GeoHC: Base translation set: %s' % base_pot) + os.system('pybabel init -i %s -d %s -l %s' % ( + base_pot, translations, lang)) + click.echo('GeoHC: Finished translating: %s' % lang) + + +@cli.command() +@click.pass_context +def compile_translations(ctx): + """build language files""" + verbose_echo(ctx, 'GeoHC: start building language files.') + import os + basedir = os.path.abspath(os.path.dirname(__file__)) + translations = os.path.normpath('%s/GeoHealthCheck/translations' % basedir) + os.system('pybabel compile -d %s' % translations) + click.echo('GeoHC: Finished building language files.') + + +@cli.command() +@click.pass_context +def update_translations(ctx): + """update language strings""" + verbose_echo(ctx, 'GeoHC: update translations.') + extract_translations(ctx) + + import os + basedir = os.path.abspath(os.path.dirname(__file__)) + base_pot = os.path.normpath( + '%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % basedir) + translations = os.path.normpath('%s/GeoHealthCheck/translations' % basedir) + os.system('pybabel update -i %s -d %s' % (base_pot, translations)) + click.echo('GeoHC: Finished updating translations.') + + +@cli.command() +@click.pass_context +def runner_daemon(ctx): + """Run the HealthCheck runner daemon scheduler""" + verbose_echo(ctx, 'GeoHC: going to run the scheduler daemon. Press ctrl-c to stop.') + import os + os.system('python %s' % os.path.normpath('GeoHealthCheck/scheduler.py')) + + +@cli.command() +@click.pass_context +def run_healthchecks(ctx): + """Run all HealthChecks directly""" + verbose_echo(ctx, 'GeoHC: going to run all the healthchecks once.') + import os + os.system('python %s' % os.path.normpath('GeoHealthCheck/healthcheck.py')) + click.echo('GeoHC: Finished running the healthchecks.') + @cli.command() @click.pass_context diff --git a/pavement.py b/pavement.py index daeb802e..9361b3d9 100644 --- a/pavement.py +++ b/pavement.py @@ -159,14 +159,6 @@ def setup(): info('development instance with "python GeoHealthCheck/app.py"') -@task -def create_secret_key(): - """create secret key for SECRET_KEY in instance/config_site.py""" - info('Secret key: \'%s\'' % codecs.encode(os.urandom(24), 'hex').decode()) - info('Copy/paste this key to set the SECRET_KEY') - info('value in instance/config_site.py') - - @task @cmdopts([ ('email=', 'e', 'email'), @@ -175,17 +167,28 @@ def create_secret_key(): ]) def create(options): """create database objects and superuser account""" - + info('Warning!: create_secret_key is deprecated since 0.8.0. Please use cli: ' + '`geohc db-create` and `geohc db-adduser`') args = '' username = options.get('username', None) password = options.get('password', None) email = options.get('email', None) - + info(username) if all([username, password, email]): args = '%s %s %s' % (username, password, email) sh('python %s create %s' % (path('GeoHealthCheck/models.py'), args)) +@task +def create_secret_key(): + """create secret key for SECRET_KEY in instance/config_site.py""" + info('Warning!: create_secret_key is deprecated since 0.8.0. Please use cli: ' + '`geohc create-secret-key`') + info('Secret key: \'%s\'' % codecs.encode(os.urandom(24), 'hex').decode()) + info('Copy/paste this key to set the SECRET_KEY') + info('value in instance/config_site.py') + + @task @cmdopts([ ('password=', 'p', 'password') @@ -195,7 +198,8 @@ def create_hash(options): Create hash, mainly for passwords. Usage: paver create_hash -p mypass """ - + info('Warning!: create_hash is deprecated since 0.8.0. Please use cli: ' + '`geohc create-hash`') import sys sys.path.insert(0, BASEDIR + '/GeoHealthCheck') from util import create_hash @@ -207,7 +211,8 @@ def create_hash(options): @task def upgrade(): """upgrade database if changed; be sure to backup first!""" - + info('Warning!: upgrade is deprecated since 0.8.0. Please use cli: ' + '`geohc db-upgrade`') info('Upgrading database...') with pushd(path('%s/GeoHealthCheck' % BASEDIR)): sh('python manage.py db upgrade') @@ -216,6 +221,8 @@ def upgrade(): @task def create_wsgi(): """create WSGI wrapper and Apache2 configuration""" + info('Warning!: create_wsgi is deprecated since 0.8.0. Please use cli: ' + '`geohc create-wsgi`') wsgi_script = '%s%sGeoHealthCheck.wsgi' % (options.base.instance, os.sep) with open(wsgi_script, 'w') as ff: ff.write('import sys\n') @@ -235,6 +242,8 @@ def create_wsgi(): @task def refresh_docs(): """Build sphinx docs from scratch""" + info('Warning!: refresh_docs is deprecated since 0.8.0. Please use cli: ' + '`geohc refresh-docs`') make = sphinx_make() @@ -251,6 +260,8 @@ def refresh_docs(): @task def clean(): """clean environment""" + info('Warning!: clean is deprecated since 0.8.0. Please use cli: ' + '`geohc clean`') if os.path.exists(options.base.static_lib): shutil.rmtree(options.base.static_lib) @@ -264,6 +275,8 @@ def clean(): def extract_translations(): """extract translations wrapped in _() or gettext()""" + info('Warning!: extract_translations is deprecated since 0.8.0. Please use cli: ' + '`geohc extract-translations`') pot_dir = path('GeoHealthCheck/translations/en/LC_MESSAGES') if not os.path.exists(pot_dir): pot_dir.makedirs() @@ -278,6 +291,8 @@ def extract_translations(): def add_language_catalogue(options): """adds new language profile""" + info('Warning!: add_language_catalogue is deprecated since 0.8.0. Please use cli: ' + '`geohc add-language-catalogue`') lang = options.get('lang', None) if lang is None: @@ -290,14 +305,16 @@ def add_language_catalogue(options): @task def compile_translations(): """build .mo files""" - + info('Warning!: compile_translations is deprecated since 0.8.0. Please use cli: ' + '`geohc compile-translations`') sh('pybabel compile -d %s' % options.base.translations) @task def update_translations(): """update language strings""" - + info('Warning!: update_translations is deprecated since 0.8.0. Please use cli: ' + '`geohc update-translations`') call_task('extract_translations') sh('pybabel update -i %s -d %s' % ( options.base.pot, options.base.translations)) @@ -306,6 +323,8 @@ def update_translations(): @task def runner_daemon(): """Run the HealthCheck runner daemon scheduler""" + info('Warning!: runner_daemon is deprecated since 0.8.0. Please use cli: ' + '`geohc runner-daemon`') sh('python %s' % path('GeoHealthCheck/scheduler.py')) From bfb74ebbc07088433386d5f42eeee52121932154 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 15:58:02 +0100 Subject: [PATCH 07/49] Update command calls --- ghc_cli.py | 10 +++++----- pavement.py | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ghc_cli.py b/ghc_cli.py index 4ff3c865..f1640c66 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -331,7 +331,7 @@ def clean(ctx): @cli.command() @click.pass_context -def extract_translations(ctx): +def lang_extract_translations(ctx): """extract translations wrapped in _() or gettext()""" verbose_echo(ctx, 'GeoHC: extracting translations') import os @@ -351,7 +351,7 @@ def extract_translations(ctx): @cli.command() @click.option('-l', '--lang', required=True, help='2-letter language code') @click.pass_context -def add_language_catalogue(ctx, lang): +def lang_add_language_catalogue(ctx, lang): """adds new language profile""" verbose_echo(ctx, 'GeoHC: Adding language catalogue.') import os @@ -367,7 +367,7 @@ def add_language_catalogue(ctx, lang): @cli.command() @click.pass_context -def compile_translations(ctx): +def lang_compile_translations(ctx): """build language files""" verbose_echo(ctx, 'GeoHC: start building language files.') import os @@ -379,10 +379,10 @@ def compile_translations(ctx): @cli.command() @click.pass_context -def update_translations(ctx): +def lang_update_translations(ctx): """update language strings""" verbose_echo(ctx, 'GeoHC: update translations.') - extract_translations(ctx) + lang_extract_translations(ctx) import os basedir = os.path.abspath(os.path.dirname(__file__)) diff --git a/pavement.py b/pavement.py index 9361b3d9..d3abf2d7 100644 --- a/pavement.py +++ b/pavement.py @@ -276,7 +276,7 @@ def extract_translations(): """extract translations wrapped in _() or gettext()""" info('Warning!: extract_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc extract-translations`') + '`geohc lang-extract-translations`') pot_dir = path('GeoHealthCheck/translations/en/LC_MESSAGES') if not os.path.exists(pot_dir): pot_dir.makedirs() @@ -292,7 +292,7 @@ def add_language_catalogue(options): """adds new language profile""" info('Warning!: add_language_catalogue is deprecated since 0.8.0. Please use cli: ' - '`geohc add-language-catalogue`') + '`geohc lang-add-language-catalogue`') lang = options.get('lang', None) if lang is None: @@ -306,7 +306,7 @@ def add_language_catalogue(options): def compile_translations(): """build .mo files""" info('Warning!: compile_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc compile-translations`') + '`geohc lang-compile-translations`') sh('pybabel compile -d %s' % options.base.translations) @@ -314,7 +314,7 @@ def compile_translations(): def update_translations(): """update language strings""" info('Warning!: update_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc update-translations`') + '`geohc lang-update-translations`') call_task('extract_translations') sh('pybabel update -i %s -d %s' % ( options.base.pot, options.base.translations)) @@ -331,6 +331,8 @@ def runner_daemon(): @task def run_healthchecks(): """Run all HealthChecks directly""" + info('Warning!: run_healthchecks is deprecated since 0.8.0. Please use cli: ' + '`geohc run-healthchecks`') sh('python %s' % path('GeoHealthCheck/healthcheck.py')) From dd9d26ba86d4a37b1f94102d43e414acb34f384b Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 16:24:36 +0100 Subject: [PATCH 08/49] Update documentation to add new cli --- docs/admin.rst | 27 +++++++++++++++++++-------- docs/config.rst | 6 +++--- docs/install.rst | 29 ++++++++++++++--------------- ghc_cli.py | 9 ++++++++- pavement.py | 2 ++ 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/docs/admin.rst b/docs/admin.rst index 2ee3b142..423b4928 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -7,7 +7,18 @@ This chapter describes maintenance tasks for the administrator of a GHC instance There is a separate :ref:`userguide` that provides guidance to the end-user to configure the actual Resource healthchecks. -Each of the sections below is geared at a specific administrative task area. +Each of the sections below is geared at a specific administrative task area. We +assume you have installed GeoHealthCheck with `pip install`, and that you have +acces to the command line interface `geohc`. You can get help from the cli via :: + + geohc --help + +This will list all available commands. To get help with a specific command, run +`geohc command --help`, e.g. :: + + geohc db-adduser --help + +This will show you all the (required) options to add a user to the database. Database -------- @@ -21,7 +32,7 @@ To create the database execute the following: Open a command line, (if needed activate your virtualenv), and do :: - python GeoHealthCheck/models.py create + geohc db-create drop db ....... @@ -30,7 +41,7 @@ To delete the database execute the following, however you will loose all your in Open a command line, (if needed activate your virtualenv), and do :: - python GeoHealthCheck/models.py drop + geohc db-drop Note: you need to create a Database again before you can start GHC again. @@ -39,7 +50,7 @@ load data To load a JSON data file, do (WARN: deletes existing data!) :: - python GeoHealthCheck/models.py load [y/n] + geohc db-load --file my_data.json Hint: see `tests/data` for example JSON data files. @@ -92,10 +103,9 @@ Or more compact within the root dir of your GHC installation: :: >>> create_hash('mynewpassword') '$pbkdf2-sha256$29000$8X4PAUAIAcC4V2rNea9Vqg$XnMx1SfEiBzBAMOQOOC7uxCcyzVuKaHENLj3IfXvfu0' -Or even more compact within the root dir of your GHC installation via Paver: :: +Or even more compact within the root dir of your GHC installation via the cli: :: - $ paver create_hash -p mypass - ---> pavement.create_hash + $ geohc create_hash -p mypass Copy/paste the entire token below for example to set password $pbkdf2-sha256$29000$FkJoTYnxPqc0pjQG4HxP6Q$C3SZb8jqtM7zKS1DSLcouc/CL9XMI9cL5xT6DRTOEd4 @@ -110,4 +120,5 @@ Build Documentation ------------------- Open a command line, (if needed activate your virtualenv) and move into the directory ``GeoHealthCheck/doc/``. -In there, type ``make html`` plus ENTER and the documentation should be built locally. +In there, type ``make html`` plus ENTER and the documentation should be built locally. Or you can +use the cli: `geohc refresh-docs`. diff --git a/docs/config.rst b/docs/config.rst index 14e2c0e7..5716f565 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -46,7 +46,7 @@ The configuration options are: Example on overriding the configuration with an environment variable: :: export GHC_SETTINGS=/tmp/my_GHC_settings.py - paver run_tests + geohc run-tests As an example: the `my_GHC_settings.py` file can contain a single line to define a test database: :: @@ -148,7 +148,7 @@ Compiling Language Files ........................ At runtime compiled versions, `*.mo` files, of the language-files are used. -Easiest to compile is via: `paver compile_translations` in the project root dir. +Easiest to compile is via: `geohc compile-translations` in the project root dir. This basically calls ``pybabel compile` with the proper options. Now you can e.g. test your new translations by starting GHC. @@ -170,7 +170,7 @@ Missing translations will have `msgstr ""` like in this excerpt: :: Next all empty `msgstr`s can be filled. -Updating is easiest using the command `paver update_translations` within the root dir of the project. +Updating is easiest using the command `geohc update-translations` within the root dir of the project. This will basically call `pybabel extract` followed by `pybabel update` with the proper parameters. Customizing the Score Matrix diff --git a/docs/install.rst b/docs/install.rst index f93aad90..b94573d1 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -27,9 +27,8 @@ GeoHealthCheck is built on the awesome Flask micro-framework and uses `APScheduler` is used to run scheduled healthchecks. -These dependencies are automatically installed (see below). ``Paver`` is used -for installation and management. ``Cron`` was used for scheduling the actual -healthchecks before v0.5.0. +These dependencies are automatically installed (see below). A command line interface is provided + with `click`. ``Cron`` was used for scheduling the actual healthchecks before v0.5.0. Starting from version v0.8.0.0 GeoHealthCheck requires **python 3**. Previous versions require **python 2**. @@ -56,13 +55,13 @@ Install cd GeoHealthCheck # install paver dependency for admin tool - pip install Paver + pip install . # setup app - paver setup + geohc create-instance # create secret key to use for auth - paver create_secret_key + geohc create-secret-key # almost there! Customize config vi instance/config_site.py @@ -83,10 +82,10 @@ Install # - GHC_MAP # or use default settings # init database - python GeoHealthCheck/models.py create + geohc db-create # start web-app - python GeoHealthCheck/app.py # http://localhost:8000/ + geohc serve # when you are done, you can exit the virtualenv deactivate @@ -103,7 +102,7 @@ An existing GHC database installation can be upgraded with: .. code-block:: bash # In the top directory (e.g. the topdir cloned from github) - paver upgrade + geohc db-upgrade # Notice any output, in particular errors @@ -119,7 +118,7 @@ Notes: When running with Docker see the `Docker Readme `_ -how to run `paver upgrade` within your Docker Container. +how to run `geohc upgrade` within your Docker Container. Upgrade notes v0.5.0 .................... @@ -144,9 +143,9 @@ Start using Flask's built-in WSGI server: .. code-block:: bash - python GeoHealthCheck/app.py # http://localhost:8000 - python GeoHealthCheck/app.py 0.0.0.0:8881 # http://localhost:8881 - python GeoHealthCheck/app.py 192.168.0.105:8957 # http://192.168.0.105:8957 + geohc serve # http://localhost:8000 + geohc serve --port 8881 # http://localhost:8881 + geohc serve --host 192.168.0.105 --port 8957 # http://192.168.0.105:8957 This runs the (Flask) **GHC Webapp**, by default with the **GHC Runner** (scheduled healthchecker) internally. @@ -157,10 +156,10 @@ From the command-line run both processes, e.g. in background or different termin .. code-block:: bash # run GHC Runner, here in background - python GeoHealthCheck/scheduler.py & + geohc runner-daemon & # run GHC Webapp for http://localhost:8000 - python GeoHealthCheck/app.py + geohc serve To enable in Apache, use ``GeoHealthCheck.wsgi`` and configure in Apache diff --git a/ghc_cli.py b/ghc_cli.py index f1640c66..ba44c555 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -415,7 +415,14 @@ def run_healthchecks(ctx): @cli.command() @click.pass_context def db_export(ctx): - pass + click.exho('GeoHC: todo- write export.') + +@cli.command() +@click.pass_context +def run_tests(ctx): + """Run all tests""" + import os + os.system('python %s' % os.path.normpath('tests/run_tests.py')) if __name__ == '__main__': diff --git a/pavement.py b/pavement.py index d3abf2d7..7247ee52 100644 --- a/pavement.py +++ b/pavement.py @@ -347,4 +347,6 @@ def sphinx_make(): @task def run_tests(): """Run all tests""" + info('Warning!: run_tests is deprecated since 0.8.0. Please use cli: ' + '`geohc run-tests`') sh('python %s' % path('tests/run_tests.py')) From adde2aba530d0e96810aeb90f3be20adc6a99f14 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 19:21:30 +0100 Subject: [PATCH 09/49] Update readme on cli --- README.md | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8891d525..6795cd17 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,15 @@ Easiest is [to run GHC using Docker](https://github.com/geopython/GeoHealthCheck Below a quick overview of a manual install on Unix-based systems like Apple Mac and Linux. ```bash -virtualenv GeoHealthCheck && cd $_ +python3 -m venv venv . bin/activate git clone https://github.com/geopython/GeoHealthCheck.git cd GeoHealthCheck -pip install Paver +pip install . # setup installation -paver setup +geohc create-instance # generate secret key -paver create_secret_key +geohc create-secret-key # setup local configuration (overrides GeoHealthCheck/config_main.py) vi instance/config_site.py # edit at least secret key: @@ -36,33 +36,42 @@ vi instance/config_site.py # - GHC_SITE_TITLE # - GHC_MAP (or use default settings) -# setup database and superuser account interactively -paver create +# setup database +geohc db-create + +# create superuser account interactively +geohc db-adduser # start webserver with healthcheck runner daemon inside # (default is 0.0.0.0:8000) -python GeoHealthCheck/app.py +geohc serve # or start webserver on another port -python GeoHealthCheck/app.py 0.0.0.0:8881 +geohc serve -p 8881 # or start webserver on another IP -python GeoHealthCheck/app.py 192.168.0.105:8001 +geohc serve -h 192.168.0.105 -p 8001 # OR start webserver and separate runner daemon (scheduler) process vi instance/config_site.py # GHC_RUNNER_IN_WEBAPP = False -python GeoHealthCheck/scheduler.py & -python GeoHealthCheck/app.py +geohc runner-daemon & +geohc serve # next: use a real webserver or preferably Docker for production # other commands # # drop database -python GeoHealthCheck/models.py drop +geohc db-drop # load data in database (WARN: deletes existing data!) # See example data .json files in tests/data -python GeoHealthCheck/models.py load <.json data file> [y/n] +geohc db-load -f <.json data file> -y + +# More help on the `geohc` cli command: +geohc --help + +# More help on a specific command +geohc db-load --help ``` From 272d21d10ce0a00b8ed9ebc211f5a0cb954501ac Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 19:31:06 +0100 Subject: [PATCH 10/49] Update README - fix sourcing venv --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6795cd17..ef69c9d0 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Easiest is [to run GHC using Docker](https://github.com/geopython/GeoHealthCheck Below a quick overview of a manual install on Unix-based systems like Apple Mac and Linux. ```bash -python3 -m venv venv -. bin/activate +python3 -m venv ghc_venv +. ghc_venv/bin/activate git clone https://github.com/geopython/GeoHealthCheck.git cd GeoHealthCheck pip install . From 8df7fd936ab6555e61e1f5ae5d02961e872ba635 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 13 Dec 2019 20:50:52 +0100 Subject: [PATCH 11/49] Update setup.py to complete build egg and wheel --- ghc_cli.py | 10 ++++++++ requirements-dev.txt | 1 + setup.py | 56 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/ghc_cli.py b/ghc_cli.py index ba44c555..4aeb38c3 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -425,5 +425,15 @@ def run_tests(ctx): os.system('python %s' % os.path.normpath('tests/run_tests.py')) +@cli.command() +@click.pass_context +def build_wheel(ctx): + """Build a python wheel""" + verbose_echo(ctx, 'GeoHC: Build a python wheel') + from os import system + system('python setup.py bdist_wheel') + click.echo('GeoHC: Finished building a wheel.') + + if __name__ == '__main__': cli() diff --git a/requirements-dev.txt b/requirements-dev.txt index a857e625..095bdec7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,3 +2,4 @@ click==7.0 flake8 Paver==1.3.4 pylint +wheel==0.33.6 diff --git a/setup.py b/setup.py index 3632e936..028a8943 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,37 @@ +# ================================================================= +# +# Authors: Rob van Loon +# Tom Kralidis +# +# Copyright (c) 2019 Rob van Loon +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# ================================================================= import io import os from setuptools import find_packages, setup + def read(filename, encoding='utf-8'): """read file contents""" full_path = os.path.join(os.path.dirname(__file__), filename) @@ -16,9 +46,21 @@ def get_package_version(): return version_file raise RuntimeError("Unable to find version string.") +LONG_DESCRIPTION = read('README.md') + +DESCRIPTION = 'GeoHealthCheck is a Quality of Service Checker for OGC Web Services and web APIs.' + setup( name='geohealthcheck', version=get_package_version(), + description=DESCRIPTION, + long_description=LONG_DESCRIPTION, + long_description_content_type="text/markdown", + author='Tom Kralidis', + author_email='tomkralidis@gmail.com', + maintainer='Tom Kralidis', + maintainer_email='tomkralidis@gmail.com', + url='https://geohealthcheck.org', license='MIT', install_requires=read('requirements.txt').splitlines(), packages=find_packages(exclude=['tests']), @@ -27,5 +69,17 @@ def get_package_version(): 'console_scripts': [ 'geohc=ghc_cli:cli', ] - } + }, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Framework :: Flask', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Scientific/Engineering :: GIS' + ], ) From 531162f3c9f58f43915e4291cf1ca4e93fc3fe1e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Sat, 14 Dec 2019 22:13:00 +0100 Subject: [PATCH 12/49] Update travis to cli commands --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b43f7be..6986bcc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,17 +6,17 @@ python: sudo: false install: - - pip install -r requirements.txt - - pip install -r requirements-dev.txt - - paver setup + - pip install . + - geohc create-instance script: - - echo -e "admin\ntest\ntest\nyou@example.com\nyou@example.com" | python GeoHealthCheck/models.py create + - geohc db-create + - geohc db-adduser -u admin -p test -e you@example.com -r admin - flake8 - - python GeoHealthCheck/models.py load tests/data/fixtures.json y - - python GeoHealthCheck/healthcheck.py - - python tests/run_tests.py + - geohc db-load -y tests/data/fixtures.json -y + - geohc run-healthchecks + - geohc run-tests - cd docs && make html after-script: - - python GeoHealthCheck/models.py drop + - geohc db-drop From f3ee207b0b4cc5d3a46e0910f53982542f896ba2 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Sat, 14 Dec 2019 22:19:08 +0100 Subject: [PATCH 13/49] Update docker scripts to cli --- docker/scripts/install.sh | 1 + docker/scripts/requirements.txt | 1 - docker/scripts/run-runner.sh | 2 +- docker/scripts/run-web.sh | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/scripts/install.sh b/docker/scripts/install.sh index 16532c83..5c819ca3 100755 --- a/docker/scripts/install.sh +++ b/docker/scripts/install.sh @@ -11,6 +11,7 @@ source /venv/bin/activate pip install -I -r /GeoHealthCheck/docker/scripts/requirements.txt cd /GeoHealthCheck +pip install . # Sets up GHC itself paver setup diff --git a/docker/scripts/requirements.txt b/docker/scripts/requirements.txt index fd68b637..1a716f6f 100644 --- a/docker/scripts/requirements.txt +++ b/docker/scripts/requirements.txt @@ -1,4 +1,3 @@ -Paver==1.3.4 Sphinx==1.8.1 psycopg2==2.7.5 eventlet==0.24.1 diff --git a/docker/scripts/run-runner.sh b/docker/scripts/run-runner.sh index bfcaa8af..6f09a838 100755 --- a/docker/scripts/run-runner.sh +++ b/docker/scripts/run-runner.sh @@ -16,6 +16,6 @@ source /venv/bin/activate . export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH cd /GeoHealthCheck -paver runner_daemon +geohc runner-daemon echo "END /run-runner.sh" diff --git a/docker/scripts/run-web.sh b/docker/scripts/run-web.sh index 9e25ed23..11df065e 100755 --- a/docker/scripts/run-web.sh +++ b/docker/scripts/run-web.sh @@ -16,7 +16,7 @@ export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH cd /GeoHealthCheck -paver upgrade +geohc db-upgrade # SCRIPT_NAME should not have value '/' [ "${SCRIPT_NAME}" = '/' ] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /" From b4513a8338432f695b02ba421a82309e399975ce Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Sun, 15 Dec 2019 21:37:00 +0100 Subject: [PATCH 14/49] Fix flake8 issues --- GeoHealthCheck/models.py | 21 +++++++++++---------- ghc_cli.py | 33 +++++++++++++++++++++------------ pavement.py | 28 ++++++++++++++-------------- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index 3c44665c..30882353 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -909,8 +909,9 @@ def db_commit(): if len(sys.argv) > 1: if sys.argv[1] == 'create': - warnings.warn('models.py create is deprecated since 0.8.0. Please use cli: ' - '`geohc db-create` and `geohc db-adduser`', DeprecationWarning) + warnings.warn('models.py create is deprecated since 0.8.0. Please' + ' use cli: `geohc db-create` and `geohc db-adduser`', + DeprecationWarning) print('Creating database objects') DB.create_all() @@ -935,15 +936,15 @@ def db_commit(): db_commit() elif sys.argv[1] == 'drop': - warnings.warn('models.py drop is deprecated since 0.8.0. Please use cli: ' - '`geohc db-drop`', DeprecationWarning) + warnings.warn('models.py drop is deprecated since 0.8.0. Please ' + 'use cli: `geohc db-drop`', DeprecationWarning) print('Dropping database objects') DB.drop_all() db_commit() elif sys.argv[1] == 'load': - warnings.warn('models.py load is deprecated since 0.8.0. Please use cli: ' - '`geohc db-load`', DeprecationWarning) + warnings.warn('models.py load is deprecated since 0.8.0. Please ' + 'use cli: `geohc db-load`', DeprecationWarning) print('Load database from JSON file (e.g. tests/fixtures.json)') if len(sys.argv) > 2: file_path = sys.argv[2] @@ -967,12 +968,12 @@ def db_commit(): print('Provide path to JSON file, e.g. tests/fixtures.json') elif sys.argv[1] == 'run': - warnings.warn('models.py run is deprecated. Please use `python healthcheck.py`', - DeprecationWarning) + warnings.warn('models.py run is deprecated. Please use `python ' + 'healthcheck.py`', DeprecationWarning) elif sys.argv[1] == 'flush': - warnings.warn('models.py flush is deprecated since 0.8.0. Please use cli: ' - '`geohc db-flush`', DeprecationWarning) + warnings.warn('models.py flush is deprecated since 0.8.0. Please ' + 'use cli: `geohc db-flush`', DeprecationWarning) flush_runs() DB.session.remove() diff --git a/ghc_cli.py b/ghc_cli.py index 4aeb38c3..2f0c51c0 100644 --- a/ghc_cli.py +++ b/ghc_cli.py @@ -114,17 +114,18 @@ def db_create(ctx): DB.create_all() db_commit() DB.session.remove() - click.echo('Database is created. Use `geohc db-adduser` to add users to the database.') + click.echo('Database is created. Use `geohc db-adduser` to add users to ' + 'the database.') @cli.command() @click.pass_context @click.option('-u', '--user', type=str, help='username', prompt=True) @click.option('-e', '--email', type=str, help='email address', prompt=True) -@click.option('-p', '--password', type=str, help='password', prompt=True, hide_input=True, - confirmation_prompt=True) -@click.option('-r', '--role', type=click.Choice(['admin', 'user']), prompt=True, - help='role for this user') +@click.option('-p', '--password', type=str, help='password', prompt=True, + hide_input=True, confirmation_prompt=True) +@click.option('-r', '--role', type=click.Choice(['admin', 'user']), + prompt=True, help='role for this user') def db_adduser(ctx, user, email, password, role): """Add an user to the database """ @@ -146,12 +147,14 @@ def db_adduser(ctx, user, email, password, role): @click.pass_context @click.option('-y', '--yes', is_flag=True, callback=abort_if_false, expose_value=False, help='Confirm dropping tables', - prompt='This will drop the tables in the database. Are you sure?') + prompt='This will drop the tables in the database. Are you ' + 'sure?') def db_drop(ctx): """Drop the current database """ verbose_echo(ctx, 'GeoHC: drop db') - click.confirm("This will drop the tables in the database. Are you sure?", abort=True) + click.confirm("This will drop the tables in the database. Are you sure?", + abort=True) verbose_echo(ctx, 'User confirmed dropping tables') from GeoHealthCheck.init import App from GeoHealthCheck.models import db_commit @@ -211,11 +214,13 @@ def create_secret_key(ctx): from codecs import encode from os import urandom click.echo('Secret key: \'%s\'' % encode(urandom(24), 'hex').decode()) - click.echo('Copy/paste this key to set the SECRET_KEY value in instance/config_site.py') + click.echo('Copy/paste this key to set the SECRET_KEY value in ' + 'instance/config_site.py') @cli.command() -@click.option('-p', '--password', prompt=True, hide_input=True, help='password') +@click.option('-p', '--password', prompt=True, hide_input=True, + help='password') @click.pass_context def create_hash(ctx, password): """Create a password hash @@ -257,7 +262,8 @@ def create_wsgi(ctx): wsgi_conf = '%s%sGeoHealthCheck.conf' % (instance, os.sep) with open(wsgi_conf, 'w') as ff: - ff.write('WSGIScriptAlias / %s%sGeoHealthCheck.wsgi\n' % (instance, os.sep)) + ff.write('WSGIScriptAlias / %s%sGeoHealthCheck.wsgi\n' % (instance, + os.sep)) ff.write('\n' % (basedir, os.sep)) ff.write('Order deny,allow\n') ff.write('Allow from all\n') @@ -342,7 +348,8 @@ def lang_extract_translations(ctx): pot_dir.makedirs() basedir = os.path.abspath(os.path.dirname(__file__)) - base_pot = os.path.normpath('%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % basedir) + base_pot = os.path.normpath('%s/GeoHealthCheck/translations/en/' + 'LC_MESSAGES/messages.po' % basedir) verbose_echo(ctx, 'GeoHC: starting translation') os.system('pybabel extract -F babel.cfg -o %s GeoHealthCheck' % base_pot) click.echo('GeoHC: finished extracting translations.') @@ -397,7 +404,8 @@ def lang_update_translations(ctx): @click.pass_context def runner_daemon(ctx): """Run the HealthCheck runner daemon scheduler""" - verbose_echo(ctx, 'GeoHC: going to run the scheduler daemon. Press ctrl-c to stop.') + verbose_echo(ctx, 'GeoHC: going to run the scheduler daemon. Press ctrl-c ' + 'to stop.') import os os.system('python %s' % os.path.normpath('GeoHealthCheck/scheduler.py')) @@ -417,6 +425,7 @@ def run_healthchecks(ctx): def db_export(ctx): click.exho('GeoHC: todo- write export.') + @cli.command() @click.pass_context def run_tests(ctx): diff --git a/pavement.py b/pavement.py index 7247ee52..ecd35738 100644 --- a/pavement.py +++ b/pavement.py @@ -167,8 +167,8 @@ def setup(): ]) def create(options): """create database objects and superuser account""" - info('Warning!: create_secret_key is deprecated since 0.8.0. Please use cli: ' - '`geohc db-create` and `geohc db-adduser`') + info('Warning!: create_secret_key is deprecated since 0.8.0. Please use ' + 'cli: `geohc db-create` and `geohc db-adduser`') args = '' username = options.get('username', None) password = options.get('password', None) @@ -182,8 +182,8 @@ def create(options): @task def create_secret_key(): """create secret key for SECRET_KEY in instance/config_site.py""" - info('Warning!: create_secret_key is deprecated since 0.8.0. Please use cli: ' - '`geohc create-secret-key`') + info('Warning!: create_secret_key is deprecated since 0.8.0. Please use ' + 'cli: `geohc create-secret-key`') info('Secret key: \'%s\'' % codecs.encode(os.urandom(24), 'hex').decode()) info('Copy/paste this key to set the SECRET_KEY') info('value in instance/config_site.py') @@ -275,8 +275,8 @@ def clean(): def extract_translations(): """extract translations wrapped in _() or gettext()""" - info('Warning!: extract_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc lang-extract-translations`') + info('Warning!: extract_translations is deprecated since 0.8.0. Please use' + ' cli: `geohc lang-extract-translations`') pot_dir = path('GeoHealthCheck/translations/en/LC_MESSAGES') if not os.path.exists(pot_dir): pot_dir.makedirs() @@ -291,8 +291,8 @@ def extract_translations(): def add_language_catalogue(options): """adds new language profile""" - info('Warning!: add_language_catalogue is deprecated since 0.8.0. Please use cli: ' - '`geohc lang-add-language-catalogue`') + info('Warning!: add_language_catalogue is deprecated since 0.8.0. Please ' + 'use cli: `geohc lang-add-language-catalogue`') lang = options.get('lang', None) if lang is None: @@ -305,16 +305,16 @@ def add_language_catalogue(options): @task def compile_translations(): """build .mo files""" - info('Warning!: compile_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc lang-compile-translations`') + info('Warning!: compile_translations is deprecated since 0.8.0. Please use' + ' cli: `geohc lang-compile-translations`') sh('pybabel compile -d %s' % options.base.translations) @task def update_translations(): """update language strings""" - info('Warning!: update_translations is deprecated since 0.8.0. Please use cli: ' - '`geohc lang-update-translations`') + info('Warning!: update_translations is deprecated since 0.8.0. Please use ' + 'cli: `geohc lang-update-translations`') call_task('extract_translations') sh('pybabel update -i %s -d %s' % ( options.base.pot, options.base.translations)) @@ -331,8 +331,8 @@ def runner_daemon(): @task def run_healthchecks(): """Run all HealthChecks directly""" - info('Warning!: run_healthchecks is deprecated since 0.8.0. Please use cli: ' - '`geohc run-healthchecks`') + info('Warning!: run_healthchecks is deprecated since 0.8.0. Please use ' + 'cli: `geohc run-healthchecks`') sh('python %s' % path('GeoHealthCheck/healthcheck.py')) From 3c427a50ee6b2cba3f2fcf596e589b5022316453 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 18 Dec 2019 08:00:24 +0100 Subject: [PATCH 15/49] Update docker commands --- docker/README.md | 4 ++-- docker/scripts/configure.sh | 2 +- docker/scripts/install.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/README.md b/docker/README.md index a1b0977f..d0d3d4ca 100644 --- a/docker/README.md +++ b/docker/README.md @@ -235,8 +235,8 @@ docker exec -it docker_geohealthcheck_1 bash source /venv/bin/activate . cd /GeoHealthCheck/ -# next can use Paver commands e.g. DB upgrade -paver upgrade +# next can use cli commands e.g. DB upgrade +geohc db-upgrade etc ``` diff --git a/docker/scripts/configure.sh b/docker/scripts/configure.sh index 8256ff23..ab0104cc 100755 --- a/docker/scripts/configure.sh +++ b/docker/scripts/configure.sh @@ -15,7 +15,7 @@ echo "Using DB_TYPE=${DB_TYPE}" # Create DB shorthand function create_db() { pushd /GeoHealthCheck/ - paver create -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL} + geohc db-adduser -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL} -r admin popd } diff --git a/docker/scripts/install.sh b/docker/scripts/install.sh index 5c819ca3..363fb03c 100755 --- a/docker/scripts/install.sh +++ b/docker/scripts/install.sh @@ -14,7 +14,7 @@ cd /GeoHealthCheck pip install . # Sets up GHC itself -paver setup +geohc create-instance mv /config_site.py /GeoHealthCheck/instance/config_site.py # Copy possible Plugins into app tree From 0741f99a96bd93f14e530539c1434a95ed53258e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 18 Dec 2019 08:07:50 +0100 Subject: [PATCH 16/49] Rename cli script --- ghc_cli.py => geohc_cli.py | 0 setup.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename ghc_cli.py => geohc_cli.py (100%) diff --git a/ghc_cli.py b/geohc_cli.py similarity index 100% rename from ghc_cli.py rename to geohc_cli.py diff --git a/setup.py b/setup.py index 028a8943..ccc2918a 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ def get_package_version(): include_package_data=True, entry_points={ 'console_scripts': [ - 'geohc=ghc_cli:cli', + 'geohc=geohc_cli:cli', ] }, classifiers=[ From efda72c37d1e45b4a305714826a8f95a4694ef24 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 18 Dec 2019 13:15:26 +0100 Subject: [PATCH 17/49] Final touches --- docs/admin.rst | 32 ++++++++++++++++++++++++++++++-- docs/install.rst | 3 +++ setup.py | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/admin.rst b/docs/admin.rst index 423b4928..6cf37892 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -14,7 +14,7 @@ acces to the command line interface `geohc`. You can get help from the cli via : geohc --help This will list all available commands. To get help with a specific command, run -`geohc command --help`, e.g. :: +`geohc <> --help`, e.g. :: geohc db-adduser --help @@ -23,7 +23,7 @@ This will show you all the (required) options to add a user to the database. Database -------- -For database administration the following commands are available. +For database administration the following commands are available: create db ......... @@ -34,6 +34,17 @@ Open a command line, (if needed activate your virtualenv), and do :: geohc db-create +add user +........ + +To add a new user to the database: + +Open a command line, (if needed activate your virtualenv), and do :: + + geohc db-adduser + # or + geohc db-adduser -u username -p password -e email@address.com -r admin + drop db ....... @@ -52,8 +63,25 @@ To load a JSON data file, do (WARN: deletes existing data!) :: geohc db-load --file my_data.json +You will be asked for confirmation. You can also specify the `-y` or `--yes` +flag to indicate you are sure and to skip the confirmation question. Hint: see `tests/data` for example JSON data files. + +flush +..... + +To flush the old records from the system, you can flush the records :: + + geohc db-flush + +upgrade +....... + +To upgrade the database structure (might be necessary with a new release of GeoHealthCheck) :: + + geohc db-upgrade + export data ........... diff --git a/docs/install.rst b/docs/install.rst index b94573d1..905a15bc 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -84,6 +84,9 @@ Install # init database geohc db-create + # create an (admin) user account + geohc db-adduser -u my_user_name -p my_pass -e e@mail.com -r admin + # start web-app geohc serve diff --git a/setup.py b/setup.py index ccc2918a..1c9d2e6a 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ def read(filename, encoding='utf-8'): contents = fh.read().strip() return contents + def get_package_version(): """get version from top-level package init""" version_file = read('VERSION') @@ -46,6 +47,7 @@ def get_package_version(): return version_file raise RuntimeError("Unable to find version string.") + LONG_DESCRIPTION = read('README.md') DESCRIPTION = 'GeoHealthCheck is a Quality of Service Checker for OGC Web Services and web APIs.' From ce5ced3b7fe5863811389144bb9cb87d25319bc3 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Thu, 19 Dec 2019 21:38:27 +0100 Subject: [PATCH 18/49] Add Pycharm files to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a8186829..755229f5 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,6 @@ GeoHealthCheck.conf # Data GeoHealthCheck/data.db + +# IDE +.idea From b3bbe004cd95b541fefc056a3ffc0078b8a248bc Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Thu, 19 Dec 2019 21:38:44 +0100 Subject: [PATCH 19/49] WIP: fix docker Need to fix loose ends: - DB exists, but still needs db-create - check import statements - fix env setting for GHC_SETTINGS_CONF - check non-docker build - update docs --- Dockerfile | 1 + GeoHealthCheck/__init__.py | 13 +---------- GeoHealthCheck/app.py | 16 ++++++------- GeoHealthCheck/check.py | 4 ++-- geohc_cli.py => GeoHealthCheck/geohc_cli.py | 0 GeoHealthCheck/healthcheck.py | 12 +++++----- GeoHealthCheck/init.py | 6 ++++- GeoHealthCheck/manage.py | 2 +- GeoHealthCheck/models.py | 25 +++++---------------- GeoHealthCheck/notifications.py | 2 +- GeoHealthCheck/plugin.py | 5 +---- GeoHealthCheck/probe.py | 8 +++---- GeoHealthCheck/resourceauth.py | 20 ++++------------- GeoHealthCheck/scheduler.py | 6 ++--- GeoHealthCheck/views.py | 10 ++++----- docker/scripts/configure.sh | 2 ++ docker/scripts/requirements.txt | 1 + docker/scripts/run-web.sh | 2 +- setup.py | 4 ++-- 19 files changed, 53 insertions(+), 86 deletions(-) rename geohc_cli.py => GeoHealthCheck/geohc_cli.py (100%) diff --git a/Dockerfile b/Dockerfile index 04ed6203..fb87b079 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ ENV LC_ALL="en_US.UTF-8" \ \ \ # GHC ENV settings\ + GHC_SETTINGS_FILE='/GeoHealthCheck/instance/config_site.py' \ ADMIN_NAME=admin \ ADMIN_PWD=admin \ ADMIN_EMAIL=admin.istrator@mydomain.com \ diff --git a/GeoHealthCheck/__init__.py b/GeoHealthCheck/__init__.py index 7f60751f..99e02e83 100644 --- a/GeoHealthCheck/__init__.py +++ b/GeoHealthCheck/__init__.py @@ -27,15 +27,4 @@ # # ================================================================= -try: - from util import read -except ImportError: - from .util import read - - -def get_package_version(file_): - """get version from top-level package init""" - return read(file_) - - -__version__ = get_package_version('../VERSION') +__version__ = '0.8.0dev' diff --git a/GeoHealthCheck/app.py b/GeoHealthCheck/app.py index f7feba37..f0a14816 100644 --- a/GeoHealthCheck/app.py +++ b/GeoHealthCheck/app.py @@ -42,14 +42,14 @@ from flask_migrate import Migrate from itertools import chain -import views -from __init__ import __version__ -from enums import RESOURCE_TYPES -from factory import Factory -from init import App -from models import Resource, Run, ProbeVars, CheckVars, Tag, User, Recipient -from resourceauth import ResourceAuth -from util import send_email, geocode, format_checked_datetime, \ +from GeoHealthCheck import views +from GeoHealthCheck.__init__ import __version__ +from GeoHealthCheck.enums import RESOURCE_TYPES +from GeoHealthCheck.factory import Factory +from GeoHealthCheck.init import App +from GeoHealthCheck.models import Resource, Run, ProbeVars, CheckVars, Tag, User, Recipient +from GeoHealthCheck.resourceauth import ResourceAuth +from GeoHealthCheck.util import send_email, geocode, format_checked_datetime, \ format_run_status, format_obj_value # Module globals for convenience diff --git a/GeoHealthCheck/check.py b/GeoHealthCheck/check.py index e08770f5..6b9874a8 100644 --- a/GeoHealthCheck/check.py +++ b/GeoHealthCheck/check.py @@ -1,5 +1,5 @@ -from plugin import Plugin -from result import CheckResult +from GeoHealthCheck.plugin import Plugin +from GeoHealthCheck.result import CheckResult class Check(Plugin): diff --git a/geohc_cli.py b/GeoHealthCheck/geohc_cli.py similarity index 100% rename from geohc_cli.py rename to GeoHealthCheck/geohc_cli.py diff --git a/GeoHealthCheck/healthcheck.py b/GeoHealthCheck/healthcheck.py index 8897fa56..1b2dac59 100644 --- a/GeoHealthCheck/healthcheck.py +++ b/GeoHealthCheck/healthcheck.py @@ -44,12 +44,12 @@ from owslib.csw import CatalogueServiceWeb from owslib.sos import SensorObservationService -from init import App -from enums import RESOURCE_TYPES -from models import Resource, Run -from probe import Probe -from result import ResourceResult -from notifications import notify +from GeoHealthCheck.init import App +from GeoHealthCheck.enums import RESOURCE_TYPES +from GeoHealthCheck.models import Resource, Run +from GeoHealthCheck.probe import Probe +from GeoHealthCheck.result import ResourceResult +from GeoHealthCheck.notifications import notify LOGGER = logging.getLogger(__name__) APP = App.get_app() diff --git a/GeoHealthCheck/init.py b/GeoHealthCheck/init.py index c46466a5..43003e88 100644 --- a/GeoHealthCheck/init.py +++ b/GeoHealthCheck/init.py @@ -67,7 +67,11 @@ def init(): # Read and override configs app.config.from_pyfile('config_main.py') - app.config.from_pyfile('../instance/config_site.py') + try: + app.config.from_pyfile('../instance/config_site.py') + except FileNotFoundError: + # for Docker build + app.config.from_pyfile('/GeoHealthCheck/instance/config_site.py') app.config.from_envvar('GHC_SETTINGS', silent=True) # Global Logging config diff --git a/GeoHealthCheck/manage.py b/GeoHealthCheck/manage.py index 82c029df..1e14569f 100644 --- a/GeoHealthCheck/manage.py +++ b/GeoHealthCheck/manage.py @@ -39,7 +39,7 @@ from flask_script import Manager from flask_migrate import Migrate, MigrateCommand -from init import App +from GeoHealthCheck.init import App DB = App.get_db() APP = App.get_app() diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index 30882353..fc029b18 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -39,26 +39,11 @@ from sqlalchemy.orm import deferred from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound -try: - import util -except ImportError: - from GeoHealthCheck import util -try: - from enums import RESOURCE_TYPES -except ImportError: - from GeoHealthCheck.enums import RESOURCE_TYPES -try: - from factory import Factory -except ImportError: - from GeoHealthCheck.factory import Factory -try: - from init import App -except ImportError: - from GeoHealthCheck.init import App -try: - from resourceauth import ResourceAuth -except ImportError: - from GeoHealthCheck.resourceauth import ResourceAuth +from GeoHealthCheck import util +from GeoHealthCheck.enums import RESOURCE_TYPES +from GeoHealthCheck.factory import Factory +from GeoHealthCheck.init import App +from GeoHealthCheck.resourceauth import ResourceAuth from wtforms.validators import Email, ValidationError from owslib.util import bind_url diff --git a/GeoHealthCheck/notifications.py b/GeoHealthCheck/notifications.py index 8b22af4a..bf6e4e9f 100644 --- a/GeoHealthCheck/notifications.py +++ b/GeoHealthCheck/notifications.py @@ -35,7 +35,7 @@ import requests from flask_babel import gettext -from util import render_template2 +from GeoHealthCheck.util import render_template2 LOGGER = logging.getLogger(__name__) diff --git a/GeoHealthCheck/plugin.py b/GeoHealthCheck/plugin.py index 8f38dc21..da73529a 100644 --- a/GeoHealthCheck/plugin.py +++ b/GeoHealthCheck/plugin.py @@ -1,7 +1,4 @@ -try: - from factory import Factory -except ImportError: - from GeoHealthCheck.factory import Factory +from GeoHealthCheck.factory import Factory import logging import inspect from collections.abc import Mapping diff --git a/GeoHealthCheck/probe.py b/GeoHealthCheck/probe.py index 2501b593..eaa53781 100644 --- a/GeoHealthCheck/probe.py +++ b/GeoHealthCheck/probe.py @@ -4,10 +4,10 @@ import datetime import requests -from factory import Factory -from init import App -from plugin import Plugin -from result import ProbeResult +from GeoHealthCheck.factory import Factory +from GeoHealthCheck.init import App +from GeoHealthCheck.plugin import Plugin +from GeoHealthCheck.result import ProbeResult LOGGER = logging.getLogger(__name__) diff --git a/GeoHealthCheck/resourceauth.py b/GeoHealthCheck/resourceauth.py index c7446b11..16b07379 100644 --- a/GeoHealthCheck/resourceauth.py +++ b/GeoHealthCheck/resourceauth.py @@ -1,21 +1,9 @@ import json import logging -try: - from plugin import Plugin -except ImportError: - from GeoHealthCheck.plugin import Plugin -try: - from factory import Factory -except ImportError: - from GeoHealthCheck.factory import Factory -try: - from util import encode, decode -except ImportError: - from GeoHealthCheck.util import encode, decode -try: - from init import App -except ImportError: - from GeoHealthCheck.init import App +from GeoHealthCheck.plugin import Plugin +from GeoHealthCheck.factory import Factory +from GeoHealthCheck.util import encode, decode +from GeoHealthCheck.init import App APP = App.get_app() LOGGER = logging.getLogger(__name__) diff --git a/GeoHealthCheck/scheduler.py b/GeoHealthCheck/scheduler.py index 62fa9c2c..83846786 100644 --- a/GeoHealthCheck/scheduler.py +++ b/GeoHealthCheck/scheduler.py @@ -33,14 +33,14 @@ import random import string from datetime import datetime, timedelta -from models import Resource, ResourceLock, flush_runs -from healthcheck import run_resource +from GeoHealthCheck.models import Resource, ResourceLock, flush_runs +from GeoHealthCheck.healthcheck import run_resource from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.jobstores.base import JobLookupError from apscheduler.events import \ EVENT_SCHEDULER_STARTED, EVENT_SCHEDULER_SHUTDOWN, \ EVENT_JOB_MISSED, EVENT_JOB_ERROR -from init import App +from GeoHealthCheck.init import App LOGGER = logging.getLogger(__name__) DB = App.get_db() diff --git a/GeoHealthCheck/views.py b/GeoHealthCheck/views.py index d5102e7c..0f3db82c 100644 --- a/GeoHealthCheck/views.py +++ b/GeoHealthCheck/views.py @@ -28,12 +28,12 @@ # ================================================================= import logging -import models -import util +from GeoHealthCheck import models +from GeoHealthCheck import util from sqlalchemy import text -from plugin import Plugin -from factory import Factory -from init import App +from GeoHealthCheck.plugin import Plugin +from GeoHealthCheck.factory import Factory +from GeoHealthCheck.init import App APP = App.get_app() LOGGER = logging.getLogger(__name__) diff --git a/docker/scripts/configure.sh b/docker/scripts/configure.sh index ab0104cc..c0386b54 100755 --- a/docker/scripts/configure.sh +++ b/docker/scripts/configure.sh @@ -15,6 +15,7 @@ echo "Using DB_TYPE=${DB_TYPE}" # Create DB shorthand function create_db() { pushd /GeoHealthCheck/ + geohc db-create geohc db-adduser -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL} -r admin popd } @@ -29,6 +30,7 @@ case ${DB_TYPE} in create_db else echo "NOT creating SQLite DB tables..." + geohc db-create #hoort hier niet fi ;; diff --git a/docker/scripts/requirements.txt b/docker/scripts/requirements.txt index 1a716f6f..fd68b637 100644 --- a/docker/scripts/requirements.txt +++ b/docker/scripts/requirements.txt @@ -1,3 +1,4 @@ +Paver==1.3.4 Sphinx==1.8.1 psycopg2==2.7.5 eventlet==0.24.1 diff --git a/docker/scripts/run-web.sh b/docker/scripts/run-web.sh index 11df065e..b30327e4 100755 --- a/docker/scripts/run-web.sh +++ b/docker/scripts/run-web.sh @@ -12,7 +12,7 @@ echo "START /run-web.sh" source /venv/bin/activate . # Make sure PYTHONPATH includes GeoHealthCheck -export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH +export PYTHONPATH=/GeoHealthCheck:$PYTHONPATH cd /GeoHealthCheck diff --git a/setup.py b/setup.py index 1c9d2e6a..3caf46a1 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ def read(filename, encoding='utf-8'): """read file contents""" full_path = os.path.join(os.path.dirname(__file__), filename) - with io.open(full_path, encoding=encoding) as fh: + with io.open(filename, encoding=encoding) as fh: contents = fh.read().strip() return contents @@ -69,7 +69,7 @@ def get_package_version(): include_package_data=True, entry_points={ 'console_scripts': [ - 'geohc=geohc_cli:cli', + 'geohc=GeoHealthCheck.geohc_cli:cli', ] }, classifiers=[ From ba875b673cf733efbfec8758870dfb9f01b65092 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 20 Dec 2019 08:20:31 +0100 Subject: [PATCH 20/49] Fix import statements app.py --- GeoHealthCheck/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GeoHealthCheck/app.py b/GeoHealthCheck/app.py index f0a14816..37d37764 100644 --- a/GeoHealthCheck/app.py +++ b/GeoHealthCheck/app.py @@ -76,7 +76,7 @@ # Should GHC Runner be run within GHC webapp? if CONFIG['GHC_RUNNER_IN_WEBAPP'] is True: LOGGER.info('Running GHC Scheduler in WebApp') - from scheduler import start_schedule + from GeoHealthCheck.scheduler import start_schedule # Start scheduler start_schedule() @@ -531,7 +531,7 @@ def add(): url = request.form['url'].strip() resources_to_add = [] - from healthcheck import sniff_test_resource, run_test_resource + from GeoHealthCheck.healthcheck import sniff_test_resource, run_test_resource sniffed_resources = sniff_test_resource(CONFIG, resource_type, url) if not sniffed_resources: @@ -734,7 +734,7 @@ def test(resource_identifier): flash(gettext('Resource not found'), 'danger') return redirect(request.referrer) - from healthcheck import run_test_resource + from GeoHealthCheck.healthcheck import run_test_resource result = run_test_resource( resource) From 727704404670696a8dbe9f9cd94275d939ffd990 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 20 Dec 2019 08:21:11 +0100 Subject: [PATCH 21/49] Format dockerfile --- Dockerfile | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb87b079..1ca2f69d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,6 @@ ENV LC_ALL="en_US.UTF-8" \ \ \ # GHC ENV settings\ - GHC_SETTINGS_FILE='/GeoHealthCheck/instance/config_site.py' \ ADMIN_NAME=admin \ ADMIN_PWD=admin \ ADMIN_EMAIL=admin.istrator@mydomain.com \ @@ -46,22 +45,22 @@ ENV LC_ALL="en_US.UTF-8" \ GHC_SMTP_PASSWORD=None \ GHC_METADATA_CACHE_SECS=900 \ \ -# WSGI server settings, assumed is gunicorn \ -HOST=0.0.0.0 \ -PORT=80 \ -WSGI_WORKERS=4 \ -WSGI_WORKER_TIMEOUT=6000 \ -WSGI_WORKER_CLASS='eventlet' \ -\ -# GHC Core Plugins modules and/or classes, seldom needed to set: \ -# if not specified here or in Container environment \ -# all GHC built-in Plugins will be active. \ -#ENV GHC_PLUGINS 'GeoHealthCheck.plugins.probe.owsgetcaps,\ -# GeoHealthCheck.plugins.probe.wms, ...., ...\ -# GeoHealthCheck.plugins.check.checks' \ -\ -# GHC User Plugins, best be overridden via Container environment \ -GHC_USER_PLUGINS='' + # WSGI server settings, assumed is gunicorn \ + HOST=0.0.0.0 \ + PORT=80 \ + WSGI_WORKERS=4 \ + WSGI_WORKER_TIMEOUT=6000 \ + WSGI_WORKER_CLASS='eventlet' \ + \ + # GHC Core Plugins modules and/or classes, seldom needed to set: \ + # if not specified here or in Container environment \ + # all GHC built-in Plugins will be active. \ + #ENV GHC_PLUGINS 'GeoHealthCheck.plugins.probe.owsgetcaps,\ + # GeoHealthCheck.plugins.probe.wms, ...., ...\ + # GeoHealthCheck.plugins.check.checks' \ + \ + # GHC User Plugins, best be overridden via Container environment \ + GHC_USER_PLUGINS='' RUN apk add --no-cache --virtual .build-deps gcc build-base libxslt-dev libxml2-dev linux-headers postgresql-dev \ && apk add --no-cache bash postgresql-client libxslt libxml2 tzdata openntpd python3 python3-dev \ From a99bd78c1cb30c74d30e1dd7b04de0f66b145be1 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 20 Dec 2019 16:15:30 +0100 Subject: [PATCH 22/49] Add paver again --- docker/scripts/requirements.txt | 3 +-- requirements.txt | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/scripts/requirements.txt b/docker/scripts/requirements.txt index fd68b637..e5794fdd 100644 --- a/docker/scripts/requirements.txt +++ b/docker/scripts/requirements.txt @@ -1,5 +1,4 @@ -Paver==1.3.4 -Sphinx==1.8.1 +Paver==1.3.4 # Paver is still required for 1 geohc cli command: geohc create-instance psycopg2==2.7.5 eventlet==0.24.1 gunicorn==19.9.0 diff --git a/requirements.txt b/requirements.txt index a937e4ce..7736133f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,4 @@ requests>=2.20.0 WTForms==2.2.1 APScheduler==3.6.1 passlib==1.7.1 +paver==1.3.4 From 6f8508d6c32cbe7c6255e586c88d3fa6dbfb7bc5 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 20 Dec 2019 16:16:03 +0100 Subject: [PATCH 23/49] Update tests to new imports --- tests/test_plugins.py | 10 +++++----- tests/test_resources.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 1ee3cdcd..864fcc1c 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -30,11 +30,11 @@ import unittest import os -from models import DB, load_data, Resource -from views import get_probes_avail -from plugin import Plugin -from probe import Probe -from factory import Factory +from GeoHealthCheck.models import DB, load_data, Resource +from GeoHealthCheck.views import get_probes_avail +from GeoHealthCheck.plugin import Plugin +from GeoHealthCheck.probe import Probe +from GeoHealthCheck.factory import Factory TEST_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/test_resources.py b/tests/test_resources.py index ab9df17e..ea418165 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -31,11 +31,11 @@ import unittest import os -from init import App -from models import (DB, Resource, Run, load_data, Recipient) -from healthcheck import run_test_resource -from notifications import _parse_webhook_location -from resourceauth import ResourceAuth +from GeoHealthCheck.init import App +from GeoHealthCheck.models import (DB, Resource, Run, load_data, Recipient) +from GeoHealthCheck.healthcheck import run_test_resource +from GeoHealthCheck.notifications import _parse_webhook_location +from GeoHealthCheck.resourceauth import ResourceAuth TEST_DIR = os.path.dirname(os.path.abspath(__file__)) From 898959008c9737d939621d12e9264dc498d5a601 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 20 Dec 2019 16:16:34 +0100 Subject: [PATCH 24/49] Cleanup and add documentation --- docker/README.md | 3 +++ docker/scripts/configure.sh | 1 - docker/scripts/run-runner.sh | 1 - docker/scripts/run-web.sh | 2 -- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docker/README.md b/docker/README.md index d0d3d4ca..d188cae3 100644 --- a/docker/README.md +++ b/docker/README.md @@ -97,6 +97,9 @@ docker-compose -f docker-compose.yml up [-d] # go to http://localhost:8083 (port 80 in GHC Container is mapped to 8083 on host) ``` +This setup maps the sqlite database to a docker volume (`ghc_sqlitedb`) that is stored on the +machine (outside the docker container). To get more information about the volume, run +`docker volume inspect ghc_sqlitedb`. ### Using PostGIS DB diff --git a/docker/scripts/configure.sh b/docker/scripts/configure.sh index c0386b54..71b2c85d 100755 --- a/docker/scripts/configure.sh +++ b/docker/scripts/configure.sh @@ -30,7 +30,6 @@ case ${DB_TYPE} in create_db else echo "NOT creating SQLite DB tables..." - geohc db-create #hoort hier niet fi ;; diff --git a/docker/scripts/run-runner.sh b/docker/scripts/run-runner.sh index 6f09a838..d8c3e24f 100755 --- a/docker/scripts/run-runner.sh +++ b/docker/scripts/run-runner.sh @@ -15,7 +15,6 @@ source /venv/bin/activate . # Make sure PYTHONPATH includes GeoHealthCheck export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH -cd /GeoHealthCheck geohc runner-daemon echo "END /run-runner.sh" diff --git a/docker/scripts/run-web.sh b/docker/scripts/run-web.sh index b30327e4..93726305 100755 --- a/docker/scripts/run-web.sh +++ b/docker/scripts/run-web.sh @@ -14,8 +14,6 @@ source /venv/bin/activate . # Make sure PYTHONPATH includes GeoHealthCheck export PYTHONPATH=/GeoHealthCheck:$PYTHONPATH -cd /GeoHealthCheck - geohc db-upgrade # SCRIPT_NAME should not have value '/' From 8a25408c4084f2022aecfb86ea0314420667a8ef Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 23 Dec 2019 07:02:57 +0100 Subject: [PATCH 25/49] Update install doc --- README.md | 3 +++ docs/install.rst | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef69c9d0..b670d63e 100644 --- a/README.md +++ b/README.md @@ -75,4 +75,7 @@ geohc db-load --help ``` +**Note for developers:** instead of `pip install .`, you might want to install with the *editable* +option specified: `pip install -e .` + More in the [full GHC documentation](http://docs.geohealthcheck.org/). \ No newline at end of file diff --git a/docs/install.rst b/docs/install.rst index 905a15bc..a034413c 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -54,7 +54,7 @@ Install git clone https://github.com/geopython/GeoHealthCheck.git cd GeoHealthCheck - # install paver dependency for admin tool + # install pip install . # setup app @@ -95,6 +95,12 @@ Install NB GHC supports internal scheduling, no cronjobs required. +Developing +.......... +If you plan to develop with the GeoHealthCheck code base, you might want to install with the +*editable* option specified: `pip install -e`. This gives you access to the command line interface, +and you can still edit and run the code. + .. _upgrade: Upgrade From abf71b8e7feda63fd33162123b0522f2b6d2892e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Thu, 26 Dec 2019 21:45:32 +0100 Subject: [PATCH 26/49] WIP: convert setup command TODO: test the create-instance, double check os.path things --- GeoHealthCheck/geohc_cli.py | 102 ++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 2f0c51c0..68dac310 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -74,10 +74,104 @@ def create_instance(ctx): This command is a copy of `paver setup` """ verbose_echo(ctx, 'GeoHC: create instance') - # calling paver for the setup - # TODO: phase out paver and switch to click - from os import system - system('paver setup') + import glob, os, shutil + from io import BytesIO + from urllib.request import urlopen + import zipfile + basedir = os.path.abspath(os.path.dirname(__file__)) + config_file = os.path.normpath('%s/GeoHealthCheck/config_main.py' % basedir) + config_site = os.path.normpath('%s/config_site.py' % basedir) + + # setup dirs + if not os.path.exists(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)): + os.mkdir(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) + if not os.path.exists(os.path.normpath('%s/instance' % basedir)): + os.mkdir(os.path.normpath('%s/instance' % basedir)) + data_dir = os.path.normpath('%s/instance/data' % basedir) + os.mkdir(data_dir, mode=0o777) + # setup config + config_file.copy(config_site) + + skin = 'http://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/v3.3.7+1.zip' # noqa + + skin_dirs = ['dist', 'vendor'] + need_to_fetch = False + + for skin_dir in skin_dirs: + skin_dir_path = os.sep.join( + ['startbootstrap-sb-admin-2-3.3.7-1', skin_dir]) + if not os.path.exists(skin_dir_path): + need_to_fetch = True + + if need_to_fetch: + zipstr = BytesIO(urlopen(skin).read()) + zipfile_obj = zipfile.ZipFile(zipstr) + zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) + + for zf_mem in skin_dirs: + src_loc = os.path.normpath('%s/GeoHealthCheck/static/lib' + 'startbootstrap-sb-admin-2-3.3.7-1/%s' %basedir, zf_mem) + dest_loc = os.path.normpath('%s/GeoHealthCheck/static/lib%s' %basedir, zf_mem) + if not os.path.exists(dest_loc): + src_loc.move(dest_loc) + else: + click.echo('directory already exists. Skipping') + + shutil.rmtree(os.path.normpath('%s/GeoHealthCheck/static/lib' + 'startbootstrap-sb-admin-2-3.3.7-1' %basedir)) + + # install sparklines to static/site/js + with open(os.path.normpath('%s/GeoHealthCheck/static/lib' + 'startbootstrap-sb-admin-2-3.3.7-1/jspark.js' %basedir ), 'w') as f: + content = urlopen('http://ejohn.org/files/jspark.js').read().decode() + content.replace('red', 'green') + f.write(content) + + # install bootstrap-tagsinput to static/lib + click.echo('Getting select2') + select2 = 'https://github.com/select2/select2/archive/4.0.3.zip' + + zipstr = BytesIO(urlopen(select2).read()) + zipfile_obj = zipfile.ZipFile(zipstr) + zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) + dirname = glob.glob(os.path.normpath('%s/GeoHealthCheck/static/lib/select2-*' % basedir))[0] + dstdir = ''.join(dirname.rsplit('-', 1)[:-1]) + try: + os.rename(dirname, dstdir) + except OSError: + shutil.rmtree(dstdir) + os.rename(dirname, dstdir) + + # install leafletjs to static/lib + click.echo('Getting leaflet') + leafletjs = 'http://cdn.leafletjs.com/downloads/leaflet-0.7.5.zip' + + zipstr = BytesIO(urlopen(leafletjs).read()) + zipfile_obj = zipfile.ZipFile(zipstr) + zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib/leaflet' % basedir)) + + # install html5shiv to static/lib + with open(os.path.normpath('%s/GeoHealthCheck/static/lib/html5shiv.min.js' % basedir), 'w') as f: + url = 'http://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js' + content = urlopen(url).read().decode() + f.write(content) + + # install respond to static/lib + with open(os.path.normpath('%s/GeoHealthCheck/static/lib/respond.min.js' % basedir), 'w') as f: + url = 'http://oss.maxcdn.com/respond/1.4.2/respond.min.js' + content = urlopen(url).read().decode() + f.write(content) + + # build i18n .mo files + lang_compile_translations(ctx) + + # build local docs + update_docs(ctx) + + # message user + click.echo('GeoHealthCheck is now built. Edit settings in %s' % config_site) + click.echo('before deploying the application. Alternatively, you can start a') + click.echo('development instance with "python GeoHealthCheck/app.py"') verbose_echo(ctx, 'GeoHC: finished creating the instance.') From 3a3bd773326eb260edd90b44dabdc88df56c12b7 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 1 Jan 2020 22:41:30 +0100 Subject: [PATCH 27/49] Fix path errors and wrap click functions --- GeoHealthCheck/geohc_cli.py | 62 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 68dac310..c2d42aa9 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -76,21 +76,24 @@ def create_instance(ctx): verbose_echo(ctx, 'GeoHC: create instance') import glob, os, shutil from io import BytesIO + from pathlib import Path from urllib.request import urlopen import zipfile basedir = os.path.abspath(os.path.dirname(__file__)) - config_file = os.path.normpath('%s/GeoHealthCheck/config_main.py' % basedir) - config_site = os.path.normpath('%s/config_site.py' % basedir) + config_file = os.path.normpath('%s/config_main.py' % basedir) + config_site = os.path.normpath(str(Path(os.path.normpath('%s' % basedir)). + parent) + + '/instance/config_site.py') # setup dirs - if not os.path.exists(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)): - os.mkdir(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) + if not os.path.exists(os.path.normpath('%s/static/lib' % basedir)): + os.mkdir(os.path.normpath('%s/static/lib' % basedir)) if not os.path.exists(os.path.normpath('%s/instance' % basedir)): os.mkdir(os.path.normpath('%s/instance' % basedir)) data_dir = os.path.normpath('%s/instance/data' % basedir) os.mkdir(data_dir, mode=0o777) # setup config - config_file.copy(config_site) + shutil.copy(config_file, config_site) skin = 'http://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/v3.3.7+1.zip' # noqa @@ -106,23 +109,23 @@ def create_instance(ctx): if need_to_fetch: zipstr = BytesIO(urlopen(skin).read()) zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) + zipfile_obj.extractall(os.path.normpath('%s/static/lib' % basedir)) for zf_mem in skin_dirs: - src_loc = os.path.normpath('%s/GeoHealthCheck/static/lib' - 'startbootstrap-sb-admin-2-3.3.7-1/%s' %basedir, zf_mem) - dest_loc = os.path.normpath('%s/GeoHealthCheck/static/lib%s' %basedir, zf_mem) + src_loc = os.path.normpath('%s/static/lib/' + 'startbootstrap-sb-admin-2-3.3.7-1/%s' %(basedir, zf_mem)) + dest_loc = os.path.normpath('%s/static/lib/%s' %(basedir, zf_mem)) if not os.path.exists(dest_loc): - src_loc.move(dest_loc) + shutil.move(src_loc, dest_loc) else: click.echo('directory already exists. Skipping') - shutil.rmtree(os.path.normpath('%s/GeoHealthCheck/static/lib' + shutil.rmtree(os.path.normpath('%s/static/lib/' 'startbootstrap-sb-admin-2-3.3.7-1' %basedir)) # install sparklines to static/site/js - with open(os.path.normpath('%s/GeoHealthCheck/static/lib' - 'startbootstrap-sb-admin-2-3.3.7-1/jspark.js' %basedir ), 'w') as f: + with open(os.path.normpath('%s/static/lib/' + 'jspark.js' %basedir ), 'w') as f: content = urlopen('http://ejohn.org/files/jspark.js').read().decode() content.replace('red', 'green') f.write(content) @@ -133,14 +136,14 @@ def create_instance(ctx): zipstr = BytesIO(urlopen(select2).read()) zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib' % basedir)) - dirname = glob.glob(os.path.normpath('%s/GeoHealthCheck/static/lib/select2-*' % basedir))[0] + zipfile_obj.extractall(os.path.normpath('%s/static/lib' % basedir)) + dirname = glob.glob(os.path.normpath('%s/static/lib/select2-*' % basedir))[0] dstdir = ''.join(dirname.rsplit('-', 1)[:-1]) try: - os.rename(dirname, dstdir) + shutil.move(dirname, dstdir) except OSError: shutil.rmtree(dstdir) - os.rename(dirname, dstdir) + shutil.move(dirname, dstdir) # install leafletjs to static/lib click.echo('Getting leaflet') @@ -148,25 +151,25 @@ def create_instance(ctx): zipstr = BytesIO(urlopen(leafletjs).read()) zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(os.path.normpath('%s/GeoHealthCheck/static/lib/leaflet' % basedir)) + zipfile_obj.extractall(os.path.normpath('%s/static/lib/leaflet' % basedir)) # install html5shiv to static/lib - with open(os.path.normpath('%s/GeoHealthCheck/static/lib/html5shiv.min.js' % basedir), 'w') as f: + with open(os.path.normpath('%s/static/lib/html5shiv.min.js' % basedir), 'w') as f: url = 'http://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js' content = urlopen(url).read().decode() f.write(content) # install respond to static/lib - with open(os.path.normpath('%s/GeoHealthCheck/static/lib/respond.min.js' % basedir), 'w') as f: + with open(os.path.normpath('%s/static/lib/respond.min.js' % basedir), 'w') as f: url = 'http://oss.maxcdn.com/respond/1.4.2/respond.min.js' content = urlopen(url).read().decode() f.write(content) # build i18n .mo files - lang_compile_translations(ctx) + compile_translations(ctx) # build local docs - update_docs(ctx) + update_documentation(ctx) # message user click.echo('GeoHealthCheck is now built. Edit settings in %s' % config_site) @@ -369,12 +372,16 @@ def create_wsgi(ctx): @click.pass_context def update_docs(ctx): """Update the spinx build of the documentation.""" + update_documentation(ctx) + +def update_documentation(ctx): verbose_echo(ctx, 'GeoHC: start building documentation.') import os import shutil + from pathlib import Path - basedir = os.path.abspath(os.path.dirname(__file__)) + basedir = str(Path(os.path.abspath(os.path.dirname(__file__))).parent) static_docs = os.path.normpath('%s/GeoHealthCheck/static/docs' % basedir) docs = os.path.normpath('%s/docs' % basedir) @@ -458,8 +465,8 @@ def lang_add_language_catalogue(ctx, lang): import os basedir = os.path.abspath(os.path.dirname(__file__)) base_pot = os.path.normpath( - '%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % basedir) - translations = os.path.normpath('%s/GeoHealthCheck/translations' % basedir) + '%s/translations/en/LC_MESSAGES/messages.po' % basedir) + translations = os.path.normpath('%s/translations' % basedir) verbose_echo(ctx, 'GeoHC: Base translation set: %s' % base_pot) os.system('pybabel init -i %s -d %s -l %s' % ( base_pot, translations, lang)) @@ -469,11 +476,14 @@ def lang_add_language_catalogue(ctx, lang): @cli.command() @click.pass_context def lang_compile_translations(ctx): + compile_translations(ctx) + +def compile_translations(ctx): """build language files""" verbose_echo(ctx, 'GeoHC: start building language files.') import os basedir = os.path.abspath(os.path.dirname(__file__)) - translations = os.path.normpath('%s/GeoHealthCheck/translations' % basedir) + translations = os.path.normpath('%s/translations' % basedir) os.system('pybabel compile -d %s' % translations) click.echo('GeoHC: Finished building language files.') From 8e5c8bb36287c155ee41638a322369c2e06951cd Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 3 Jan 2020 22:49:54 +0100 Subject: [PATCH 28/49] Update path things in cli --- GeoHealthCheck/geohc_cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index c2d42aa9..990d1ebf 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -80,17 +80,16 @@ def create_instance(ctx): from urllib.request import urlopen import zipfile basedir = os.path.abspath(os.path.dirname(__file__)) + basedir_parent = os.path.normpath(str(Path(basedir))) config_file = os.path.normpath('%s/config_main.py' % basedir) - config_site = os.path.normpath(str(Path(os.path.normpath('%s' % basedir)). - parent) - + '/instance/config_site.py') + config_site = os.path.normpath(basedir_parent + '/instance/config_site.py') # setup dirs if not os.path.exists(os.path.normpath('%s/static/lib' % basedir)): os.mkdir(os.path.normpath('%s/static/lib' % basedir)) if not os.path.exists(os.path.normpath('%s/instance' % basedir)): - os.mkdir(os.path.normpath('%s/instance' % basedir)) - data_dir = os.path.normpath('%s/instance/data' % basedir) + os.mkdir(os.path.normpath('%s/instance' % basedir_parent)) + data_dir = os.path.normpath('%s/instance/data' % basedir_parent) os.mkdir(data_dir, mode=0o777) # setup config shutil.copy(config_file, config_site) From 1e6129e6f26d23f6e0d25fe9349de1724e816e2a Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 3 Jan 2020 23:14:01 +0100 Subject: [PATCH 29/49] Fix flake8 issues --- GeoHealthCheck/app.py | 6 ++++-- GeoHealthCheck/geohc_cli.py | 37 ++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/GeoHealthCheck/app.py b/GeoHealthCheck/app.py index 37d37764..66a5440b 100644 --- a/GeoHealthCheck/app.py +++ b/GeoHealthCheck/app.py @@ -47,7 +47,8 @@ from GeoHealthCheck.enums import RESOURCE_TYPES from GeoHealthCheck.factory import Factory from GeoHealthCheck.init import App -from GeoHealthCheck.models import Resource, Run, ProbeVars, CheckVars, Tag, User, Recipient +from GeoHealthCheck.models import Resource, Run, ProbeVars, CheckVars, Tag, \ + User, Recipient from GeoHealthCheck.resourceauth import ResourceAuth from GeoHealthCheck.util import send_email, geocode, format_checked_datetime, \ format_run_status, format_obj_value @@ -531,7 +532,8 @@ def add(): url = request.form['url'].strip() resources_to_add = [] - from GeoHealthCheck.healthcheck import sniff_test_resource, run_test_resource + from GeoHealthCheck.healthcheck import sniff_test_resource, \ + run_test_resource sniffed_resources = sniff_test_resource(CONFIG, resource_type, url) if not sniffed_resources: diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 990d1ebf..717c52eb 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -74,7 +74,9 @@ def create_instance(ctx): This command is a copy of `paver setup` """ verbose_echo(ctx, 'GeoHC: create instance') - import glob, os, shutil + import glob + import os + import shutil from io import BytesIO from pathlib import Path from urllib.request import urlopen @@ -112,19 +114,21 @@ def create_instance(ctx): for zf_mem in skin_dirs: src_loc = os.path.normpath('%s/static/lib/' - 'startbootstrap-sb-admin-2-3.3.7-1/%s' %(basedir, zf_mem)) - dest_loc = os.path.normpath('%s/static/lib/%s' %(basedir, zf_mem)) + 'startbootstrap-sb-admin-2-3.3.7-1/%s' + % (basedir, zf_mem)) + dest_loc = os.path.normpath('%s/static/lib/%s' % (basedir, zf_mem)) if not os.path.exists(dest_loc): shutil.move(src_loc, dest_loc) else: click.echo('directory already exists. Skipping') - shutil.rmtree(os.path.normpath('%s/static/lib/' - 'startbootstrap-sb-admin-2-3.3.7-1' %basedir)) + shutil.rmtree(os.path.normpath('%s/static/lib/' + 'startbootstrap-sb-admin-2-3.3.7-1' + % basedir)) # install sparklines to static/site/js - with open(os.path.normpath('%s/static/lib/' - 'jspark.js' %basedir ), 'w') as f: + with open(os.path.normpath('%s/static/lib/' + 'jspark.js' % basedir), 'w') as f: content = urlopen('http://ejohn.org/files/jspark.js').read().decode() content.replace('red', 'green') f.write(content) @@ -136,7 +140,8 @@ def create_instance(ctx): zipstr = BytesIO(urlopen(select2).read()) zipfile_obj = zipfile.ZipFile(zipstr) zipfile_obj.extractall(os.path.normpath('%s/static/lib' % basedir)) - dirname = glob.glob(os.path.normpath('%s/static/lib/select2-*' % basedir))[0] + dirname = glob.glob(os.path.normpath('%s/static/lib/select2-*' + % basedir))[0] dstdir = ''.join(dirname.rsplit('-', 1)[:-1]) try: shutil.move(dirname, dstdir) @@ -153,13 +158,15 @@ def create_instance(ctx): zipfile_obj.extractall(os.path.normpath('%s/static/lib/leaflet' % basedir)) # install html5shiv to static/lib - with open(os.path.normpath('%s/static/lib/html5shiv.min.js' % basedir), 'w') as f: + with open(os.path.normpath('%s/static/lib/html5shiv.min.js' % basedir), + 'w') as f: url = 'http://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js' content = urlopen(url).read().decode() f.write(content) # install respond to static/lib - with open(os.path.normpath('%s/static/lib/respond.min.js' % basedir), 'w') as f: + with open(os.path.normpath('%s/static/lib/respond.min.js' % basedir), + 'w') as f: url = 'http://oss.maxcdn.com/respond/1.4.2/respond.min.js' content = urlopen(url).read().decode() f.write(content) @@ -171,9 +178,11 @@ def create_instance(ctx): update_documentation(ctx) # message user - click.echo('GeoHealthCheck is now built. Edit settings in %s' % config_site) - click.echo('before deploying the application. Alternatively, you can start a') - click.echo('development instance with "python GeoHealthCheck/app.py"') + click.echo('GeoHealthCheck is now built. Edit settings in %s' + % config_site) + click.echo('before deploying the application. Alternatively, you can') + click.echo('start a development instance with ') + click.echo('"python GeoHealthCheck/app.py"') verbose_echo(ctx, 'GeoHC: finished creating the instance.') @@ -373,6 +382,7 @@ def update_docs(ctx): """Update the spinx build of the documentation.""" update_documentation(ctx) + def update_documentation(ctx): verbose_echo(ctx, 'GeoHC: start building documentation.') @@ -477,6 +487,7 @@ def lang_add_language_catalogue(ctx, lang): def lang_compile_translations(ctx): compile_translations(ctx) + def compile_translations(ctx): """build language files""" verbose_echo(ctx, 'GeoHC: start building language files.') From fce898f90b879ae643199f502f449558e18f3761 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Fri, 3 Jan 2020 23:27:21 +0100 Subject: [PATCH 30/49] Remove paver from docker requirements --- docker/scripts/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/scripts/requirements.txt b/docker/scripts/requirements.txt index e5794fdd..30ed0374 100644 --- a/docker/scripts/requirements.txt +++ b/docker/scripts/requirements.txt @@ -1,4 +1,3 @@ -Paver==1.3.4 # Paver is still required for 1 geohc cli command: geohc create-instance psycopg2==2.7.5 eventlet==0.24.1 gunicorn==19.9.0 From 88675bfa9ecc1925fd862bb985ed8c1691db5c14 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 6 Jan 2020 22:37:26 +0100 Subject: [PATCH 31/49] WIP: fix paths in docker --- GeoHealthCheck/geohc_cli.py | 12 +++++++++--- docker/scripts/install.sh | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 717c52eb..2e06ba7d 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -68,7 +68,8 @@ def version(ctx): @cli.command() @click.pass_context -def create_instance(ctx): +@click.option('--basepath', '-p', type=str, help='path to the directory to install the instance data and help files.') +def create_instance(ctx, basepath): """Create an instance of GeoHealthCheck App This command is a copy of `paver setup` @@ -82,6 +83,9 @@ def create_instance(ctx): from urllib.request import urlopen import zipfile basedir = os.path.abspath(os.path.dirname(__file__)) + if (basepath != None): + basedir = os.path.abspath(basepath) + verbose_echo(ctx, 'Setting base install directory to %s' %basedir) basedir_parent = os.path.normpath(str(Path(basedir))) config_file = os.path.normpath('%s/config_main.py' % basedir) config_site = os.path.normpath(basedir_parent + '/instance/config_site.py') @@ -175,7 +179,7 @@ def create_instance(ctx): compile_translations(ctx) # build local docs - update_documentation(ctx) + update_documentation(ctx, basedir_parent) # message user click.echo('GeoHealthCheck is now built. Edit settings in %s' @@ -383,7 +387,7 @@ def update_docs(ctx): update_documentation(ctx) -def update_documentation(ctx): +def update_documentation(ctx, basepath=None): verbose_echo(ctx, 'GeoHC: start building documentation.') import os @@ -391,6 +395,8 @@ def update_documentation(ctx): from pathlib import Path basedir = str(Path(os.path.abspath(os.path.dirname(__file__))).parent) + if basepath: + basedir = os.path.abspath(basepath) static_docs = os.path.normpath('%s/GeoHealthCheck/static/docs' % basedir) docs = os.path.normpath('%s/docs' % basedir) diff --git a/docker/scripts/install.sh b/docker/scripts/install.sh index 363fb03c..07c77ec3 100755 --- a/docker/scripts/install.sh +++ b/docker/scripts/install.sh @@ -14,7 +14,7 @@ cd /GeoHealthCheck pip install . # Sets up GHC itself -geohc create-instance +geohc create-instance --basepath /GeoHealthCheck/GeoHealthCheck mv /config_site.py /GeoHealthCheck/instance/config_site.py # Copy possible Plugins into app tree From a6a1da067abed11a23886d0ca0b1266518861a4a Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Tue, 7 Jan 2020 22:28:11 +0100 Subject: [PATCH 32/49] Fix docker build --- GeoHealthCheck/geohc_cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 2e06ba7d..9d8f2507 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -86,7 +86,7 @@ def create_instance(ctx, basepath): if (basepath != None): basedir = os.path.abspath(basepath) verbose_echo(ctx, 'Setting base install directory to %s' %basedir) - basedir_parent = os.path.normpath(str(Path(basedir))) + basedir_parent = os.path.normpath(str(Path(basedir).parent)) config_file = os.path.normpath('%s/config_main.py' % basedir) config_site = os.path.normpath(basedir_parent + '/instance/config_site.py') @@ -176,10 +176,10 @@ def create_instance(ctx, basepath): f.write(content) # build i18n .mo files - compile_translations(ctx) + compile_translations(ctx, path=basedir) # build local docs - update_documentation(ctx, basedir_parent) + update_documentation(ctx, basepath=basedir_parent) # message user click.echo('GeoHealthCheck is now built. Edit settings in %s' @@ -494,11 +494,11 @@ def lang_compile_translations(ctx): compile_translations(ctx) -def compile_translations(ctx): +def compile_translations(ctx, path=None): """build language files""" verbose_echo(ctx, 'GeoHC: start building language files.') import os - basedir = os.path.abspath(os.path.dirname(__file__)) + basedir = path if path else os.path.abspath(os.path.dirname(__file__)) translations = os.path.normpath('%s/translations' % basedir) os.system('pybabel compile -d %s' % translations) click.echo('GeoHC: Finished building language files.') From 74d14554fae88f152dc31b4b1f2c9a01608a63a7 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 21:31:08 +0100 Subject: [PATCH 33/49] Fix flake8 --- GeoHealthCheck/geohc_cli.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/geohc_cli.py index 9d8f2507..25523098 100644 --- a/GeoHealthCheck/geohc_cli.py +++ b/GeoHealthCheck/geohc_cli.py @@ -68,7 +68,8 @@ def version(ctx): @cli.command() @click.pass_context -@click.option('--basepath', '-p', type=str, help='path to the directory to install the instance data and help files.') +@click.option('--basepath', '-p', type=str, help='path to the directory to' + 'install the instance data and help files.') def create_instance(ctx, basepath): """Create an instance of GeoHealthCheck App @@ -83,9 +84,9 @@ def create_instance(ctx, basepath): from urllib.request import urlopen import zipfile basedir = os.path.abspath(os.path.dirname(__file__)) - if (basepath != None): + if (basepath is not None): basedir = os.path.abspath(basepath) - verbose_echo(ctx, 'Setting base install directory to %s' %basedir) + verbose_echo(ctx, 'Setting base install directory to %s' % basedir) basedir_parent = os.path.normpath(str(Path(basedir).parent)) config_file = os.path.normpath('%s/config_main.py' % basedir) config_site = os.path.normpath(basedir_parent + '/instance/config_site.py') From 09e87bb5e17603263950394969da0d0ce6e3fa2e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 22:19:11 +0100 Subject: [PATCH 34/49] Fix travis build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6986bcc5..ef1f1f5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ sudo: false install: - pip install . - - geohc create-instance + - geohc create-instance -p /home/travis/geopython/geohealthcheck script: - geohc db-create From 25a3cbc71161936c808849b41bf0104bbabf2348 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 22:25:03 +0100 Subject: [PATCH 35/49] Fix travis build -2 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef1f1f5b..76622454 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ python: sudo: false install: - - pip install . - - geohc create-instance -p /home/travis/geopython/geohealthcheck + - pip install -e . + - geohc create-instance script: - geohc db-create From 7e194256693ac05e30ab06e777d1f3943d86f9c7 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 22:28:46 +0100 Subject: [PATCH 36/49] Fix travis build -3 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 76622454..7a3529b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,13 +7,14 @@ sudo: false install: - pip install -e . + - pip install -r requirements-dev.txt - geohc create-instance script: - geohc db-create - geohc db-adduser -u admin -p test -e you@example.com -r admin - flake8 - - geohc db-load -y tests/data/fixtures.json -y + - geohc db-load -f tests/data/fixtures.json -y - geohc run-healthchecks - geohc run-tests - cd docs && make html From 5b708d5c5bba2f664bc3ec3fdece582f10aae7f5 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 22:34:27 +0100 Subject: [PATCH 37/49] Fix flake8 issues --- setup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3caf46a1..ee8501fb 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,8 @@ def read(filename, encoding='utf-8'): """read file contents""" - full_path = os.path.join(os.path.dirname(__file__), filename) + full_path = os.path.join(os.path.dirname(__file__), + filename) with io.open(filename, encoding=encoding) as fh: contents = fh.read().strip() return contents @@ -50,7 +51,8 @@ def get_package_version(): LONG_DESCRIPTION = read('README.md') -DESCRIPTION = 'GeoHealthCheck is a Quality of Service Checker for OGC Web Services and web APIs.' +DESCRIPTION = 'GeoHealthCheck is a Quality of Service Checker for OGC Web' \ + 'Services and web APIs.' setup( name='geohealthcheck', From 71ea488701659ae232a22efa1f53cab9ce563d04 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 8 Jan 2020 22:37:05 +0100 Subject: [PATCH 38/49] Fix flake8 issues --- setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.py b/setup.py index ee8501fb..9a21c861 100644 --- a/setup.py +++ b/setup.py @@ -28,14 +28,11 @@ # # ================================================================= import io -import os from setuptools import find_packages, setup def read(filename, encoding='utf-8'): """read file contents""" - full_path = os.path.join(os.path.dirname(__file__), - filename) with io.open(filename, encoding=encoding) as fh: contents = fh.read().strip() return contents From 0d2cc5c501696cb2c3fbb56f513a4d6b242909a4 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 06:53:13 +0100 Subject: [PATCH 39/49] Update format versionnumner --- GeoHealthCheck/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GeoHealthCheck/__init__.py b/GeoHealthCheck/__init__.py index 99e02e83..f8ac92ff 100644 --- a/GeoHealthCheck/__init__.py +++ b/GeoHealthCheck/__init__.py @@ -27,4 +27,4 @@ # # ================================================================= -__version__ = '0.8.0dev' +__version__ = '0.8.dev0' From 4263ffe3c9a185560c3f854eba33af22f01580eb Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 06:54:15 +0100 Subject: [PATCH 40/49] Rename file geohc_cli to cli --- GeoHealthCheck/{geohc_cli.py => cli.py} | 0 setup.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename GeoHealthCheck/{geohc_cli.py => cli.py} (100%) diff --git a/GeoHealthCheck/geohc_cli.py b/GeoHealthCheck/cli.py similarity index 100% rename from GeoHealthCheck/geohc_cli.py rename to GeoHealthCheck/cli.py diff --git a/setup.py b/setup.py index 9a21c861..db3d1905 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ def get_package_version(): include_package_data=True, entry_points={ 'console_scripts': [ - 'geohc=GeoHealthCheck.geohc_cli:cli', + 'geohc=GeoHealthCheck.cli:cli', ] }, classifiers=[ From b68098dd8a5145dc74ea0ee9649bdabdb1014c2e Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 06:58:09 +0100 Subject: [PATCH 41/49] Use LOGGER.warning instead of warnings module --- GeoHealthCheck/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index fc029b18..57b5c901 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -30,7 +30,6 @@ import json import logging -import warnings from flask_babel import gettext as _ from datetime import datetime, timedelta from itsdangerous import TimedJSONWebSignatureSerializer as Serializer @@ -894,7 +893,7 @@ def db_commit(): if len(sys.argv) > 1: if sys.argv[1] == 'create': - warnings.warn('models.py create is deprecated since 0.8.0. Please' + LOGGER.warning('models.py create is deprecated since 0.8.0. Please' ' use cli: `geohc db-create` and `geohc db-adduser`', DeprecationWarning) print('Creating database objects') @@ -921,14 +920,14 @@ def db_commit(): db_commit() elif sys.argv[1] == 'drop': - warnings.warn('models.py drop is deprecated since 0.8.0. Please ' + LOGGER.warning('models.py drop is deprecated since 0.8.0. Please ' 'use cli: `geohc db-drop`', DeprecationWarning) print('Dropping database objects') DB.drop_all() db_commit() elif sys.argv[1] == 'load': - warnings.warn('models.py load is deprecated since 0.8.0. Please ' + LOGGER.warning('models.py load is deprecated since 0.8.0. Please ' 'use cli: `geohc db-load`', DeprecationWarning) print('Load database from JSON file (e.g. tests/fixtures.json)') if len(sys.argv) > 2: @@ -953,11 +952,11 @@ def db_commit(): print('Provide path to JSON file, e.g. tests/fixtures.json') elif sys.argv[1] == 'run': - warnings.warn('models.py run is deprecated. Please use `python ' + LOGGER.warning('models.py run is deprecated. Please use `python ' 'healthcheck.py`', DeprecationWarning) elif sys.argv[1] == 'flush': - warnings.warn('models.py flush is deprecated since 0.8.0. Please ' + LOGGER.warning('models.py flush is deprecated since 0.8.0. Please ' 'use cli: `geohc db-flush`', DeprecationWarning) flush_runs() From bb96eb0f11ada1a71b80151a5aa1d7a7e5401d61 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 07:10:07 +0100 Subject: [PATCH 42/49] Fix acquiring version number --- VERSION | 1 - setup.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 3128c152..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.8.dev0 diff --git a/setup.py b/setup.py index db3d1905..15241dc3 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ # # ================================================================= import io +import re from setuptools import find_packages, setup @@ -40,9 +41,11 @@ def read(filename, encoding='utf-8'): def get_package_version(): """get version from top-level package init""" - version_file = read('VERSION') - if version_file: - return version_file + version_file = read('GeoHealthCheck/__init__.py') + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) raise RuntimeError("Unable to find version string.") From f6da999fe568ad61ba1b95f10759de18bf1f1f46 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 15:53:30 +0100 Subject: [PATCH 43/49] Update name to correct use of capitals --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 15241dc3..85a3effd 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ def get_package_version(): 'Services and web APIs.' setup( - name='geohealthcheck', + name='GeoHealthCheck', version=get_package_version(), description=DESCRIPTION, long_description=LONG_DESCRIPTION, From 040aa0a74c8d810e27144e889ca9732ea669611c Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 21:42:31 +0100 Subject: [PATCH 44/49] Create cli subcommand for database --- .travis.yml | 8 +- GeoHealthCheck/cli.py | 260 +++++++++++++++++++----------------- GeoHealthCheck/models.py | 8 +- README.md | 12 +- docker/scripts/configure.sh | 4 +- docker/scripts/run-web.sh | 2 +- docs/admin.rst | 16 +-- 7 files changed, 160 insertions(+), 150 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a3529b5..c0ee9d76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,13 +11,13 @@ install: - geohc create-instance script: - - geohc db-create - - geohc db-adduser -u admin -p test -e you@example.com -r admin + - geohc db create + - geohc db adduser -u admin -p test -e you@example.com -r admin - flake8 - - geohc db-load -f tests/data/fixtures.json -y + - geohc db load -f tests/data/fixtures.json -y - geohc run-healthchecks - geohc run-tests - cd docs && make html after-script: - - geohc db-drop + - geohc db drop diff --git a/GeoHealthCheck/cli.py b/GeoHealthCheck/cli.py index 25523098..35c5070b 100644 --- a/GeoHealthCheck/cli.py +++ b/GeoHealthCheck/cli.py @@ -208,113 +208,6 @@ def serve(ctx, host, port): system(f"python app.py {host}:{port}") -@cli.command() -@click.pass_context -def db_create(ctx): - """Create the GHC database - - Note: you still need to add a user - """ - verbose_echo(ctx, 'GeoHC: create db') - from GeoHealthCheck.init import App - from GeoHealthCheck.models import db_commit - verbose_echo(ctx, 'GeoHC: get database') - DB = App.get_db() - verbose_echo(ctx, 'GeoHC: create all tables') - DB.create_all() - db_commit() - DB.session.remove() - click.echo('Database is created. Use `geohc db-adduser` to add users to ' - 'the database.') - - -@cli.command() -@click.pass_context -@click.option('-u', '--user', type=str, help='username', prompt=True) -@click.option('-e', '--email', type=str, help='email address', prompt=True) -@click.option('-p', '--password', type=str, help='password', prompt=True, - hide_input=True, confirmation_prompt=True) -@click.option('-r', '--role', type=click.Choice(['admin', 'user']), - prompt=True, help='role for this user') -def db_adduser(ctx, user, email, password, role): - """Add an user to the database - """ - verbose_echo(ctx, 'GeoHC: add user to database') - from GeoHealthCheck.init import App - from GeoHealthCheck.models import User, db_commit - verbose_echo(ctx, 'GeoHC: get database') - DB = App.get_db() - verbose_echo(ctx, 'GeoHC: create user') - user_to_add = User(user, password, email, role=role) - verbose_echo(ctx, 'GeoHC: adding user to database') - DB.session.add(user_to_add) - db_commit() - DB.session.remove() - click.echo(f'User {user} is added.') - - -@cli.command() -@click.pass_context -@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, - expose_value=False, help='Confirm dropping tables', - prompt='This will drop the tables in the database. Are you ' - 'sure?') -def db_drop(ctx): - """Drop the current database - """ - verbose_echo(ctx, 'GeoHC: drop db') - click.confirm("This will drop the tables in the database. Are you sure?", - abort=True) - verbose_echo(ctx, 'User confirmed dropping tables') - from GeoHealthCheck.init import App - from GeoHealthCheck.models import db_commit - verbose_echo(ctx, 'GeoHC: get database') - DB = App.get_db() - verbose_echo(ctx, 'GeoHC: dropping all tables') - DB.drop_all() - db_commit() - DB.session.remove() - click.echo('Database dropped all tables.') - - -@cli.command() -@click.pass_context -@click.option('-f', '--file', type=click.Path(), multiple=False, required=True, - help='Path to the file to load into the database. MUST be JSON.') -@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, - expose_value=False, help='Confirm dropping old content.', - prompt='WARNING: all database data will be lost. Proceed?') -def db_load(ctx, file): - """Load JSON into the database - - e.g. test/data/fixtures.json - """ - verbose_echo(ctx, 'GeoHC: load data into db') - verbose_echo(ctx, 'User confirmed loading new data and losing old data.') - from GeoHealthCheck.init import App - from GeoHealthCheck.models import load_data - DB = App.get_db() - if file[-5:].lower() != '.json': - click.echo("File must have '.json' file extension. Aborting import.") - ctx.exit() - verbose_echo(ctx, 'Start loading file.') - load_data(file) - verbose_echo(ctx, 'Data loaded!') - DB.session.remove() - click.echo('Finished loading data.') - - -@cli.command() -@click.pass_context -def db_flush(ctx): - """Flush runs: remove old data over retention date. - """ - verbose_echo(ctx, 'GeoHC: flush old runs from database.') - from GeoHealthCheck.models import flush_runs - flush_runs() - click.echo('Finished flushing old runs from database.') - - @cli.command() @click.pass_context def create_secret_key(ctx): @@ -341,18 +234,6 @@ def create_hash(ctx, password): click.echo(token) -@cli.command() -@click.pass_context -def db_upgrade(ctx): - """Upgrade the database - """ - verbose_echo(ctx, 'GeoHC: upgrade db') - from os import system, chdir - chdir('GeoHealthCheck') - system('python manage.py db upgrade') - click.echo('Upgrade DB finished.') - - @cli.command() @click.pass_context def create_wsgi(ctx): @@ -541,12 +422,6 @@ def run_healthchecks(ctx): click.echo('GeoHC: Finished running the healthchecks.') -@cli.command() -@click.pass_context -def db_export(ctx): - click.exho('GeoHC: todo- write export.') - - @cli.command() @click.pass_context def run_tests(ctx): @@ -565,5 +440,140 @@ def build_wheel(ctx): click.echo('GeoHC: Finished building a wheel.') +# Database sub commands +@cli.group() +@click.pass_context +@click.option('--verbose', '-v', is_flag=True, help='Verbose') +def db(ctx, verbose): + """Database subcommands""" + ctx.ensure_object(dict) + ctx.obj['VERBOSE'] = verbose + + +@db.command() +@click.pass_context +def create(ctx): + """Create the GHC database + + Note: you still need to add a user + """ + verbose_echo(ctx, 'GeoHC: create db') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import db_commit + verbose_echo(ctx, 'GeoHC: get database') + DB = App.get_db() + verbose_echo(ctx, 'GeoHC: create all tables') + DB.create_all() + db_commit() + DB.session.remove() + click.echo('Database is created. Use `geohc db-adduser` to add users to ' + 'the database.') + + +@db.command() +@click.pass_context +@click.option('-u', '--user', type=str, help='username', prompt=True) +@click.option('-e', '--email', type=str, help='email address', prompt=True) +@click.option('-p', '--password', type=str, help='password', prompt=True, + hide_input=True, confirmation_prompt=True) +@click.option('-r', '--role', type=click.Choice(['admin', 'user']), + prompt=True, help='role for this user') +def adduser(ctx, user, email, password, role): + """Add an user to the database + """ + verbose_echo(ctx, 'GeoHC: add user to database') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import User, db_commit + verbose_echo(ctx, 'GeoHC: get database') + DB = App.get_db() + verbose_echo(ctx, 'GeoHC: create user') + user_to_add = User(user, password, email, role=role) + verbose_echo(ctx, 'GeoHC: adding user to database') + DB.session.add(user_to_add) + db_commit() + DB.session.remove() + click.echo(f'User {user} is added.') + + +@db.command() +@click.pass_context +@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, + expose_value=False, help='Confirm dropping tables', + prompt='This will drop the tables in the database. Are you ' + 'sure?') +def drop(ctx): + """Drop the current database + """ + verbose_echo(ctx, 'GeoHC: drop db') + click.confirm("This will drop the tables in the database. Are you sure?", + abort=True) + verbose_echo(ctx, 'User confirmed dropping tables') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import db_commit + verbose_echo(ctx, 'GeoHC: get database') + DB = App.get_db() + verbose_echo(ctx, 'GeoHC: dropping all tables') + DB.drop_all() + db_commit() + DB.session.remove() + click.echo('Database dropped all tables.') + + +@db.command() +@click.pass_context +@click.option('-f', '--file', type=click.Path(), multiple=False, required=True, + help='Path to the file to load into the database. MUST be JSON.') +@click.option('-y', '--yes', is_flag=True, callback=abort_if_false, + expose_value=False, help='Confirm dropping old content.', + prompt='WARNING: all database data will be lost. Proceed?') +def load(ctx, file): + """Load JSON into the database + + e.g. test/data/fixtures.json + """ + verbose_echo(ctx, 'GeoHC: load data into db') + verbose_echo(ctx, 'User confirmed loading new data and losing old data.') + from GeoHealthCheck.init import App + from GeoHealthCheck.models import load_data + DB = App.get_db() + if file[-5:].lower() != '.json': + click.echo("File must have '.json' file extension. Aborting import.") + ctx.exit() + verbose_echo(ctx, 'Start loading file.') + load_data(file) + verbose_echo(ctx, 'Data loaded!') + DB.session.remove() + click.echo('Finished loading data.') + + +@db.command() +@click.pass_context +def flush(ctx): + """Flush runs: remove old data over retention date. + """ + verbose_echo(ctx, 'GeoHC: flush old runs from database.') + from GeoHealthCheck.models import flush_runs + flush_runs() + click.echo('Finished flushing old runs from database.') + + +@db.command() +@click.pass_context +def upgrade(ctx): + """Upgrade the database + """ + verbose_echo(ctx, 'GeoHC: upgrade db') + from os import system, chdir + chdir('GeoHealthCheck') + system('python manage.py db upgrade') + click.echo('Upgrade DB finished.') + + +@db.command() +@click.pass_context +def export(ctx): + click.exho('GeoHC: todo- write export.') + + if __name__ == '__main__': cli() diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index 57b5c901..b1289e69 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -894,7 +894,7 @@ def db_commit(): if len(sys.argv) > 1: if sys.argv[1] == 'create': LOGGER.warning('models.py create is deprecated since 0.8.0. Please' - ' use cli: `geohc db-create` and `geohc db-adduser`', + ' use cli: `geohc db create` and `geohc db adduser`', DeprecationWarning) print('Creating database objects') DB.create_all() @@ -921,14 +921,14 @@ def db_commit(): elif sys.argv[1] == 'drop': LOGGER.warning('models.py drop is deprecated since 0.8.0. Please ' - 'use cli: `geohc db-drop`', DeprecationWarning) + 'use cli: `geohc db drop`', DeprecationWarning) print('Dropping database objects') DB.drop_all() db_commit() elif sys.argv[1] == 'load': LOGGER.warning('models.py load is deprecated since 0.8.0. Please ' - 'use cli: `geohc db-load`', DeprecationWarning) + 'use cli: `geohc db load`', DeprecationWarning) print('Load database from JSON file (e.g. tests/fixtures.json)') if len(sys.argv) > 2: file_path = sys.argv[2] @@ -957,7 +957,7 @@ def db_commit(): elif sys.argv[1] == 'flush': LOGGER.warning('models.py flush is deprecated since 0.8.0. Please ' - 'use cli: `geohc db-flush`', DeprecationWarning) + 'use cli: `geohc db flush`', DeprecationWarning) flush_runs() DB.session.remove() diff --git a/README.md b/README.md index b670d63e..22ed6048 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ vi instance/config_site.py # - GHC_MAP (or use default settings) # setup database -geohc db-create +geohc db create # create superuser account interactively -geohc db-adduser +geohc db adduser # start webserver with healthcheck runner daemon inside # (default is 0.0.0.0:8000) @@ -61,21 +61,21 @@ geohc serve # other commands # # drop database -geohc db-drop +geohc db drop # load data in database (WARN: deletes existing data!) # See example data .json files in tests/data -geohc db-load -f <.json data file> -y +geohc db load -f <.json data file> -y # More help on the `geohc` cli command: geohc --help # More help on a specific command -geohc db-load --help +geohc db load --help ``` **Note for developers:** instead of `pip install .`, you might want to install with the *editable* option specified: `pip install -e .` -More in the [full GHC documentation](http://docs.geohealthcheck.org/). \ No newline at end of file +More in the [full GHC documentation](http://docs.geohealthcheck.org/). diff --git a/docker/scripts/configure.sh b/docker/scripts/configure.sh index 71b2c85d..54d33c02 100755 --- a/docker/scripts/configure.sh +++ b/docker/scripts/configure.sh @@ -15,8 +15,8 @@ echo "Using DB_TYPE=${DB_TYPE}" # Create DB shorthand function create_db() { pushd /GeoHealthCheck/ - geohc db-create - geohc db-adduser -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL} -r admin + geohc db create + geohc db adduser -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL} -r admin popd } diff --git a/docker/scripts/run-web.sh b/docker/scripts/run-web.sh index 93726305..ca83f70e 100755 --- a/docker/scripts/run-web.sh +++ b/docker/scripts/run-web.sh @@ -14,7 +14,7 @@ source /venv/bin/activate . # Make sure PYTHONPATH includes GeoHealthCheck export PYTHONPATH=/GeoHealthCheck:$PYTHONPATH -geohc db-upgrade +geohc db upgrade # SCRIPT_NAME should not have value '/' [ "${SCRIPT_NAME}" = '/' ] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /" diff --git a/docs/admin.rst b/docs/admin.rst index 6cf37892..d53ddac3 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -16,7 +16,7 @@ acces to the command line interface `geohc`. You can get help from the cli via : This will list all available commands. To get help with a specific command, run `geohc <> --help`, e.g. :: - geohc db-adduser --help + geohc db adduser --help This will show you all the (required) options to add a user to the database. @@ -32,7 +32,7 @@ To create the database execute the following: Open a command line, (if needed activate your virtualenv), and do :: - geohc db-create + geohc db create add user ........ @@ -41,9 +41,9 @@ To add a new user to the database: Open a command line, (if needed activate your virtualenv), and do :: - geohc db-adduser + geohc db adduser # or - geohc db-adduser -u username -p password -e email@address.com -r admin + geohc db adduser -u username -p password -e email@address.com -r admin drop db ....... @@ -52,7 +52,7 @@ To delete the database execute the following, however you will loose all your in Open a command line, (if needed activate your virtualenv), and do :: - geohc db-drop + geohc db drop Note: you need to create a Database again before you can start GHC again. @@ -61,7 +61,7 @@ load data To load a JSON data file, do (WARN: deletes existing data!) :: - geohc db-load --file my_data.json + geohc db load --file my_data.json You will be asked for confirmation. You can also specify the `-y` or `--yes` flag to indicate you are sure and to skip the confirmation question. @@ -73,14 +73,14 @@ flush To flush the old records from the system, you can flush the records :: - geohc db-flush + geohc db flush upgrade ....... To upgrade the database structure (might be necessary with a new release of GeoHealthCheck) :: - geohc db-upgrade + geohc db upgrade export data ........... From 14df3f03e700e9f7f6eb4359bfd56dee1bfa7eee Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 21:44:42 +0100 Subject: [PATCH 45/49] Fix flake8 --- GeoHealthCheck/models.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/GeoHealthCheck/models.py b/GeoHealthCheck/models.py index b1289e69..33f65e51 100644 --- a/GeoHealthCheck/models.py +++ b/GeoHealthCheck/models.py @@ -894,8 +894,9 @@ def db_commit(): if len(sys.argv) > 1: if sys.argv[1] == 'create': LOGGER.warning('models.py create is deprecated since 0.8.0. Please' - ' use cli: `geohc db create` and `geohc db adduser`', - DeprecationWarning) + ' use cli: `geohc db create` and ' + '`geohc db adduser`', + DeprecationWarning) print('Creating database objects') DB.create_all() @@ -921,14 +922,14 @@ def db_commit(): elif sys.argv[1] == 'drop': LOGGER.warning('models.py drop is deprecated since 0.8.0. Please ' - 'use cli: `geohc db drop`', DeprecationWarning) + 'use cli: `geohc db drop`', DeprecationWarning) print('Dropping database objects') DB.drop_all() db_commit() elif sys.argv[1] == 'load': LOGGER.warning('models.py load is deprecated since 0.8.0. Please ' - 'use cli: `geohc db load`', DeprecationWarning) + 'use cli: `geohc db load`', DeprecationWarning) print('Load database from JSON file (e.g. tests/fixtures.json)') if len(sys.argv) > 2: file_path = sys.argv[2] @@ -953,11 +954,11 @@ def db_commit(): elif sys.argv[1] == 'run': LOGGER.warning('models.py run is deprecated. Please use `python ' - 'healthcheck.py`', DeprecationWarning) + 'healthcheck.py`', DeprecationWarning) elif sys.argv[1] == 'flush': LOGGER.warning('models.py flush is deprecated since 0.8.0. Please ' - 'use cli: `geohc db flush`', DeprecationWarning) + 'use cli: `geohc db flush`', DeprecationWarning) flush_runs() DB.session.remove() From f9afdfe0f014454813ae8f101fd5950f0bce8558 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Mon, 13 Jan 2020 21:54:05 +0100 Subject: [PATCH 46/49] Fix version number in docs --- docs/conf.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b51008ec..dd91ba54 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,6 +14,7 @@ import sys import os +import re # indicate Sphinx is building (to replace @Config decorators) os.environ['SPHINX_BUILD'] = '1' @@ -55,8 +56,10 @@ # built documents. # # The short X.Y version. -with open('../VERSION') as ff: - version = ff.read().strip() +with open('../GeoHealthCheck/__init__.py') as ff: + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + ff.read(), re.M) + version = version_match.group(1) # The full version, including alpha/beta/rc tags. release = version From 57383c063d255a1182a57dcc91c81403cedc3f44 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 15 Jan 2020 09:57:07 +0100 Subject: [PATCH 47/49] Remove references to paver --- GeoHealthCheck/cli.py | 2 - GeoHealthCheck/migrations/README.md | 4 +- README.md | 2 +- docker/README.md | 2 +- docs/config.rst | 4 +- docs/install.rst | 13 +- pavement.py | 352 ---------------------------- requirements-dev.txt | 1 - requirements.txt | 1 - 9 files changed, 16 insertions(+), 365 deletions(-) delete mode 100644 pavement.py diff --git a/GeoHealthCheck/cli.py b/GeoHealthCheck/cli.py index 35c5070b..9bd0ed40 100644 --- a/GeoHealthCheck/cli.py +++ b/GeoHealthCheck/cli.py @@ -72,8 +72,6 @@ def version(ctx): 'install the instance data and help files.') def create_instance(ctx, basepath): """Create an instance of GeoHealthCheck App - - This command is a copy of `paver setup` """ verbose_echo(ctx, 'GeoHC: create instance') import glob diff --git a/GeoHealthCheck/migrations/README.md b/GeoHealthCheck/migrations/README.md index 81db6740..5f0d6527 100755 --- a/GeoHealthCheck/migrations/README.md +++ b/GeoHealthCheck/migrations/README.md @@ -6,7 +6,7 @@ and Flask-Script. Users should be able to upgrade existing installs via: # In top dir of installation - paver upgrade + geohc db upgrade The `versions` dir contains the various upgrades. These were initially created using the Alembic `autogenerate` facility @@ -39,7 +39,7 @@ Subsequently the upgrade can be performed using: python manage.py db upgrade # or the equivalent (for users) - paver upgrade + geohc db upgrade ## Revisions diff --git a/README.md b/README.md index 22ed6048..0719b947 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ geohc create-secret-key # setup local configuration (overrides GeoHealthCheck/config_main.py) vi instance/config_site.py # edit at least secret key: -# - SECRET_KEY # copy/paste result string from paver create_secret_key +# - SECRET_KEY # copy/paste result string from geohc create-secret-key # Optional: edit other settings or leave defaults # - SQLALCHEMY_DATABASE_URI diff --git a/docker/README.md b/docker/README.md index d188cae3..8c2ddbd4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -244,5 +244,5 @@ geohc db-upgrade etc ``` -NB: database upgrades (`paver upgrade`) +NB: database upgrades (`geohc db upgrade`) are always performed automatically when running GHC via Docker. diff --git a/docs/config.rst b/docs/config.rst index 5716f565..c4395ec6 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -14,7 +14,7 @@ a configuration file in the environment settings that will override settings in The configuration options are: - **SQLALCHEMY_DATABASE_URI**: the database configuration. See the SQLAlchemy documentation for more info -- **SECRET_KEY**: secret key to set when enabling authentication. Use the output of ``paver create_secret_key`` to set this value +- **SECRET_KEY**: secret key to set when enabling authentication. Use the output of ``geohc create-secret-key`` to set this value - **GHC_RETENTION_DAYS**: the number of days to keep Run history - **GHC_PROBE_HTTP_TIMEOUT_SECS**: stop waiting for the first byte of a Probe response after the given number of seconds - **GHC_MINIMAL_RUN_FREQUENCY_MINS**: minimal run frequency for Resource that can be set in web UI @@ -106,7 +106,7 @@ This is the preferred mode as each `Resource` can have its own schedule (configu via Dashboard) and `cron` has dependencies on local environment. Later versions may phase out cron-scheduling completely. -The **GHC Runner** can be run via the command `paver runner_daemon` or can run internally within +The **GHC Runner** can be run via the command `geohc runner-daemon` or can run internally within the **GHC Webapp** by setting the config variable **GHC_RUNNER_IN_WEBAPP** to `True` (the default). NB it is still possible to run GHC as in the pre-v0.5.0 mode using cron-jobs: just run the **GHC Webapp** with **GHC_RUNNER_IN_WEBAPP** set to `False` and have your cron-jobs scheduled. diff --git a/docs/install.rst b/docs/install.rst index a034413c..d2c85615 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -67,7 +67,7 @@ Install vi instance/config_site.py # edit: # - SQLALCHEMY_DATABASE_URI - # - SECRET_KEY # from paver create_secret_key + # - SECRET_KEY # from geohc create-secret-key # - GHC_RETENTION_DAYS # - GHC_SELF_REGISTER # - GHC_NOTIFICATIONS @@ -118,8 +118,8 @@ An existing GHC database installation can be upgraded with: Notes: * **Always backup your database first!!** -* make sure Flask-Migrate is installed (see requirements.txt), else: `pip install Flask-Migrate==2.5.2`, but best is to run `paver setup` also for other dependencies -* upgrading is "smart": you can always run `paver upgrade`, it has no effect when DB is already up to date +* make sure Flask-Migrate is installed (see requirements.txt), else: `pip install Flask-Migrate==2.5.2`, but best is to run `geohc create-instance` also for other dependencies +* upgrading is "smart": you can always run `geohc db upgrade`, it has no effect when DB is already up to date * when upgrading from earlier versions without Plugin-support: - adapt your `config_site.py` to Plugin settings from `config_main.py` @@ -144,6 +144,13 @@ the `paver upgrade` command. Also password recovery was changed: a user can crea a unique, personal URL that GHC sends by email. This requires a working email configuration and a reachable `SITE_URL` config value. See :ref:`admin_user_mgt` for solving password problems. +Upgrade notes v0.8.0 +.................... + +In previous version GHC used `paver` to control the setup and administration of +the application. With this version GHC switched `click` and the cli commands +changed to `geohc`. Type `geohc --help` to get more information. + Running ------- diff --git a/pavement.py b/pavement.py deleted file mode 100644 index ecd35738..00000000 --- a/pavement.py +++ /dev/null @@ -1,352 +0,0 @@ -# ================================================================= -# -# Authors: Tom Kralidis -# -# Copyright (c) 2014 Tom Kralidis -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, -# copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following -# conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. -# -# ================================================================= - -import codecs -import glob -import os -import shutil -import tempfile -from io import BytesIO -from urllib.request import urlopen -import zipfile - -from paver.easy import (Bunch, call_task, cmdopts, info, options, - path, pushd, sh, task) - -BASEDIR = os.path.abspath(os.path.dirname(__file__)) - -options( - base=Bunch( - home=path(BASEDIR), - docs=path('%s/docs' % BASEDIR), - instance=path('%s/instance' % BASEDIR), - pot=path('%s/GeoHealthCheck/translations/en/LC_MESSAGES/messages.po' % - BASEDIR), - static_docs=path('%s/GeoHealthCheck/static/docs' % BASEDIR), - static_lib=path('%s/GeoHealthCheck/static/lib' % BASEDIR), - tmp=path(tempfile.mkdtemp()), - translations=path('%s/GeoHealthCheck/translations' % BASEDIR) - ), -) - - -@task -def setup(): - """setup plugin dependencies""" - - config_file = options.base.home / 'GeoHealthCheck/config_main.py' - config_site = options.base.instance / 'config_site.py' - - # setup dirs - if not os.path.exists(options.base.static_lib): - options.base.static_lib.mkdir() - if not os.path.exists(options.base.instance): - options.base.instance.mkdir() - data_dir = options.base.instance / 'data' - data_dir.mkdir() - # data_dir.chmod(0777) gives failure on Python 2.7 Paver 1.2.1 - os.chmod(path(data_dir), 0o777) - # setup config - config_file.copy(config_site) - - # setup deps - sh('pip install -r requirements.txt') - - skin = 'http://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/v3.3.7+1.zip' # noqa - - skin_dirs = ['dist', 'vendor'] - need_to_fetch = False - - for skin_dir in skin_dirs: - skin_dir_path = os.sep.join( - ['startbootstrap-sb-admin-2-3.3.7-1', skin_dir]) - if not os.path.exists(skin_dir_path): - need_to_fetch = True - - if need_to_fetch: - zipstr = BytesIO(urlopen(skin).read()) - zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(options.base.static_lib) - - for zf_mem in skin_dirs: - src_loc = path(options.base.static_lib / - 'startbootstrap-sb-admin-2-3.3.7-1' / zf_mem) - dest_loc = path(options.base.static_lib / zf_mem) - if not os.path.exists(dest_loc): - src_loc.move(dest_loc) - else: - info('directory already exists. Skipping') - - shutil.rmtree(path(options.base.static_lib / - 'startbootstrap-sb-admin-2-3.3.7-1')) - - # install sparklines to static/site/js - with open(path(options.base.static_lib / 'jspark.js'), 'w') as f: - content = urlopen('http://ejohn.org/files/jspark.js').read().decode() - content.replace('red', 'green') - f.write(content) - - # install bootstrap-tagsinput to static/lib - info('Getting select2') - select2 = 'https://github.com/select2/select2/archive/4.0.3.zip' - - zipstr = BytesIO(urlopen(select2).read()) - zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(options.base.static_lib) - dirname = glob.glob(options.base.static_lib / 'select2-*')[0] - dstdir = ''.join(dirname.rsplit('-', 1)[:-1]) - try: - os.rename(dirname, dstdir) - except OSError: - shutil.rmtree(dstdir) - os.rename(dirname, dstdir) - - # install leafletjs to static/lib - info('Getting leaflet') - leafletjs = 'http://cdn.leafletjs.com/downloads/leaflet-0.7.5.zip' - - zipstr = BytesIO(urlopen(leafletjs).read()) - zipfile_obj = zipfile.ZipFile(zipstr) - zipfile_obj.extractall(options.base.static_lib / 'leaflet') - - # install html5shiv to static/lib - with open(path(options.base.static_lib / 'html5shiv.min.js'), 'w') as f: - url = 'http://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js' - content = urlopen(url).read().decode() - f.write(content) - - # install respond to static/lib - with open(path(options.base.static_lib / 'respond.min.js'), 'w') as f: - url = 'http://oss.maxcdn.com/respond/1.4.2/respond.min.js' - content = urlopen(url).read().decode() - f.write(content) - - # build i18n .mo files - call_task('compile_translations') - - # build local docs - call_task('refresh_docs') - - # message user - info('GeoHealthCheck is now built. Edit settings in %s' % config_site) - info('before deploying the application. Alternatively, you can start a') - info('development instance with "python GeoHealthCheck/app.py"') - - -@task -@cmdopts([ - ('email=', 'e', 'email'), - ('username=', 'u', 'username'), - ('password=', 'p', 'password') -]) -def create(options): - """create database objects and superuser account""" - info('Warning!: create_secret_key is deprecated since 0.8.0. Please use ' - 'cli: `geohc db-create` and `geohc db-adduser`') - args = '' - username = options.get('username', None) - password = options.get('password', None) - email = options.get('email', None) - info(username) - if all([username, password, email]): - args = '%s %s %s' % (username, password, email) - sh('python %s create %s' % (path('GeoHealthCheck/models.py'), args)) - - -@task -def create_secret_key(): - """create secret key for SECRET_KEY in instance/config_site.py""" - info('Warning!: create_secret_key is deprecated since 0.8.0. Please use ' - 'cli: `geohc create-secret-key`') - info('Secret key: \'%s\'' % codecs.encode(os.urandom(24), 'hex').decode()) - info('Copy/paste this key to set the SECRET_KEY') - info('value in instance/config_site.py') - - -@task -@cmdopts([ - ('password=', 'p', 'password') -]) -def create_hash(options): - """ - Create hash, mainly for passwords. - Usage: paver create_hash -p mypass - """ - info('Warning!: create_hash is deprecated since 0.8.0. Please use cli: ' - '`geohc create-hash`') - import sys - sys.path.insert(0, BASEDIR + '/GeoHealthCheck') - from util import create_hash - token = create_hash(options.get('password', None)) - info('Copy/paste the entire token below for example to set password') - info(token) - - -@task -def upgrade(): - """upgrade database if changed; be sure to backup first!""" - info('Warning!: upgrade is deprecated since 0.8.0. Please use cli: ' - '`geohc db-upgrade`') - info('Upgrading database...') - with pushd(path('%s/GeoHealthCheck' % BASEDIR)): - sh('python manage.py db upgrade') - - -@task -def create_wsgi(): - """create WSGI wrapper and Apache2 configuration""" - info('Warning!: create_wsgi is deprecated since 0.8.0. Please use cli: ' - '`geohc create-wsgi`') - wsgi_script = '%s%sGeoHealthCheck.wsgi' % (options.base.instance, os.sep) - with open(wsgi_script, 'w') as ff: - ff.write('import sys\n') - ff.write('sys.path.insert(0, \'%s\')\n' % BASEDIR) - ff.write('from GeoHealthCheck.app import APP as application') - - wsgi_conf = '%s%sGeoHealthCheck.conf' % (options.base.instance, os.sep) - with open(wsgi_conf, 'w') as ff: - ff.write('WSGIScriptAlias / %s%sGeoHealthCheck.wsgi\n' % - (options.base.instance, os.sep)) - ff.write('\n' % (BASEDIR, os.sep)) - ff.write('Order deny,allow\n') - ff.write('Allow from all\n') - ff.write('') - - -@task -def refresh_docs(): - """Build sphinx docs from scratch""" - info('Warning!: refresh_docs is deprecated since 0.8.0. Please use cli: ' - '`geohc refresh-docs`') - - make = sphinx_make() - - if os.path.exists(options.base.static_docs): - shutil.rmtree(options.base.static_docs) - - with pushd(options.base.docs): - sh('%s clean' % make) - sh('%s html' % make) - source_html_dir = path('%s/docs/_build/html' % BASEDIR) - source_html_dir.copytree(options.base.static_docs) - - -@task -def clean(): - """clean environment""" - info('Warning!: clean is deprecated since 0.8.0. Please use cli: ' - '`geohc clean`') - - if os.path.exists(options.base.static_lib): - shutil.rmtree(options.base.static_lib) - if os.path.exists(options.base.tmp): - shutil.rmtree(options.base.tmp) - if os.path.exists(options.base.static_docs): - shutil.rmtree(options.base.static_docs) - - -@task -def extract_translations(): - """extract translations wrapped in _() or gettext()""" - - info('Warning!: extract_translations is deprecated since 0.8.0. Please use' - ' cli: `geohc lang-extract-translations`') - pot_dir = path('GeoHealthCheck/translations/en/LC_MESSAGES') - if not os.path.exists(pot_dir): - pot_dir.makedirs() - - sh('pybabel extract -F babel.cfg -o %s GeoHealthCheck' % options.base.pot) - - -@task -@cmdopts([ - ('lang=', 'l', '2-letter language code'), -]) -def add_language_catalogue(options): - """adds new language profile""" - - info('Warning!: add_language_catalogue is deprecated since 0.8.0. Please ' - 'use cli: `geohc lang-add-language-catalogue`') - lang = options.get('lang', None) - - if lang is None: - raise RuntimeError('missing lang argument') - - sh('pybabel init -i %s -d %s -l %s' % ( - options.base.pot, options.base.translations, lang)) - - -@task -def compile_translations(): - """build .mo files""" - info('Warning!: compile_translations is deprecated since 0.8.0. Please use' - ' cli: `geohc lang-compile-translations`') - sh('pybabel compile -d %s' % options.base.translations) - - -@task -def update_translations(): - """update language strings""" - info('Warning!: update_translations is deprecated since 0.8.0. Please use ' - 'cli: `geohc lang-update-translations`') - call_task('extract_translations') - sh('pybabel update -i %s -d %s' % ( - options.base.pot, options.base.translations)) - - -@task -def runner_daemon(): - """Run the HealthCheck runner daemon scheduler""" - info('Warning!: runner_daemon is deprecated since 0.8.0. Please use cli: ' - '`geohc runner-daemon`') - sh('python %s' % path('GeoHealthCheck/scheduler.py')) - - -@task -def run_healthchecks(): - """Run all HealthChecks directly""" - info('Warning!: run_healthchecks is deprecated since 0.8.0. Please use ' - 'cli: `geohc run-healthchecks`') - sh('python %s' % path('GeoHealthCheck/healthcheck.py')) - - -def sphinx_make(): - """return what command Sphinx is using for make""" - - if os.name == 'nt': - return 'make.bat' - return 'make' - - -@task -def run_tests(): - """Run all tests""" - info('Warning!: run_tests is deprecated since 0.8.0. Please use cli: ' - '`geohc run-tests`') - sh('python %s' % path('tests/run_tests.py')) diff --git a/requirements-dev.txt b/requirements-dev.txt index 095bdec7..d4d8edf7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,4 @@ click==7.0 flake8 -Paver==1.3.4 pylint wheel==0.33.6 diff --git a/requirements.txt b/requirements.txt index 7736133f..a937e4ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,3 @@ requests>=2.20.0 WTForms==2.2.1 APScheduler==3.6.1 passlib==1.7.1 -paver==1.3.4 From 9675b12f579fc7b7e63327eda5264415af7a7056 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Tue, 21 Jan 2020 19:18:24 +0100 Subject: [PATCH 48/49] Fix paths in setup script --- GeoHealthCheck/cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/GeoHealthCheck/cli.py b/GeoHealthCheck/cli.py index 9bd0ed40..db1b3919 100644 --- a/GeoHealthCheck/cli.py +++ b/GeoHealthCheck/cli.py @@ -92,12 +92,14 @@ def create_instance(ctx, basepath): # setup dirs if not os.path.exists(os.path.normpath('%s/static/lib' % basedir)): os.mkdir(os.path.normpath('%s/static/lib' % basedir)) - if not os.path.exists(os.path.normpath('%s/instance' % basedir)): + if not os.path.exists(os.path.normpath('%s/instance' % basedir_parent)): os.mkdir(os.path.normpath('%s/instance' % basedir_parent)) - data_dir = os.path.normpath('%s/instance/data' % basedir_parent) - os.mkdir(data_dir, mode=0o777) # setup config shutil.copy(config_file, config_site) + if not os.path.exists(os.path.normpath('%s/instance/data' + % basedir_parent)): + data_dir = os.path.normpath('%s/instance/data' % basedir_parent) + os.mkdir(data_dir, mode=0o777) skin = 'http://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/v3.3.7+1.zip' # noqa @@ -181,8 +183,8 @@ def create_instance(ctx, basepath): update_documentation(ctx, basepath=basedir_parent) # message user - click.echo('GeoHealthCheck is now built. Edit settings in %s' - % config_site) + click.echo('GeoHealthCheck is now built. Edit settings like the secret-key' + ' and the database connection string in %s' % config_site) click.echo('before deploying the application. Alternatively, you can') click.echo('start a development instance with ') click.echo('"python GeoHealthCheck/app.py"') From d52e6a9315b49a5a47fdd476c68c69aaecd5adb5 Mon Sep 17 00:00:00 2001 From: Rob van Loon Date: Wed, 22 Jan 2020 16:55:02 +0100 Subject: [PATCH 49/49] Fix docker daemon --- GeoHealthCheck/cli.py | 12 +++++++++--- docker/scripts/run-runner.sh | 3 --- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/GeoHealthCheck/cli.py b/GeoHealthCheck/cli.py index db1b3919..1d26a97e 100644 --- a/GeoHealthCheck/cli.py +++ b/GeoHealthCheck/cli.py @@ -409,7 +409,9 @@ def runner_daemon(ctx): verbose_echo(ctx, 'GeoHC: going to run the scheduler daemon. Press ctrl-c ' 'to stop.') import os - os.system('python %s' % os.path.normpath('GeoHealthCheck/scheduler.py')) + basedir = os.path.abspath(os.path.dirname(__file__)) + scheduler = basedir + '/scheduler.py' + os.system('python %s' % os.path.normpath(scheduler)) @cli.command() @@ -418,7 +420,9 @@ def run_healthchecks(ctx): """Run all HealthChecks directly""" verbose_echo(ctx, 'GeoHC: going to run all the healthchecks once.') import os - os.system('python %s' % os.path.normpath('GeoHealthCheck/healthcheck.py')) + basedir = os.path.abspath(os.path.dirname(__file__)) + healtcheck = basedir + '/healtcheck.py' + os.system('python %s' % os.path.normpath(healtcheck)) click.echo('GeoHC: Finished running the healthchecks.') @@ -427,7 +431,9 @@ def run_healthchecks(ctx): def run_tests(ctx): """Run all tests""" import os - os.system('python %s' % os.path.normpath('tests/run_tests.py')) + basedir = os.path.abspath(os.path.dirname(__file__)) + tests = basedir + '/run_tests.py' + os.system('python %s' % os.path.normpath(tests)) @cli.command() diff --git a/docker/scripts/run-runner.sh b/docker/scripts/run-runner.sh index d8c3e24f..f34ee4fe 100755 --- a/docker/scripts/run-runner.sh +++ b/docker/scripts/run-runner.sh @@ -12,9 +12,6 @@ echo "START /run-runner.sh" # that schedules healthcheck jobs source /venv/bin/activate . -# Make sure PYTHONPATH includes GeoHealthCheck -export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH - geohc runner-daemon echo "END /run-runner.sh"