database uri option
This commit is contained in:
parent
388f10fb22
commit
12f6b562a0
|
@ -3,10 +3,10 @@ import cherrypy
|
|||
import logging
|
||||
from nodepupper.nodeops import NodeOps, NObject, NClass, NClassAttachment
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from nodepupper.common import pwhash
|
||||
import math
|
||||
from urllib.parse import urlparse
|
||||
import math
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
|
||||
APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
|
||||
|
@ -278,7 +278,8 @@ def main():
|
|||
parser.add_argument('-p', '--port', default=8080, type=int, help="tcp port to listen on")
|
||||
# parser.add_argument('-l', '--library', default="./library", help="library path")
|
||||
# parser.add_argument('-c', '--cache', default="./cache", help="cache path")
|
||||
parser.add_argument('-s', '--database', default="./pupper.db", help="path to persistent sqlite database")
|
||||
parser.add_argument('-s', '--database', default=os.environ.get('DATABASE_URI', None),
|
||||
help="mysql:// connection uri")
|
||||
parser.add_argument('--debug', action="store_true", help="enable development options")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
@ -286,6 +287,10 @@ def main():
|
|||
logging.basicConfig(level=logging.INFO if args.debug else logging.WARNING,
|
||||
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
||||
|
||||
if not args.database:
|
||||
print("--database or $DATABASE_URI is required")
|
||||
sys.exit(2)
|
||||
|
||||
library = NodeOps(args.database)
|
||||
|
||||
tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from urllib.parse import urlparse
|
||||
import ZODB
|
||||
from relstorage.storage import RelStorage
|
||||
from relstorage.options import Options
|
||||
|
@ -42,8 +43,10 @@ class NClassAttachment(persistent.Persistent):
|
|||
|
||||
|
||||
class NodeOps(object):
|
||||
def __init__(self, db_path):
|
||||
self.mysql = MySQLAdapter(host="localhost", user="zodb", passwd="zodb", db="zodb",
|
||||
def __init__(self, db_uri):
|
||||
uri = urlparse(db_uri)
|
||||
|
||||
self.mysql = MySQLAdapter(host=uri.hostname, user=uri.username, passwd=uri.password, db=uri.path[1:],
|
||||
options=Options(keep_history=False))
|
||||
self.storage = RelStorage(adapter=self.mysql)
|
||||
self.db = ZODB.DB(self.storage)
|
||||
|
|
|
@ -20,7 +20,7 @@ pycparser==2.19
|
|||
PyMySQL==0.9.3
|
||||
pytz==2018.5
|
||||
PyYAML==3.13
|
||||
RelStorage==2.1.1
|
||||
-e git+ssh://git@git.davepedu.com:223/dave/relstorage.git@5ae138b71a0eeb740208e61cfd1662c49738ee45#egg=RelStorage
|
||||
requests==2.21.0
|
||||
six==1.11.0
|
||||
tempora==1.13
|
||||
|
|
Loading…
Reference in New Issue