-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://xpra.org/svn/Xpra/trunk@22622 3bb7dfac-3a0b-4e04-842a-767bc560f471
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
# This file is part of Xpra. | ||
# Copyright (C) 2019 Antoine Martin <antoine@xpra.org> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
import os | ||
import sys | ||
|
||
from xpra.server.auth.sys_auth_base import init, log | ||
from xpra.server.auth.sqlauthbase import SQLAuthenticator, DatabaseUtilBase, run_dbutil | ||
assert init and log #tests will disable logging from here | ||
|
||
|
||
class Authenticator(SQLAuthenticator): | ||
|
||
def __init__(self, username, uri, **kwargs): | ||
SQLAuthenticator.__init__(self, username, **kwargs) | ||
self.uri = uri | ||
|
||
def db_cursor(self, *sqlargs): | ||
from sqlalchemy import create_engine #@UnresolvedImport | ||
db = create_engine(self.uri) | ||
cursor = db.cursor() | ||
cursor.execute(*sqlargs) | ||
#keep reference to db so it doesn't get garbage collected just yet: | ||
cursor.db = db | ||
log("db_cursor(%s)=%s", sqlargs, cursor) | ||
return cursor | ||
|
||
def __repr__(self): | ||
return "sql" | ||
|
||
|
||
class SQLDatabaseUtil(DatabaseUtilBase): | ||
|
||
def __init__(self, uri): | ||
DatabaseUtilBase.__init__(self, uri) | ||
#from sqlalchemy import create_engine #@UnresolvedImport | ||
#db = create_engine(self.uri) | ||
self.param = os.environ.get("PARAMSTYLE", "%s") | ||
|
||
def exec_database_sql_script(self, cursor_cb, *sqlargs): | ||
from sqlalchemy import create_engine #@UnresolvedImport | ||
db = create_engine(self.uri) | ||
log("%s.execute%s", db, sqlargs) | ||
result = db.execute(*sqlargs) | ||
log("result=%s", result) | ||
if cursor_cb: | ||
cursor_cb(result) | ||
return result | ||
|
||
def get_authenticator_class(self): | ||
return Authenticator | ||
|
||
|
||
def main(): | ||
return run_dbutil(SQLDatabaseUtil, "databaseURI", sys.argv) | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |