diff --git a/.gitignore b/.gitignore index ae8fdba..c2103a6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ lib-cov *.out *.pid *.gz +*.pyc + +.venv +.ropeproject diff --git a/luncho/.server.py.swp b/luncho/.server.py.swp new file mode 100644 index 0000000..c978502 Binary files /dev/null and b/luncho/.server.py.swp differ diff --git a/luncho/__init__.py b/luncho/__init__.py new file mode 100644 index 0000000..5413cba --- /dev/null +++ b/luncho/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + + diff --git a/luncho/blueprints/.index.py.swp b/luncho/blueprints/.index.py.swp new file mode 100644 index 0000000..4f675b6 Binary files /dev/null and b/luncho/blueprints/.index.py.swp differ diff --git a/luncho/blueprints/__init__.py b/luncho/blueprints/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/luncho/blueprints/index.py b/luncho/blueprints/index.py new file mode 100644 index 0000000..6742333 --- /dev/null +++ b/luncho/blueprints/index.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +"""The index blueprint. There is nothing here, we just show a summary of +the current API requests.""" + +from operator import itemgetter + +from flask import Blueprint +from flask import jsonify +from flask import current_app + +index = Blueprint('index', __name__) + +@index.route('') +def show_routes(): + """List the current API""" + routes = [] + for rule in current_app.url_map.iter_rules(): + endpoint = rule.endpoint + if endpoint == 'static': + continue + + path = str(rule) + methods = rule.methods + doc = current_app.view_functions[endpoint].__doc__ + + routes.append([ + path, + doc + ]) + + routes.sort(key=itemgetter(0)) + return jsonify(routes) diff --git a/luncho/database.py b/luncho/database.py new file mode 100644 index 0000000..b25f592 --- /dev/null +++ b/luncho/database.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import datetime + +from pony.orm import Database +from pony.orm import PrimaryKey +from pony.orm import Optional +from pony.orm import Required +# from pony.orm import Set + +db = Database("sqlite", "tagallery.db", create_db=True) + +class User(db.Entity): + """Users.""" + username = PrimaryKey(unicode) + passhash = Required(unicode) + token = Optional(unicode) # 1. if the user never logged in, they will + # not have a token. + # 2. This forces the user to have a single + # login everywhere, per day. + issue_date = Optional(datetime.datetime) + +db.generate_mapping(create_tables=True) diff --git a/luncho/server.py b/luncho/server.py new file mode 100644 index 0000000..10ed00d --- /dev/null +++ b/luncho/server.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import sys + +from flask import Flask + +# ---------------------------------------------------------------------- +# Config +# ---------------------------------------------------------------------- +SQLITE_FILENAME = './luncho.db3' + +# ---------------------------------------------------------------------- +# Load the config +# ---------------------------------------------------------------------- +app = Flask(__name__) +app.config.from_object(__name__) +app.config.from_envvar('LUCNHO_CONFIG', True) + +# ---------------------------------------------------------------------- +# Blueprints +# ---------------------------------------------------------------------- +from blueprints.index import index + +app.register_blueprint(index, url_prefix='/') + +# ---------------------------------------------------------------------- +# Database +# ---------------------------------------------------------------------- +from pony.orm import db_session +app.wsgi_app = db_session(app.wsgi_app) + +# ---------------------------------------------------------------------- +# Main +# ---------------------------------------------------------------------- +if __name__ == '__main__': + log.warning('Use manage.py to run the server.') + sys.exit(1) + diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..a7471d8 --- /dev/null +++ b/manage.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +import logging + +from flask.ext.script import Manager + +from luncho.server import app + +manager = Manager(app) + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + manager.run() diff --git a/requirements.txt b/requirements.txt index 42b7a23..d17b341 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ Flask flask-script -flask-sqlalchemy +pony