perf scripts python: call-graph-from-sql.py: Separate the database details into a class
Separate the database details into a class that can provide different connections using the same connection information. That paves the way for sub-processes that require their own connection. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/20181001062853.28285-7-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
7e4fc93e2a
commit
b2556c46a6
@ -284,6 +284,42 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.setCentralWidget(self.view)
|
self.setCentralWidget(self.view)
|
||||||
|
|
||||||
|
# Database reference
|
||||||
|
|
||||||
|
class DBRef():
|
||||||
|
|
||||||
|
def __init__(self, is_sqlite3, dbname):
|
||||||
|
self.is_sqlite3 = is_sqlite3
|
||||||
|
self.dbname = dbname
|
||||||
|
|
||||||
|
def Open(self, connection_name):
|
||||||
|
dbname = self.dbname
|
||||||
|
if self.is_sqlite3:
|
||||||
|
db = QSqlDatabase.addDatabase("QSQLITE", connection_name)
|
||||||
|
else:
|
||||||
|
db = QSqlDatabase.addDatabase("QPSQL", connection_name)
|
||||||
|
opts = dbname.split()
|
||||||
|
for opt in opts:
|
||||||
|
if "=" in opt:
|
||||||
|
opt = opt.split("=")
|
||||||
|
if opt[0] == "hostname":
|
||||||
|
db.setHostName(opt[1])
|
||||||
|
elif opt[0] == "port":
|
||||||
|
db.setPort(int(opt[1]))
|
||||||
|
elif opt[0] == "username":
|
||||||
|
db.setUserName(opt[1])
|
||||||
|
elif opt[0] == "password":
|
||||||
|
db.setPassword(opt[1])
|
||||||
|
elif opt[0] == "dbname":
|
||||||
|
dbname = opt[1]
|
||||||
|
else:
|
||||||
|
dbname = opt
|
||||||
|
|
||||||
|
db.setDatabaseName(dbname)
|
||||||
|
if not db.open():
|
||||||
|
raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
|
||||||
|
return db, dbname
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
|
|
||||||
def Main():
|
def Main():
|
||||||
@ -302,31 +338,8 @@ def Main():
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if is_sqlite3:
|
dbref = DBRef(is_sqlite3, dbname)
|
||||||
db = QSqlDatabase.addDatabase('QSQLITE')
|
db, dbname = dbref.Open("main")
|
||||||
else:
|
|
||||||
db = QSqlDatabase.addDatabase('QPSQL')
|
|
||||||
opts = dbname.split()
|
|
||||||
for opt in opts:
|
|
||||||
if '=' in opt:
|
|
||||||
opt = opt.split('=')
|
|
||||||
if opt[0] == 'hostname':
|
|
||||||
db.setHostName(opt[1])
|
|
||||||
elif opt[0] == 'port':
|
|
||||||
db.setPort(int(opt[1]))
|
|
||||||
elif opt[0] == 'username':
|
|
||||||
db.setUserName(opt[1])
|
|
||||||
elif opt[0] == 'password':
|
|
||||||
db.setPassword(opt[1])
|
|
||||||
elif opt[0] == 'dbname':
|
|
||||||
dbname = opt[1]
|
|
||||||
else:
|
|
||||||
dbname = opt
|
|
||||||
|
|
||||||
db.setDatabaseName(dbname)
|
|
||||||
if not db.open():
|
|
||||||
raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MainWindow(db, dbname)
|
window = MainWindow(db, dbname)
|
||||||
window.show()
|
window.show()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user