56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
|
|
#!/opt/homebrew/bin/python3
|
||
|
|
# -*- coding:utf-8 -*-
|
||
|
|
import json
|
||
|
|
from PyQt6 import *
|
||
|
|
from PyQt6.QtCore import *
|
||
|
|
from logs import log
|
||
|
|
from typing import Union
|
||
|
|
from models import DevModel, Session
|
||
|
|
from config import config
|
||
|
|
from projectModel.projectManager import projectManager
|
||
|
|
from influxDB import influxdb
|
||
|
|
|
||
|
|
class InfluxdbManager(QObject):
|
||
|
|
|
||
|
|
def __init__(self, parent=None):
|
||
|
|
super().__init__()
|
||
|
|
|
||
|
|
@pyqtSlot(result=str)
|
||
|
|
def getCurrentInfluxdb(self):
|
||
|
|
if not config.data.__contains__("influxdbName"):
|
||
|
|
config.data["influxdbName"] = config.data["influxdbs"][0]['name']
|
||
|
|
return config.data["influxdbName"]
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=bool)
|
||
|
|
def setInfluxdb(self, influxdbName):
|
||
|
|
influxdbs = config.data["influxdbs"]
|
||
|
|
confData = config.toDict()
|
||
|
|
confData['influxdbName'] = influxdbName
|
||
|
|
for _influxdb in influxdbs:
|
||
|
|
if _influxdb["name"] == influxdbName:
|
||
|
|
influxdb.close()
|
||
|
|
influxdb.setConfig( _influxdb )
|
||
|
|
influxdb.open()
|
||
|
|
projectInfo = projectManager.getCurrentProInfo()
|
||
|
|
proname = "name" in projectInfo and projectInfo["name"] or ""
|
||
|
|
influxdb.create(proname)
|
||
|
|
config.update(confData)
|
||
|
|
return True
|
||
|
|
return False
|
||
|
|
|
||
|
|
@pyqtSlot(str, result=QVariant)
|
||
|
|
@pyqtSlot(str, result=list)
|
||
|
|
def getInfo(self, name = 'all'):
|
||
|
|
influxdbs = config.data["influxdbs"]
|
||
|
|
if name == 'all':
|
||
|
|
return influxdbs
|
||
|
|
else:
|
||
|
|
for _influxdb in influxdbs:
|
||
|
|
if _influxdb['name'] == name:
|
||
|
|
return _influxdb
|
||
|
|
return None
|
||
|
|
|
||
|
|
influxdbManager = InfluxdbManager()
|
||
|
|
|
||
|
|
|