Skip to content

Commit

Permalink
demo first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
BartSaelen committed Apr 11, 2014
1 parent b2e94ee commit 05e7550
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 12 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include *.txt *.ini *.cfg *.rst
recursive-include atramhasis *.ico *.png *.css *.gif *.jpg *.pt *.txt *.jinja2 *.js *.html *.xml
graft atramhasis/scaffolds
13 changes: 9 additions & 4 deletions atramhasis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
from .models import (
DBSession,
Base,
)
)


def includeme(config):
"""this function adds some configuration for the application"""
config.include('pyramid_jinja2')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')


def main(global_config, **settings):
Expand All @@ -14,8 +21,6 @@ def main(global_config, **settings):
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
includeme(config)
config.scan()
return config.make_wsgi_app()
11 changes: 11 additions & 0 deletions atramhasis/scaffolds/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pyramid.scaffolds import PyramidTemplate


class AtramhasisTemplate(PyramidTemplate):
_template_dir = 'atramhasis_scaffold'
summary = 'Create an Atramhasis implementation'


class AtramhasisDemoTemplate(PyramidTemplate):
_template_dir = 'atramhasis_demo'
summary = 'Create an Atramhasis demo'
18 changes: 18 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/+package+/__init__.py_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pyramid.config import Configurator


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""

print("--{{project}}--MAIN--")

# Set up pyramid
config = Configurator(settings=settings)

#Add skos support
config.include('{{package}}.skos')

config.scan()

return config.make_wsgi_app()
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-

import os
import csv

from skosprovider.providers import (
DictionaryProvider,
SimpleCsvProvider
)

import logging
log = logging.getLogger(__name__)

larch = {
'id': '1',
'uri': 'http://id.trees.org/1',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'The Larch'},
{'type': 'prefLabel', 'language': 'nl', 'label': 'De Lariks'}
],
'notes': [
{'type': 'definition', 'language': 'en', 'note': 'A type of tree.'}
]
}

chestnut = {
'id': '2',
'uri': 'http://id.trees.org/2',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'The Chestnut'},
{'type': 'altLabel', 'language': 'nl', 'label': 'De Paardekastanje'}
],
'notes': [
{
'type': 'definition', 'language': 'en',
'note': 'A different type of tree.'
}
]
}

species = {
'id': 3,
'uri': 'http://id.trees.org/3',
'labels': [
{'type': 'prefLabel', 'language': 'en', 'label': 'Trees by species'},
{'type': 'prefLabel', 'language': 'nl', 'label': 'Bomen per soort'}
],
'type': 'collection',
'members': ['1', '2']
}

TREES = DictionaryProvider(
{'id': 'TREES', 'default_language': 'nl'},
[larch, chestnut, species]
)


def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
for row in csv_reader:
yield [unicode(cell, 'utf-8') for cell in row]

reader = unicode_csv_reader(
open(os.path.join(os.path.dirname(__file__), 'menu.csv'), 'r'),
delimiter=',',
quotechar='"'
)

MENU = SimpleCsvProvider(
{'id': 'MENU'},
reader
)


def includeme(config):
config.include('pyramid_skosprovider')
config.scan('pyramid_skosprovider')
skosregis = config.get_skos_registry()
skosregis.register_provider(TREES)
skosregis.register_provider(MENU)

11 changes: 11 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/+package+/skos/menu.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1,"Egg and Bacon",
2,"Egg, sausage and Bacon",
3,"Egg and Spam",
4,"Spam Egg Sausage and Spam",
5,"Egg, Bacon and Spam",
6,"Egg, Bacon, sausage and Spam",
7,"Spam, Bacon, sausage and Spam",
8,"Spam, Egg, Spam, Spam, Bacon and Spam",
9,"Spam, Spam, Spam, Egg and Spam",
10,"Spam, Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam",
11,"Lobster Thermidor", "Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provencale manner with shallots and aubergines, garnished with truffle pâté, brandy and a fried egg on top and Spam"
4 changes: 4 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/CHANGES.txt_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.0
---

- Initial version
2 changes: 2 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/MANIFEST.in_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.txt *.ini *.cfg *.rst
recursive-include {{package}} *.ico *.png *.css *.gif *.jpg *.pt *.txt *.jinja2 *.js *.html *.xml
3 changes: 3 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/README.txt_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{project}} README

This is a Atramhasis demo application
Binary file not shown.
76 changes: 76 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/development.ini_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:atramhasis

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid_tm

sqlalchemy.url = sqlite:///%(here)s/atramhasis.sqlite

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1

###
# wsgi server configuration
###

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, atramhasis, sqlalchemy, {{package_logger}}

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_atramhasis]
level = DEBUG
handlers =
qualname = atramhasis

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[logger_{{package_logger}}]
level = DEBUG
handlers =
qualname = {{package}}

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
50 changes: 50 additions & 0 deletions atramhasis/scaffolds/atramhasis_demo/setup.py_tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.txt')) as f:
README = f.read()
with open(os.path.join(here, 'CHANGES.txt')) as f:
CHANGES = f.read()

requires = [
'pyramid',
'pyramid_debugtoolbar',
'pyramid_tm',
'SQLAlchemy',
'transaction',
'zope.sqlalchemy',
'waitress',
'skosprovider',
'skosprovider_sqlalchemy',
'pyramid_skosprovider',
'pyramid_jinja2',
'alembic'
]

setup(name='{{project}}',
version='0.0',
description='{{project}}',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
keywords='web pyramid pylons',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requires,
tests_require=requires,
test_suite="{{package}}",
entry_points="""\
[paste.app_factory]
main = {{package}}:main
""",
)
19 changes: 11 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
'transaction',
'zope.sqlalchemy',
'waitress',
'skosprovider',
'skosprovider',
'skosprovider_sqlalchemy',
'pyramid_skosprovider',
'pyramid_jinja2',
'alembic'
]
]

setup(name='atramhasis',
version='0.0',
description='atramhasis',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
Expand All @@ -47,5 +47,8 @@
main = atramhasis:main
[console_scripts]
initialize_atramhasis_db = atramhasis.scripts.initializedb:main
[pyramid.scaffold]
atramhasis_scaffold=atramhasis.scaffolds:AtramhasisTemplate
atramhasis_demo=atramhasis.scaffolds:AtramhasisDemoTemplate
""",
)
)

0 comments on commit 05e7550

Please sign in to comment.