You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
import os |
|
import sys |
|
import transaction |
|
|
|
from pyramid.paster import ( |
|
get_appsettings, |
|
setup_logging, |
|
) |
|
|
|
from pyramid.scripts.common import parse_vars |
|
|
|
from urllib.parse import urlparse |
|
|
|
from ..models.meta import Base |
|
from ..models import ( |
|
get_engine, |
|
get_session_factory, |
|
get_tm_session, |
|
) |
|
from ..models import Role, User |
|
|
|
|
|
def usage(argv): |
|
cmd = os.path.basename(argv[0]) |
|
print('usage: %s <config_uri> [var=value]\n' |
|
'(example: "%s development.ini")' % (cmd, cmd)) |
|
sys.exit(1) |
|
|
|
|
|
def main(argv=sys.argv): |
|
if len(argv) < 2: |
|
usage(argv) |
|
config_uri = argv[1] |
|
options = parse_vars(argv[2:]) |
|
setup_logging(config_uri) |
|
settings = get_appsettings(config_uri, options=options) |
|
|
|
# remove an existing database |
|
sqlalchemy_url = urlparse(settings['sqlalchemy.url']) |
|
path = os.path.abspath(sqlalchemy_url.path) |
|
if os.path.exists(path): |
|
os.remove(path) |
|
|
|
engine = get_engine(settings) |
|
Base.metadata.create_all(engine) |
|
|
|
session_factory = get_session_factory(engine) |
|
|
|
with transaction.manager: |
|
dbsession = get_tm_session(session_factory, transaction.manager) |
|
|
|
account = User( |
|
username='Holgi', |
|
first_name='Holger', |
|
last_name='Frey', |
|
email='frey@imtek.de', |
|
role=Role.ADMIN |
|
) |
|
account.set_password('test') |
|
dbsession.add(account)
|
|
|