Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #57 from plone/newt_support
Browse files Browse the repository at this point in the history
Newt support
  • Loading branch information
bloodbare committed Jan 27, 2017
2 parents 84bdb5b + 708ee12 commit 9a7266e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
11 changes: 11 additions & 0 deletions buildout-newt.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[buildout]
extends = buildout.cfg
parts -= server
parts += newtdb

[newtdb]
recipe = zc.recipe.egg
eggs =
plone.server
plone.example
newt.db
50 changes: 50 additions & 0 deletions config-newt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"databases": [
{
"newt0": {
"storage": "NEWT",
"type": "postgres",
"dsn": {
"dbname": "zodb",
"username": "zodb",
"password": "secret",
"host": "localhost",
"port": "5432"
},
"options": {
"read_only": false,
"keep_history": true,
"commit_lock_timeout": 30
},
"configuration": {
"pool_size": 100,
"cache_size": 100
}
}
}
],
"applications": [],
"address": 8080,
"static": [
{"favicon.ico": "static/favicon.ico"}
],
"root_user": {
"password": "root"
},
"auth_token_validators": [
"plone.server.auth.validators.SaltedHashPasswordValidator"
],
"jwt": {
"secret": "secret",
"algorithm": "HS256"
},
"cors": {
"allow_origin": ["*"],
"allow_methods": ["GET", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS"],
"allow_headers": ["*"],
"expose_headers": ["*"],
"allow_credentials": true,
"max_age": 3660
},
"utilities": []
}
3 changes: 3 additions & 0 deletions src/plone.server/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ New features:
- install, uninstall methods for addon class can now be async
[vangheem]

- Support with newt
[ramonnb]

- Be able to define adapters, subscribers, permissions, roles, grant
with decorators, not zcml
[vangheem]
Expand Down
28 changes: 28 additions & 0 deletions src/plone.server/plone/server/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
except ImportError:
RELSTORAGE = False

try:
import newt.db
NEWT = True
except ImportError:
NEWT = False

try:
from Crypto.PublicKey import RSA
Expand Down Expand Up @@ -478,6 +483,29 @@ def make_app(config_file=None, settings=None):
rs = RelStorage(adapter=adapter, options=options)
db = RequestAwareDB(rs, **config)
dbo = Database(key, db)
elif dbconfig['storage'] == 'NEWT' and NEWT:
options = Options(**dbconfig['options'])
if dbconfig['type'] == 'postgres':
from relstorage.adapters.postgresql import PostgreSQLAdapter
dsn = "dbname={dbname} user={username} host={host} password={password} port={port}".format(**dbconfig['dsn'])
adapter = PostgreSQLAdapter(dsn=dsn, options=options)
rs = RelStorage(adapter=adapter, options=options)
db = DB(rs)
try:
conn = db.open()
rootobj = conn.root()
if not IDatabase.providedBy(rootobj):
alsoProvides(rootobj, IDatabase)
transaction.commit()
except:
pass
finally:
rootobj = None
conn.close()
db.close()
rs = RelStorage(adapter=adapter, options=options)
db = newt.db._db.NewtDB(RequestAwareDB(rs, **config))
dbo = Database(key, db)
elif dbconfig['storage'] == 'DEMO':
storage = DemoStorage(name=dbconfig['name'])
db = DB(storage)
Expand Down

0 comments on commit 9a7266e

Please sign in to comment.