Skip to content

Commit

Permalink
Merge pull request #16 from al4/master
Browse files Browse the repository at this point in the history
Merry Christmas 🎄 (also, a large addition)
  • Loading branch information
al4 committed Jan 5, 2016
2 parents 94f377c + b1612aa commit d3ac85c
Show file tree
Hide file tree
Showing 28 changed files with 2,591 additions and 463 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ target/
# Created by .ignore support plugin (hsz.mobi)
.idea/
orlo/orlo.db
orlo/_version.py
.vagrant
*.swp
*.deb
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ python:
addons:
apt:
packages:
- curl
- curl
postgresql: "9.3"

services:
- postgresql

before_script:
- psql -c "CREATE USER orlo PASSWORD 'password';"
- psql -c "CREATE DATABASE orlo OWNER orlo;" -U postgres

before_install:
- pip install -r requirements.txt
Expand Down
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Vagrant.configure(2) do |config|
# sudo sed -i 's/archive.ubuntu.com/nl.archive.ubuntu.com/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get -y install python-pip python-dev postgresql postgresql-server-dev-all
echo "CREATE USER orlo WITH PASSWORD 'password'; CREATE DATABASE orlo OWNER orlo; " \
| sudo -u postgres -i psql
# Build tools
sudo apt-get -y install build-essential git-buildpackage debhelper python-dev
Expand All @@ -85,5 +87,7 @@ Vagrant.configure(2) do |config|
sudo python /vagrant/setup.py install
python /vagrant/create_db.py
sudo pip install -r /vagrant/requirements.txt
sudo pip install pytest Flask-Testing
SHELL
end
66 changes: 2 additions & 64 deletions bin/orlo
Original file line number Diff line number Diff line change
@@ -1,67 +1,5 @@
#!/usr/share/python/python-orlo/bin/python
#!/bin/bash

import argparse
/usr/share/python/python-orlo/bin/python /usr/share/python/python-orlo/lib/python2.7/site-packages/orlo/cli.py $@


def parse_args():
parser = argparse.ArgumentParser()

p_config = argparse.ArgumentParser(add_help=False)
p_config.add_argument('--file', '-f', dest='filepath', help="File to write to",
default='/etc/orlo.conf')

p_database = argparse.ArgumentParser(add_help=False)
p_server = argparse.ArgumentParser(add_help=False)
p_server.add_argument('--host', '-H', dest='host', default='127.0.0.1', help="Address to listen on")
p_server.add_argument('--port', '-P', dest='port', type=int, default=5000, help="Port to listen on")

subparsers = parser.add_subparsers(dest='action')
sp_config = subparsers.add_parser(
'write_config', help="Write config file",
parents=[p_config])
sp_config.set_defaults(func=write_config)

sp_database = subparsers.add_parser(
'setup_database', help="Initialise the configured DB",
parents=[p_database])
sp_database.set_defaults(func=setup_database)

sp_run_server = subparsers.add_parser(
'run_server', help="Run a test server",
parents=[p_server])
sp_run_server.set_defaults(func=run_server)

return parser.parse_args()


def write_config(args):
from orlo import config
config_file = open(args.filepath, 'w')
config.write(config_file)


def setup_database(args):
from orlo.orm import db
from orlo.config import config

if config.get('db', 'uri') == 'sqlite://':
print("Warning: setting up in-memory database, this is "
"probably not what you want!\n"
"Please configure db:uri in /etc/orlo.conf")
db.create_all()


def run_server(args):
print("Warning: this is a development server and not suitable "
"for production, we recommend running under gunicorn.")

from orlo import app
app.config['DEBUG'] = True
app.config['TRAP_HTTP_EXCEPTIONS'] = True
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
app.run(host=args.host, port=args.port, debug=True, use_reloader=True)


if __name__ == '__main__':
args = parse_args()
args.func(args)
12 changes: 12 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
python-orlo (0.0.4) stable; urgency=medium

* Update debian description
* Rename /import/release to /releases/import, update docstring
* Fix release import error
* Add .deb files to gitignore
* Bump version
* Handle import of documents that omit optional parameters
* Add support for importing notes

-- Alex Forbes <[email protected]> Fri, 11 Dec 2015 12:52:59 +0000

python-orlo (0.0.3) stable; urgency=medium

* Multiple changes
Expand Down
23 changes: 12 additions & 11 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ Orlo

Orlo is an API for tracking deployments, written with Python, Flask and SqlAlchemy.

It originated as part of a siteops hackathon at eBay classifieds, and is currently in development by staff at gumtree.com, kijiji.ca, mobile.de and 2dehands.be (all part of eBay Classifieds).

It is in a very early stage of development, but eventually we hope that it will be used more broadly within ECG and possibly elsewhere.
It originated as part of a siteops hackathon, and is currently in development by staff at eBay Classifieds Group.


Contents
Expand Down Expand Up @@ -43,16 +41,19 @@ The API should also be agnostic to release process, server container or packagin
Why "orlo"?
-------------

Originally this project was called "Sponge", because sponges are absorbent. But it turns out that name was already in use on readthedocs.org, so it was renamed. In English, orlo means "a plinth supporting the base of a column", which seems like a pretty good analogy for this project.
Originally this project was called "Sponge", because sponges are absorbent. But it turns out that name was already in use on readthedocs.org, so it was renamed. In English, orlo means "a plinth supporting the base of a column".

Roadmap
-------

In the beginning:
- Records release information in a database
- Returns release information in JSON
- API documentation
Currently, Orlo can:
- Record release information in a database
- Return release information in JSON
- Present basic stats on releases

