annotate PerfsDb/ConfigFileBuilder.py @ 158:df1f9946571c

perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
author am@osimis.io
date Fri, 17 Aug 2018 11:58:26 +0200
parents f1a75985caa8
children 616da104a996
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import typing
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 import json
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
3 import os
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
4
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5 from DbType import DbType
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7 class ConfigFileBuilder:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 @staticmethod
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 def generate(
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 outputPath: str,
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
12 pluginsPath: str,
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 storagePath: str,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 dbType: DbType,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 dbSize: str,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16 port: int
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
17 ):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
19 config = {}
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
20 config["StorageDirectory"] = storagePath
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
21
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22 dbConfig = {}
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
23 dbConfig["EnableIndex"] = True
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
24
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
25 if dbType.isServer():
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
26 dbConfig["Host"] = "127.0.0.1"
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
27 dbConfig["Lock"] = False
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
28 dbConfig["Port"] = port
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
29
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
30 if dbType == DbType.MySQL:
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
31 config["Plugins"] = [os.path.join(pluginsPath, "libOrthancMySQLIndex.so")]
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
32 dbConfig["EnableStorage"] = False
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
33 # config["Plugins"] = [os.path.join(pluginsPath, "libOrthancMySQLStorage.so")]
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
34
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35 dbConfig["Database"] = "orthanc"
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
36 dbConfig["Username"] = "orthanc"
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37 dbConfig["Password"] = "orthanc"
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
39 config["MySQL"] = dbConfig
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
40
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
41 elif dbType.isPG():
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
42 config["Plugins"] = [os.path.join(pluginsPath, "libOrthancPostgreSQLIndex.so")]
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43 dbConfig["EnableStorage"] = False
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
44 # config["Plugins"] = [os.path.join(pluginsPath, "libOrthancPostgreSQLStorage.so")]
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
45
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
46 dbConfig["Database"] = "postgres"
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
47 dbConfig["Username"] = "postgres"
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
48
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
49 config["PostgreSQL"] = dbConfig
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
50
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
51 elif dbType == DbType.MSSQL:
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
52 config["Plugins"] = [os.path.join(pluginsPath, "libOrthancMsSqlIndex.so")]
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
53 dbConfig["EnableStorage"] = False
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
54
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
55 dbConfig["ConnectionString"] = "Driver={ODBC Driver 13 for SQL Server};Server=tcp:127.0.0.1," + str(port) + ";Database=master;Uid=sa;Pwd=MyStrOngPa55word!;Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30"
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
56 dbConfig["LicenseString"] = "1abaamBcReVXv6EtE_X___demo-orthanc%osimis.io___HHHnqVHYvEkR3jGs2Y3EvpbxZgTt7yaCniJa2Bz7hFWTMa" # note: this is a trial license expiring on 2018-09-30, replace with your license code
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
57
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
58 config["MSSQL"] = dbConfig
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
59
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
60 elif dbType.isSqlite():
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
61 config["IndexDirectory"] = storagePath
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
62 if dbType == DbType.SqlitePlugin:
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
63 config["Plugins"] = [os.path.join(pluginsPath, "libOrthancSQLiteIndex.so")]
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
64
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
65 else:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
66 raise NotImplementedError
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
67
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
68 with open(outputPath, "w") as configFile:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
69 json.dump(config, fp=configFile, indent=4)