176 |
176 |
templateDbPath = os.path.join(path, 'Template.db')
|
177 |
177 |
return templateDbPath
|
178 |
178 |
|
|
179 |
def getAppDbPath(self):
|
|
180 |
"""
|
|
181 |
@brief Get application DB file path in ProgramData
|
|
182 |
@author humkyung
|
|
183 |
@date 2018.10.01
|
|
184 |
"""
|
|
185 |
|
|
186 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID')
|
|
187 |
app_database = os.path.join(path, 'App.db')
|
|
188 |
return app_database
|
|
189 |
|
179 |
190 |
'''
|
180 |
191 |
@brief getter of colors
|
181 |
192 |
@author humkyung
|
... | ... | |
1044 |
1055 |
|
1045 |
1056 |
return res
|
1046 |
1057 |
|
|
1058 |
def getAppConfigs(self, section, key=None):
|
|
1059 |
"""
|
|
1060 |
@brief get application configurations
|
|
1061 |
@author humkyung
|
|
1062 |
@date 2018.11.01
|
|
1063 |
"""
|
|
1064 |
|
|
1065 |
res = []
|
|
1066 |
|
|
1067 |
try:
|
|
1068 |
# Creates or opens a file called mydb with a SQLite3 DB
|
|
1069 |
dbPath = self.getAppDbPath()
|
|
1070 |
conn = sqlite3.connect(dbPath)
|
|
1071 |
# Get a cursor object
|
|
1072 |
cursor = conn.cursor()
|
|
1073 |
|
|
1074 |
if key is not None:
|
|
1075 |
sql = "select * from configuration where section=? and key=?"
|
|
1076 |
param = (section, key)
|
|
1077 |
else:
|
|
1078 |
sql = "select * from configuration where section=?"
|
|
1079 |
param = (section,)
|
|
1080 |
|
|
1081 |
cursor.execute(sql, param)
|
|
1082 |
rows = cursor.fetchall()
|
|
1083 |
for row in rows:
|
|
1084 |
res.append(Config(row[0], row[1], row[2]))
|
|
1085 |
# Catch the exception
|
|
1086 |
except Exception as ex:
|
|
1087 |
# Roll back any change if something goes wrong
|
|
1088 |
conn.rollback()
|
|
1089 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
1090 |
finally:
|
|
1091 |
# Close the db connection
|
|
1092 |
conn.close()
|
|
1093 |
|
|
1094 |
return res
|
|
1095 |
|
1047 |
1096 |
'''
|
1048 |
1097 |
@brief save configurations
|
1049 |
1098 |
@author humkyung
|
... | ... | |
1078 |
1127 |
# Close the db connection
|
1079 |
1128 |
conn.close()
|
1080 |
1129 |
|
|
1130 |
def saveAppConfigs(self, configs):
|
|
1131 |
"""
|
|
1132 |
@brief save application configurations
|
|
1133 |
@author humkyung
|
|
1134 |
@date 2018.10.01
|
|
1135 |
"""
|
|
1136 |
|
|
1137 |
try:
|
|
1138 |
# Creates or opens a file called mydb with a SQLite3 DB
|
|
1139 |
dbPath = self.getAppDbPath()
|
|
1140 |
conn = sqlite3.connect(dbPath)
|
|
1141 |
# Get a cursor object
|
|
1142 |
cursor = conn.cursor()
|
|
1143 |
|
|
1144 |
for config in configs:
|
|
1145 |
value = config.value
|
|
1146 |
if type(value) is str and "'" in value:
|
|
1147 |
value = value.replace("'", "''")
|
|
1148 |
|
|
1149 |
sql = "insert or replace into configuration values(?,?,?)"
|
|
1150 |
param = (config.section, config.key, value)
|
|
1151 |
|
|
1152 |
cursor.execute(sql, param)
|
|
1153 |
conn.commit()
|
|
1154 |
# Catch the exception
|
|
1155 |
except Exception as ex:
|
|
1156 |
# Roll back any change if something goes wrong
|
|
1157 |
conn.rollback()
|
|
1158 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
1159 |
finally:
|
|
1160 |
# Close the db connection
|
|
1161 |
conn.close()
|
|
1162 |
|
1081 |
1163 |
'''
|
1082 |
1164 |
@brief delete configurations
|
1083 |
1165 |
@author humkyung
|
... | ... | |
1107 |
1189 |
# Close the db connection
|
1108 |
1190 |
conn.close()
|
1109 |
1191 |
|
|
1192 |
def deleteAppConfigs(self, section, key=None):
|
|
1193 |
"""
|
|
1194 |
@brief delete application configurations
|
|
1195 |
@author humkyung
|
|
1196 |
@date 2018.11.01
|
|
1197 |
"""
|
|
1198 |
|
|
1199 |
try:
|
|
1200 |
# Creates or opens a file called mydb with a SQLite3 DB
|
|
1201 |
dbPath = self.getAppDbPath()
|
|
1202 |
conn = sqlite3.connect(dbPath)
|
|
1203 |
# Get a cursor object
|
|
1204 |
cursor = conn.cursor()
|
|
1205 |
|
|
1206 |
if key is not None:
|
|
1207 |
sql = "delete from configuration where section='{}' and key='{}'".format(section, key)
|
|
1208 |
else:
|
|
1209 |
sql = "delete from configuration where section='{}'".format(section)
|
|
1210 |
cursor.execute(sql)
|
|
1211 |
|
|
1212 |
conn.commit()
|
|
1213 |
# Catch the exception
|
|
1214 |
except Exception as ex:
|
|
1215 |
# Roll back any change if something goes wrong
|
|
1216 |
conn.rollback()
|
|
1217 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
1218 |
finally:
|
|
1219 |
# Close the db connection
|
|
1220 |
conn.close()
|
|
1221 |
|
1110 |
1222 |
'''
|
1111 |
1223 |
@brief set area list
|
1112 |
1224 |
@history humkyung 2018.05.18 round area coordinate and dimension before saving
|