We also have API documentation and a client library in Python (see [orlo-client](https://github.com/eBayClassifiedsGroup/orloclient))

In the future:
- UI to display and consume the data
- Control API for performing deployments
In the future, we hope to add:
- UI to display and consume the data (started at [orloui](https://github.com/al4/orloui))
- Security and authentication/authorization (at present everything is wide open)
- Control API for performing deployments (not yet started)
2 changes: 1 addition & 1 deletion etc/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server {

server_name <my-host-name>;

location / {
location /api/ {
try_files $uri @proxy_to_app;
}

Expand Down
16 changes: 14 additions & 2 deletions orlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@
from logging.handlers import RotatingFileHandler

from orlo.config import config
from orlo._version import __version__

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = config.get('db', 'uri')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

if config.getboolean('main', 'propagate_exceptions'):
app.config['PROPAGATE_EXCEPTIONS'] = True

if config.getboolean('db', 'echo_queries'):
app.config['SQLALCHEMY_ECHO'] = True

if config.getboolean('logging', 'debug'):
app.debug = True
app.logger.debug('Debug enabled')

if not config.getboolean('main', 'strict_slashes'):
app.url_map.strict_slashes = False

logfile = config.get('logging', 'file')
if logfile != 'disabled':
handler = RotatingFileHandler(
logfile,
maxBytes=10000,
maxBytes=1048576,
backupCount=1,
)
app.logger.addHandler(handler)

# Must be imported last
import orlo.views
import orlo.error_handlers
import orlo.route_api
import orlo.route_import
import orlo.route_info
import orlo.route_stats

74 changes: 74 additions & 0 deletions orlo/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from __future__ import print_function
import argparse

__author__ = 'alforbes'

"""
Command line interface
Generally setup/initialisation functions and the like, called by /usr/bin/orlo
"""


def parse_args():
parser = argparse.ArgumentParser()

p_config = argparse.ArgumentParser(add_help=False)
p_config.add_argument('--file', '-f', dest='filepath', help="File to write to",
default='/etc/orlo.conf')

p_database = argparse.ArgumentParser(add_help=False)
p_server = argparse.ArgumentParser(add_help=False)
p_server.add_argument('--host', '-H', dest='host', default='127.0.0.1', help="Address to listen on")
p_server.add_argument('--port', '-P', dest='port', type=int, default=5000, help="Port to listen on")

subparsers = parser.add_subparsers(dest='action')
sp_config = subparsers.add_parser(
'write_config', help="Write config file",
parents=[p_config])
sp_config.set_defaults(func=write_config)

sp_database = subparsers.add_parser(
'setup_database', help="Initialise the configured DB",
parents=[p_database])
sp_database.set_defaults(func=setup_database)

sp_run_server = subparsers.add_parser(
'run_server', help="Run a test server",
parents=[p_server])
sp_run_server.set_defaults(func=run_server)

return parser.parse_args()


def write_config(args):
from orlo import config
config_file = open(args.filepath, 'w')
config.write(config_file)


def setup_database(args):
from orlo.orm import db
from orlo.config import config

if config.get('db', 'uri') == 'sqlite://':
print("Warning: setting up in-memory database, this is "
"probably not what you want!\n"
"Please configure db:uri in /etc/orlo.conf")
db.create_all()


def run_server(args):
print("Warning: this is a development server and not suitable "
"for production, we recommend running under gunicorn.")

from orlo import app
app.config['DEBUG'] = True
app.config['TRAP_HTTP_EXCEPTIONS'] = True
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
app.run(host=args.host, port=args.port, debug=True, use_reloader=True)


if __name__ == '__main__':
args = parse_args()
args.func(args)
4 changes: 3 additions & 1 deletion orlo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
config.set('main', 'propagate_exceptions', 'true')
config.set('main', 'time_format', '%Y-%m-%dT%H:%M:%SZ')
config.set('main', 'time_zone', 'UTC')
config.set('main', 'strict_slashes', 'false')

config.add_section('db')
config.set('db', 'uri', 'sqlite://')
config.set('db', 'uri', 'postgres://orlo:password@localhost:5432/orlo')
config.set('db', 'echo_queries', 'false')

config.add_section('logging')
config.set('logging', 'debug', 'false')
Expand Down
5 changes: 0 additions & 5 deletions orlo/data.py

This file was deleted.

27 changes: 27 additions & 0 deletions orlo/error_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import print_function
from flask import jsonify, request
from orlo import app
from orlo.exceptions import InvalidUsage

__author__ = 'alforbes'


@app.errorhandler(404)
def page_not_found(error):
d = {'message': "404 Not Found", 'url': request.url}
return jsonify(d), 404


@app.errorhandler(InvalidUsage)
def handle_invalid_usage(error):
response = jsonify(error.to_dict())
response.status_code = error.status_code
return response


@app.errorhandler(400)
def handle_400(error):
response = jsonify(error.to_dict())
response.status_code = error.status_code
return response

17 changes: 14 additions & 3 deletions orlo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
__author__ = 'alforbes'


class InvalidUsage(Exception):
status_code = 400

class OrloError(Exception):
def __init__(self, message, status_code=None, payload=None):
Exception.__init__(self)
self.message = message
Expand All @@ -17,3 +15,16 @@ def to_dict(self):
rv = dict(self.payload or ())
rv['message'] = self.message
return rv


class InvalidUsage(OrloError):
status_code = 400


class DatabaseError(OrloError):
status_code = 500


class OrloWorkflowError(OrloError):
status_code = 400

Loading

0 comments on commit d3ac85c

Please sign in to comment.