Added icon.png
This commit is contained in:
parent
f08c99800d
commit
9ebad5610e
3 changed files with 132 additions and 44 deletions
BIN
pastafaristats/icon.png
Normal file
BIN
pastafaristats/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
|
|
@ -5,6 +5,28 @@ from pastafaristats import send_info_daemon
|
|||
from time import sleep
|
||||
import os
|
||||
import psutil
|
||||
from pathlib import Path
|
||||
import signal
|
||||
|
||||
#Get user_home and environment variables
|
||||
|
||||
user_home=str(Path.home())
|
||||
|
||||
path_config=user_home+'/.config/pastafari/stats.cfg'
|
||||
|
||||
# Create configuration
|
||||
|
||||
Path(os.path.dirname(path_config)).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if not os.path.isfile(path_config):
|
||||
config_data="""[DEFAULT]
|
||||
url_server={}
|
||||
""".format('http://localhost:5000/api_token')
|
||||
|
||||
with open(path_config, 'w') as f:
|
||||
f.write(config_data)
|
||||
|
||||
# Get functions
|
||||
|
||||
def quit_app():
|
||||
print('Quitting Application...')
|
||||
|
|
@ -31,12 +53,18 @@ def quit_app():
|
|||
# Killing using pid
|
||||
|
||||
#p.stop()
|
||||
def show_config_win():
|
||||
|
||||
winconfig.show()
|
||||
|
||||
def send_data():
|
||||
print('Init daemon...')
|
||||
|
||||
url_monit=send_info_daemon.load_config()
|
||||
|
||||
while True:
|
||||
|
||||
send_info_daemon.run()
|
||||
send_info_daemon.run(url_monit)
|
||||
|
||||
sleep(120)
|
||||
|
||||
|
|
@ -62,6 +90,37 @@ class ProcessRunnable(QRunnable):
|
|||
del self.t
|
||||
"""
|
||||
|
||||
class WinConfig(QWidget):
|
||||
def __init__(self, url_monit='http://192.168.1.51/monit'):
|
||||
super().__init__()
|
||||
|
||||
url_monit=send_info_daemon.load_config()
|
||||
|
||||
self.text=QLabel("Change monitoritation url, example: http://192.168.1.51/monit/api_token")
|
||||
self.input=QLineEdit(url_monit)
|
||||
self.button=QPushButton("Save")
|
||||
|
||||
self.layout=QVBoxLayout(self)
|
||||
self.layout.addWidget(self.text)
|
||||
self.layout.addWidget(self.input)
|
||||
self.layout.addWidget(self.button)
|
||||
|
||||
self.button.clicked.connect(self.save_config)
|
||||
|
||||
|
||||
def save_config(self):
|
||||
|
||||
config_data="""[DEFAULT]
|
||||
url_server={}
|
||||
""".format(self.input.text())
|
||||
|
||||
with open(path_config, 'w') as f:
|
||||
f.write(config_data)
|
||||
|
||||
print('Config saved...')
|
||||
|
||||
self.hide()
|
||||
|
||||
app = QApplication([])
|
||||
app.setQuitOnLastWindowClosed(False)
|
||||
|
||||
|
|
@ -79,10 +138,10 @@ menu = QMenu()
|
|||
|
||||
option1 = QAction("Pastafari monitoring")
|
||||
menu.addAction(option1)
|
||||
"""
|
||||
option2 = QAction("GFG")
|
||||
|
||||
option2 = QAction("Setup Monitoring url")
|
||||
option2.triggered.connect(show_config_win)
|
||||
menu.addAction(option2)
|
||||
"""
|
||||
|
||||
# To quit the app
|
||||
quit = QAction("Quit")
|
||||
|
|
@ -92,11 +151,30 @@ menu.addAction(quit)
|
|||
# Adding options to the System Tray
|
||||
tray.setContextMenu(menu)
|
||||
|
||||
# Prepare url monitoritation
|
||||
|
||||
winconfig=WinConfig()
|
||||
|
||||
winconfig.resize(400, 200)
|
||||
|
||||
# Begin background process
|
||||
|
||||
p = ProcessRunnable(target=send_data, args=())
|
||||
p.start()
|
||||
|
||||
# Catch sigint
|
||||
|
||||
def catch_signal(sig, frame):
|
||||
print('Exiting from app...')
|
||||
pid=os.getpid()
|
||||
|
||||
p=psutil.Process(pid)
|
||||
|
||||
p.terminate()
|
||||
exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, catch_signal)
|
||||
|
||||
# Begin tray loop
|
||||
|
||||
app.exec_()
|
||||
|
|
|
|||
|
|
@ -14,14 +14,12 @@ import signal
|
|||
|
||||
#url="http://url/to/info"
|
||||
|
||||
# Get config from /etc/pastafari or ~/.config/pastafari
|
||||
user_home=str(Path.home())
|
||||
|
||||
# Load configuration
|
||||
def load_config():
|
||||
|
||||
yes_config=False
|
||||
|
||||
user_home=str(Path.home())
|
||||
|
||||
config = configparser.ConfigParser(interpolation=None)
|
||||
|
||||
if os.path.isfile(user_home+'/.config/pastafari/stats.cfg'):
|
||||
|
|
@ -36,7 +34,6 @@ elif os.path.isfile('/etc/pastafari/stats.cfg'):
|
|||
|
||||
yes_config=True
|
||||
|
||||
|
||||
if not yes_config:
|
||||
|
||||
exit("Sorry, cannot load config file")
|
||||
|
|
@ -51,7 +48,10 @@ if not 'url_server' in config['DEFAULT']:
|
|||
|
||||
url=config['DEFAULT']['url_server']
|
||||
|
||||
def run():
|
||||
return url
|
||||
|
||||
|
||||
def run(url):
|
||||
|
||||
network_info=psutil.net_io_counters(pernic=False)
|
||||
|
||||
|
|
@ -103,21 +103,31 @@ def run():
|
|||
|
||||
print('Cannot connect to data server -> '+str(e))
|
||||
|
||||
def start():
|
||||
#Reload config
|
||||
url=load_config()
|
||||
|
||||
|
||||
def start(url):
|
||||
|
||||
# Get config from /etc/pastafari or ~/.config/pastafari
|
||||
|
||||
# Load configuration
|
||||
|
||||
while True:
|
||||
|
||||
run()
|
||||
run(url)
|
||||
|
||||
sleep(120)
|
||||
|
||||
if __name__=='__main__':
|
||||
|
||||
def catch_signal(sig, frame):
|
||||
print('Exiting...')
|
||||
exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, catch_signal)
|
||||
|
||||
if __name__=='__main__':
|
||||
url=load_config()
|
||||
|
||||
start()
|
||||
start(url)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue