Python передача данных между функциями
Я пытаюсь создать плазмоидный виджет, чтобы показать вывод Snort на моем рабочем столе, в настоящее время я изучаю C, но у меня мало знаний о Python, кроме того, что я выяснил, пытаясь сделать это приложения, я изначально думал, что это было это будет просто, но Иисус... это 4 дня болтало с моей головой, и я просто не могу заставить ее работать...
Я не могу просто сделать
commands.getoutput("snort -A console -q -u snort -g snort -c /etc/snort/snort.conf")
Потому что это программа типа "top", которая обновляется и остается "открытой" на экране bash, а не просто выводит выходные данные и завершает выполнение...
Итак, из того, что я собрал, мне нужно сделать это через потоки, чтобы я узнал, что могу сделать следующее
def snortout():
print(time.ctime())
threading.Timer(10, repeat).start()
f= open('snort.out', 'w')
top= os.system("snort -A console -q -u snort -g snort -c /etc/snort/snort.conf")
s=str(top)
textout = f.write(s)
snortout()
Теперь мне нужно передать данные "textout" в функцию paintInterface(), и я не уверен, что делать... Я думаю, я мог бы объявить глобальный в верхней части программы и передать "textout" из snortout() в глобальный и вызвать его из paintInterface(), чтобы он отображался художником?
Я не в курсе, ребята...
# -*- coding: utf-8 -*-
# <Copyright and license information goes here.>
from PyQt4.QtCore import Qt
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript
import commands
import os
import time
import threading
class HelloPython(plasmascript.Applet):
def __init__(self,parent,args=None):
plasmascript.Applet.__init__(self,parent)
def init(self):
self.setHasConfigurationInterface(False)
self.resize(800, 400)
self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
def repeat():
print(time.ctime())
threading.Timer(10, repeat).start()
f= open('snort.out', 'w')
top= os.system("snort -A console -q -u snort -g snort -c /etc/snort/snort.conf")
s=str(top)
textout = f.write(s)
repeat()
def paintInterface(self, painter, option, rect):
painter.save()
painter.setPen(Qt.black)
painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter,textout)
painter.restore()
def CreateApplet(parent):
return HelloPython(parent)