From c12d304adbd6fbd21b71508d1e57e604d634e4d8 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 17 Jul 2018 20:57:29 +0200 Subject: [PATCH] Fix inventory not nesting devices --- README.md | 23 ++++++++++--------- example/README.md | 8 +++++++ example/apache.conf | 30 +++++++++++++++++++++++++ example_app.py => example/app.py | 6 +++++ example/wsgi.wsgi | 38 ++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 example/README.md create mode 100644 example/apache.conf rename example_app.py => example/app.py (74%) create mode 100644 example/wsgi.wsgi diff --git a/README.md b/README.md index c74f0f70..b8364792 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,9 @@ The requirements are: Install Devicehub with *pip*: `pip3 install ereuse-devicehub -U --pre`. ## Running -Create a python file with the following and call it `app.py`: -```python -from ereuse_devicehub.devicehub import Devicehub -from ereuse_devicehub.config import DevicehubConfig -class MyConfig(DevicehubConfig): - ORGANIZATION_NAME = 'My org' - ORGANIZATION_TAX_ID = 'foo-bar' +Download, or copy the contents, of [this file](example/app.py), and +call the new file ``app.py``. - -app = Devicehub(MyConfig()) -``` Create a PostgreSQL database called *devicehub*: ```bash @@ -89,3 +81,14 @@ interactive). Use postman as an example of how to use the API. [![Run in Postman](https://run.pstmn.io/button.svg)](https://documenter.getpostman.com/view/254251/RWEnmFPs) + +## Testing +To run the tests you will need to: + +1. `git clone` this project. +2. Create a database for testing. By default the database used is + `dh_test`. Execute to create it: + 1. `postgres $ createdb dh_test`. + 2. `postgres $ psql devicehub`. + 3. `postgres $ GRANT ALL PRIVILEGES ON DATABASE dh_test TO dhub;`. +3. Execute at the root folder of the project ``python3 setup.py test``. diff --git a/example/README.md b/example/README.md new file mode 100644 index 00000000..1a1bbfbe --- /dev/null +++ b/example/README.md @@ -0,0 +1,8 @@ +Example stuff +============= + +Example configurations useful for Devicehub. + +You can use [App.py](./app.py), [Apache.conf](./apache.conf), +and [wsgi.wsgi](./wsgi.wsgi) to configure Apache with Devicehub. Look +at each files to know what to configure. \ No newline at end of file diff --git a/example/apache.conf b/example/apache.conf new file mode 100644 index 00000000..b1a3ee1c --- /dev/null +++ b/example/apache.conf @@ -0,0 +1,30 @@ +# Apache configuration for a Devicehub +# It uses plain HTTP +# Change the following variables: + +Define servername api.devicetag.io +# The domain used to access the server +Define appdir /path/to/app/dir +# The path where the app directory is. Apache must have access to this folder. +Define wsgipath ${appdir}/wsgi.wsgi +# The location of the .wsgi file + + + ServerName ${servername} + + WSGIDaemonProcess "${servername}" threads=5 lang='en_US.UTF-8' locale='en_US.UTF-8' + WSGIScriptAlias / ${wsgipath} + + # pass the required headers through to the application + WSGIPassAuthorization On + + + WSGIProcessGroup "${servername}" + WSGIApplicationGroup %{GLOBAL} + Require all granted + + + # mod_deflate + SetOutputFilter DEFLATE + SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|deb|exe|dmg)$" no-gzip + diff --git a/example_app.py b/example/app.py similarity index 74% rename from example_app.py rename to example/app.py index ffa2f5e5..cc057684 100644 --- a/example_app.py +++ b/example/app.py @@ -1,6 +1,12 @@ from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.devicehub import Devicehub +""" +Example app with minimal configuration. + +Use this as a starting point. +""" + class MyConfig(DevicehubConfig): ORGANIZATION_NAME = 'My org' diff --git a/example/wsgi.wsgi b/example/wsgi.wsgi new file mode 100644 index 00000000..10ef4912 --- /dev/null +++ b/example/wsgi.wsgi @@ -0,0 +1,38 @@ +""" +An exemplifying Apache python WSGI to a Devicehub app. + +Based in http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/ + +You only need to modify ``app_dir`` and ``venv``. +""" + +from pathlib import Path + +import sys + +app_dir = Path(__file__).parent +""" +The **directory** where app.py is located. +Change this accordingly. +""" +assert app_dir.is_dir(), 'app_dir must point to a directory: {}'.format(app_dir) +app_dir = str(app_dir.resolve()) + +venv = Path(__file__).parent.parent / 'venv' / 'bin' / 'activate_this.py' +""" +The location of the ``activate_this.py`` file of the virtualenv. +Change this accordingly. +""" +assert venv.is_file(), 'venv must point to a file: {}'.format(venv) +venv = str(venv.resolve()) + +# Load the virtualenv +# ------------------- +_globals = dict(__file__=venv) +exec(open(venv).read(), _globals) + +# Load the app +# ------------ +sys.path.insert(0, str(app_dir)) +# noinspection PyUnresolvedReferences +from app import app as application \ No newline at end of file