def __init__(self, config_path): if not os.path.exists(config_path): raise ValueError("Can't find config file \"" + config_path + "\"") #if sys.stdout = Unbuffered(sys.stdout) sys.stderr = Unbuffered(sys.stderr) self.__config = ConfigParser() self.__config.read(config_path) self.__active_mails_count = 0 self.__send_lock = Lock() self.__users_db = Users(self.get_param_str('Main', 'ACCESS_FILE_PATH')) self.__whitelist = FilterList(self.get_param_str('Main', 'WHITELIST_SENDERS')) self.__blacklist = FilterList(self.get_param_str('Main', 'BLACKLIST_SENDERS'))
def __init__(self, config_path): if not os.path.exists(config_path): raise ValueError("Can't find config file \"" + config_path + "\"") #if sys.stdout = Unbuffered(sys.stdout) sys.stderr = Unbuffered(sys.stderr) self.__config = ConfigParser() self.__config.read(config_path) self.__active_mails_count = 0 self.__send_lock = Lock() self.__users_db = Users(self.get_param_str('Main', 'ACCESS_FILE_PATH')) self.__whitelist = FilterList( self.get_param_str('Main', 'WHITELIST_SENDERS')) self.__blacklist = FilterList( self.get_param_str('Main', 'BLACKLIST_SENDERS'))
def setupUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setObjectName(_fromUtf8("EventDetectionCtrlForm")) EventDetectionCtrlForm.resize(264, 340) self.verticalLayout_3 = QtGui.QVBoxLayout(EventDetectionCtrlForm) self.verticalLayout_3.setSpacing(0) self.verticalLayout_3.setMargin(0) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.groupBox_2 = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(100) sizePolicy.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth()) self.groupBox_2.setSizePolicy(sizePolicy) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.gridLayout_3 = QtGui.QGridLayout(self.groupBox_2) self.gridLayout_3.setMargin(0) self.gridLayout_3.setSpacing(0) self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.preFilterList = FilterList(self.groupBox_2) self.preFilterList.setObjectName(_fromUtf8("preFilterList")) self.gridLayout_3.addWidget(self.preFilterList, 0, 0, 1, 1) self.verticalLayout_3.addWidget(self.groupBox_2) self.groupBox = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) self.groupBox.setSizePolicy(sizePolicy) self.groupBox.setObjectName(_fromUtf8("groupBox")) self.verticalLayout = QtGui.QVBoxLayout(self.groupBox) self.verticalLayout.setSpacing(0) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.detectMethodCombo = QtGui.QComboBox(self.groupBox) self.detectMethodCombo.setObjectName(_fromUtf8("detectMethodCombo")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.detectMethodCombo) self.detectMethodStack = QtGui.QStackedWidget(self.groupBox) self.detectMethodStack.setObjectName(_fromUtf8("detectMethodStack")) self.page_3 = QtGui.QWidget() self.page_3.setObjectName(_fromUtf8("page_3")) self.gridLayout_4 = QtGui.QGridLayout(self.page_3) self.gridLayout_4.setMargin(0) self.gridLayout_4.setSpacing(0) self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) self.label_6 = QtGui.QLabel(self.page_3) self.label_6.setObjectName(_fromUtf8("label_6")) self.gridLayout_4.addWidget(self.label_6, 0, 0, 1, 1) self.stThresholdSpin = SpinBox(self.page_3) self.stThresholdSpin.setProperty("value", 3.0) self.stThresholdSpin.setObjectName(_fromUtf8("stThresholdSpin")) self.gridLayout_4.addWidget(self.stThresholdSpin, 0, 1, 1, 1) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_4.addItem(spacerItem, 1, 0, 1, 1) self.detectMethodStack.addWidget(self.page_3) self.page_2 = QtGui.QWidget() self.page_2.setObjectName(_fromUtf8("page_2")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.page_2) self.verticalLayout_4.setSpacing(0) self.verticalLayout_4.setMargin(0) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.gridLayout = QtGui.QGridLayout() self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.label = QtGui.QLabel(self.page_2) self.label.setObjectName(_fromUtf8("label")) self.gridLayout.addWidget(self.label, 1, 0, 1, 1) self.label_3 = QtGui.QLabel(self.page_2) self.label_3.setObjectName(_fromUtf8("label_3")) self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) self.zcSumAbsThresholdSpin = SpinBox(self.page_2) self.zcSumAbsThresholdSpin.setObjectName(_fromUtf8("zcSumAbsThresholdSpin")) self.gridLayout.addWidget(self.zcSumAbsThresholdSpin, 1, 2, 1, 1) self.zcAmpAbsThresholdSpin = SpinBox(self.page_2) self.zcAmpAbsThresholdSpin.setEnabled(True) self.zcAmpAbsThresholdSpin.setObjectName(_fromUtf8("zcAmpAbsThresholdSpin")) self.gridLayout.addWidget(self.zcAmpAbsThresholdSpin, 2, 2, 1, 1) self.label_8 = QtGui.QLabel(self.page_2) self.label_8.setObjectName(_fromUtf8("label_8")) self.gridLayout.addWidget(self.label_8, 0, 2, 1, 1) self.label_9 = QtGui.QLabel(self.page_2) self.label_9.setObjectName(_fromUtf8("label_9")) self.gridLayout.addWidget(self.label_9, 3, 0, 1, 1) self.zcAmpRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcAmpRelThresholdSpin.setEnabled(False) self.zcAmpRelThresholdSpin.setProperty("value", 8.0) self.zcAmpRelThresholdSpin.setObjectName(_fromUtf8("zcAmpRelThresholdSpin")) self.gridLayout.addWidget(self.zcAmpRelThresholdSpin, 2, 3, 1, 1) self.zcSumRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcSumRelThresholdSpin.setProperty("value", 8.0) self.zcSumRelThresholdSpin.setObjectName(_fromUtf8("zcSumRelThresholdSpin")) self.gridLayout.addWidget(self.zcSumRelThresholdSpin, 1, 3, 1, 1) self.label_7 = QtGui.QLabel(self.page_2) self.label_7.setObjectName(_fromUtf8("label_7")) self.gridLayout.addWidget(self.label_7, 0, 3, 1, 1) self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.page_2) self.doubleSpinBox_2.setEnabled(False) self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2")) self.gridLayout.addWidget(self.doubleSpinBox_2, 3, 3, 1, 1) self.zcLenAbsThresholdSpin = QtGui.QSpinBox(self.page_2) self.zcLenAbsThresholdSpin.setMaximum(100000) self.zcLenAbsThresholdSpin.setProperty("value", 3) self.zcLenAbsThresholdSpin.setObjectName(_fromUtf8("zcLenAbsThresholdSpin")) self.gridLayout.addWidget(self.zcLenAbsThresholdSpin, 3, 2, 1, 1) self.verticalLayout_4.addLayout(self.gridLayout) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem1) self.detectMethodStack.addWidget(self.page_2) self.page = QtGui.QWidget() self.page.setObjectName(_fromUtf8("page")) self.verticalLayout_5 = QtGui.QVBoxLayout(self.page) self.verticalLayout_5.setSpacing(0) self.verticalLayout_5.setMargin(0) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.label_2 = QtGui.QLabel(self.page) self.label_2.setObjectName(_fromUtf8("label_2")) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1) self.cbThresholdSpin = QtGui.QDoubleSpinBox(self.page) self.cbThresholdSpin.setProperty("value", 4.0) self.cbThresholdSpin.setObjectName(_fromUtf8("cbThresholdSpin")) self.gridLayout_2.addWidget(self.cbThresholdSpin, 0, 1, 1, 1) self.label_4 = QtGui.QLabel(self.page) self.label_4.setObjectName(_fromUtf8("label_4")) self.gridLayout_2.addWidget(self.label_4, 1, 0, 1, 1) self.cbRiseTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbRiseTauSpin.setProperty("value", 0.01) self.cbRiseTauSpin.setObjectName(_fromUtf8("cbRiseTauSpin")) self.gridLayout_2.addWidget(self.cbRiseTauSpin, 1, 1, 1, 1) self.label_5 = QtGui.QLabel(self.page) self.label_5.setObjectName(_fromUtf8("label_5")) self.gridLayout_2.addWidget(self.label_5, 2, 0, 1, 1) self.cbFallTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbFallTauSpin.setProperty("value", 0.01) self.cbFallTauSpin.setObjectName(_fromUtf8("cbFallTauSpin")) self.gridLayout_2.addWidget(self.cbFallTauSpin, 2, 1, 1, 1) self.verticalLayout_5.addLayout(self.gridLayout_2) self.detectMethodStack.addWidget(self.page) self.verticalLayout.addWidget(self.detectMethodStack) self.verticalLayout_3.addWidget(self.groupBox) self.retranslateUi(EventDetectionCtrlForm) self.detectMethodCombo.setCurrentIndex(1) self.detectMethodStack.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(EventDetectionCtrlForm)
class Ui_EventDetectionCtrlForm(object): def setupUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setObjectName(_fromUtf8("EventDetectionCtrlForm")) EventDetectionCtrlForm.resize(264, 340) self.verticalLayout_3 = QtGui.QVBoxLayout(EventDetectionCtrlForm) self.verticalLayout_3.setSpacing(0) self.verticalLayout_3.setMargin(0) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.groupBox_2 = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(100) sizePolicy.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth()) self.groupBox_2.setSizePolicy(sizePolicy) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.gridLayout_3 = QtGui.QGridLayout(self.groupBox_2) self.gridLayout_3.setMargin(0) self.gridLayout_3.setSpacing(0) self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.preFilterList = FilterList(self.groupBox_2) self.preFilterList.setObjectName(_fromUtf8("preFilterList")) self.gridLayout_3.addWidget(self.preFilterList, 0, 0, 1, 1) self.verticalLayout_3.addWidget(self.groupBox_2) self.groupBox = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth()) self.groupBox.setSizePolicy(sizePolicy) self.groupBox.setObjectName(_fromUtf8("groupBox")) self.verticalLayout = QtGui.QVBoxLayout(self.groupBox) self.verticalLayout.setSpacing(0) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.detectMethodCombo = QtGui.QComboBox(self.groupBox) self.detectMethodCombo.setObjectName(_fromUtf8("detectMethodCombo")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.detectMethodCombo) self.detectMethodStack = QtGui.QStackedWidget(self.groupBox) self.detectMethodStack.setObjectName(_fromUtf8("detectMethodStack")) self.page_3 = QtGui.QWidget() self.page_3.setObjectName(_fromUtf8("page_3")) self.gridLayout_4 = QtGui.QGridLayout(self.page_3) self.gridLayout_4.setMargin(0) self.gridLayout_4.setSpacing(0) self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) self.label_6 = QtGui.QLabel(self.page_3) self.label_6.setObjectName(_fromUtf8("label_6")) self.gridLayout_4.addWidget(self.label_6, 0, 0, 1, 1) self.stThresholdSpin = SpinBox(self.page_3) self.stThresholdSpin.setProperty("value", 3.0) self.stThresholdSpin.setObjectName(_fromUtf8("stThresholdSpin")) self.gridLayout_4.addWidget(self.stThresholdSpin, 0, 1, 1, 1) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_4.addItem(spacerItem, 1, 0, 1, 1) self.detectMethodStack.addWidget(self.page_3) self.page_2 = QtGui.QWidget() self.page_2.setObjectName(_fromUtf8("page_2")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.page_2) self.verticalLayout_4.setSpacing(0) self.verticalLayout_4.setMargin(0) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.gridLayout = QtGui.QGridLayout() self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.label = QtGui.QLabel(self.page_2) self.label.setObjectName(_fromUtf8("label")) self.gridLayout.addWidget(self.label, 1, 0, 1, 1) self.label_3 = QtGui.QLabel(self.page_2) self.label_3.setObjectName(_fromUtf8("label_3")) self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) self.zcSumAbsThresholdSpin = SpinBox(self.page_2) self.zcSumAbsThresholdSpin.setObjectName(_fromUtf8("zcSumAbsThresholdSpin")) self.gridLayout.addWidget(self.zcSumAbsThresholdSpin, 1, 2, 1, 1) self.zcAmpAbsThresholdSpin = SpinBox(self.page_2) self.zcAmpAbsThresholdSpin.setEnabled(True) self.zcAmpAbsThresholdSpin.setObjectName(_fromUtf8("zcAmpAbsThresholdSpin")) self.gridLayout.addWidget(self.zcAmpAbsThresholdSpin, 2, 2, 1, 1) self.label_8 = QtGui.QLabel(self.page_2) self.label_8.setObjectName(_fromUtf8("label_8")) self.gridLayout.addWidget(self.label_8, 0, 2, 1, 1) self.label_9 = QtGui.QLabel(self.page_2) self.label_9.setObjectName(_fromUtf8("label_9")) self.gridLayout.addWidget(self.label_9, 3, 0, 1, 1) self.zcAmpRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcAmpRelThresholdSpin.setEnabled(False) self.zcAmpRelThresholdSpin.setProperty("value", 8.0) self.zcAmpRelThresholdSpin.setObjectName(_fromUtf8("zcAmpRelThresholdSpin")) self.gridLayout.addWidget(self.zcAmpRelThresholdSpin, 2, 3, 1, 1) self.zcSumRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcSumRelThresholdSpin.setProperty("value", 8.0) self.zcSumRelThresholdSpin.setObjectName(_fromUtf8("zcSumRelThresholdSpin")) self.gridLayout.addWidget(self.zcSumRelThresholdSpin, 1, 3, 1, 1) self.label_7 = QtGui.QLabel(self.page_2) self.label_7.setObjectName(_fromUtf8("label_7")) self.gridLayout.addWidget(self.label_7, 0, 3, 1, 1) self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.page_2) self.doubleSpinBox_2.setEnabled(False) self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2")) self.gridLayout.addWidget(self.doubleSpinBox_2, 3, 3, 1, 1) self.zcLenAbsThresholdSpin = QtGui.QSpinBox(self.page_2) self.zcLenAbsThresholdSpin.setMaximum(100000) self.zcLenAbsThresholdSpin.setProperty("value", 3) self.zcLenAbsThresholdSpin.setObjectName(_fromUtf8("zcLenAbsThresholdSpin")) self.gridLayout.addWidget(self.zcLenAbsThresholdSpin, 3, 2, 1, 1) self.verticalLayout_4.addLayout(self.gridLayout) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem1) self.detectMethodStack.addWidget(self.page_2) self.page = QtGui.QWidget() self.page.setObjectName(_fromUtf8("page")) self.verticalLayout_5 = QtGui.QVBoxLayout(self.page) self.verticalLayout_5.setSpacing(0) self.verticalLayout_5.setMargin(0) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.label_2 = QtGui.QLabel(self.page) self.label_2.setObjectName(_fromUtf8("label_2")) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1) self.cbThresholdSpin = QtGui.QDoubleSpinBox(self.page) self.cbThresholdSpin.setProperty("value", 4.0) self.cbThresholdSpin.setObjectName(_fromUtf8("cbThresholdSpin")) self.gridLayout_2.addWidget(self.cbThresholdSpin, 0, 1, 1, 1) self.label_4 = QtGui.QLabel(self.page) self.label_4.setObjectName(_fromUtf8("label_4")) self.gridLayout_2.addWidget(self.label_4, 1, 0, 1, 1) self.cbRiseTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbRiseTauSpin.setProperty("value", 0.01) self.cbRiseTauSpin.setObjectName(_fromUtf8("cbRiseTauSpin")) self.gridLayout_2.addWidget(self.cbRiseTauSpin, 1, 1, 1, 1) self.label_5 = QtGui.QLabel(self.page) self.label_5.setObjectName(_fromUtf8("label_5")) self.gridLayout_2.addWidget(self.label_5, 2, 0, 1, 1) self.cbFallTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbFallTauSpin.setProperty("value", 0.01) self.cbFallTauSpin.setObjectName(_fromUtf8("cbFallTauSpin")) self.gridLayout_2.addWidget(self.cbFallTauSpin, 2, 1, 1, 1) self.verticalLayout_5.addLayout(self.gridLayout_2) self.detectMethodStack.addWidget(self.page) self.verticalLayout.addWidget(self.detectMethodStack) self.verticalLayout_3.addWidget(self.groupBox) self.retranslateUi(EventDetectionCtrlForm) self.detectMethodCombo.setCurrentIndex(1) self.detectMethodStack.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(EventDetectionCtrlForm) def retranslateUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setWindowTitle(_translate("EventDetectionCtrlForm", "Form", None)) self.groupBox_2.setToolTip(_translate("EventDetectionCtrlForm", "Pre-processing options. Used for processing data before any event detection takes place. Processing is performed in the order listed.", None)) self.groupBox_2.setTitle(_translate("EventDetectionCtrlForm", "Pre-processing", None)) self.groupBox.setTitle(_translate("EventDetectionCtrlForm", "Event Detection", None)) self.detectMethodCombo.setItemText(0, _translate("EventDetectionCtrlForm", "Stdev. Threshold", None)) self.detectMethodCombo.setItemText(1, _translate("EventDetectionCtrlForm", "Zero-crossing", None)) self.detectMethodCombo.setItemText(2, _translate("EventDetectionCtrlForm", "Clements-Bekkers", None)) self.label_6.setText(_translate("EventDetectionCtrlForm", "Threshold", None)) self.label.setText(_translate("EventDetectionCtrlForm", "Sum Thresh.", None)) self.label_3.setText(_translate("EventDetectionCtrlForm", "Amp. Thresh.", None)) self.label_8.setText(_translate("EventDetectionCtrlForm", "Abs.", None)) self.label_9.setText(_translate("EventDetectionCtrlForm", "Len. Thresh.", None)) self.label_7.setText(_translate("EventDetectionCtrlForm", "Rel.", None)) self.label_2.setText(_translate("EventDetectionCtrlForm", "Threshold", None)) self.label_4.setText(_translate("EventDetectionCtrlForm", "Rise Tau", None)) self.label_5.setText(_translate("EventDetectionCtrlForm", "Fall Tau", None))
class msh: def __init__(self, config_path): if not os.path.exists(config_path): raise ValueError("Can't find config file \"" + config_path + "\"") #if sys.stdout = Unbuffered(sys.stdout) sys.stderr = Unbuffered(sys.stderr) self.__config = ConfigParser() self.__config.read(config_path) self.__active_mails_count = 0 self.__send_lock = Lock() self.__users_db = Users(self.get_param_str('Main', 'ACCESS_FILE_PATH')) self.__whitelist = FilterList(self.get_param_str('Main', 'WHITELIST_SENDERS')) self.__blacklist = FilterList(self.get_param_str('Main', 'BLACKLIST_SENDERS')) #def def _send_response(self, email_from, msg): self.__send_lock.acquire() if not msg is None: print "[%s] Sending response to '%s'" % (datetime.today().strftime('%d/%m/%y %H:%M'), email_from) recipients = [email_from, self.get_param_str('Mail', 'SEND_COPY_TO')] message = "%s%s%s\n%s" % ('From: %s \n' % (self.get_param_str('Main', 'BOT_NAME')), 'To: %s \n' % (email_from), 'Subject: Report %s \n' % (datetime.today().strftime('%d/%m/%y %H:%M')), msg) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = smtplib.SMTP_SSL(self.get_param_str("Mail", "SMTP_SERVER"), self.get_param_int("Mail", "SMTP_SSL_PORT")) else: session = smtplib.SMTP(self.get_param_str("Mail", "SMTP_SERVER"), self.get_param_int("Mail", "SMTP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.set_debuglevel(100) #if session.login(self.get_param_str("Mail", "EMAIL_USER"), self.get_param_str("Mail", "EMAIL_PASS")) session.sendmail(self.get_param_str("Mail", "EMAIL_USER"), recipients, message) session.quit() #if self.__send_lock.release() #def def _check_pop(self): print "[%s] Going to get messages by POP" % (datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = poplib.POP3_SSL(self.get_param_str("Mail", "POP_SERVER"), self.get_param_int("Mail", "POP_SSL_PORT")) else: session = poplib.POP3(self.get_param_str("Mail", "POP_SERVER"), self.get_param_int("Mail", "POP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.set_debuglevel(100) #if try: session.user(self.get_param_str("Mail", "EMAIL_USER")) session.pass_(self.get_param_str("Mail", "EMAIL_PASS")) except poplib.error_proto as e: sys.stderr.write("Got an error while conencting to POP server: '%s'\n" % (e)) return False #try numMessages = len(session.list()[1]) for i in range(numMessages): m_parsed = Parser().parsestr("\n".join(session.top(i+1, 0)[1])) if self.get_param_str('Main', 'SUBJECT_CODE_PHRASE') == m_parsed['subject']: #Looks like valid cmd for bot, continue if self._process_msg("\n".join(session.retr(i+1)[1])): session.dele(i+1) #if #if #for session.quit() #def def _check_imap(self): print "[%s] Going to get messages by IMAP" % (datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = imaplib.IMAP4_SSL(self.get_param_str("Mail", "IMAP_SERVER"), self.get_param_int("Mail", "IMAP_SSL_PORT")) else: session = imaplib.IMAP4(self.get_param_str("Mail", "IMAP_SERVER"), self.get_param_int("Mail", "IMAP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.debug = 100 #if try: session.login(self.get_param_str("Mail", "EMAIL_USER"), self.get_param_str("Mail", "EMAIL_PASS")) except imaplib.IMAP4.error as e: sys.stderr.write("Got an error while connecting to IMAP server: '%s'\n" % (e)) return False #try session.select(self.get_param_str('Mail', 'IMAP_MAILBOX_NAME')) typ, data = session.search(None, 'SUBJECT', self.get_param_str("Main", "SUBJECT_CODE_PHRASE")) # 'UNSEEN') if not data[0] is None: for num in data[0].split(): typ, data = session.fetch(num, '(RFC822)') if self._process_msg(data[0][1]): session.store(num, '+FLAGS', '\\Deleted') # session.store(num, '+FLAGS', '\\Seen') #if #for #if session.expunge() session.close() session.logout() #def def _process_msg(self, raw_email): if not type(raw_email) is types.StringType: return True #if m_parsed = Parser().parsestr(raw_email) m_from = m_parsed['from'] if self.__active_mails_count > self.get_param_int('Main', 'NUMBER_OF_PROCESSING_THREADS'): print "[%s] All processing threads are busy. Will try in next iteratio" % (datetime.today().strftime('%d/%m/%y %H:%M')) return False #if print "[%s] Processing message from user '%s'" % (datetime.today().strftime('%d/%m/%y %H:%M'), m_from) #check it in white/black lists if not self.__whitelist.has_elem(m_from, is_enabled(self.get_param_str('Main', 'USE_REGEXP_IN_FILTERING'))): print "Got command from unknown email (%s)" % (m_from) return True #if if self.__blacklist.has_elem(m_from, is_enabled(self.get_param_str('Main', 'USE_REGEXP_IN_FILTERING'))): print "Got command from blacklisted email (%s)" % (m_from) return True #if self.__active_mails_count += 1 for m_body in self._get_payload_from_msg(m_parsed): if self._check_user(m_body[0]): for i in xrange(1, len(m_body)): #self._thread_routine(ddm_from, m_body[i].strip()) Process(target=self._thread_routine, args=(m_from, m_body[i].strip())).start() #for else: print "Received an incorrect pair of user+password!" #if #for return True #def def _get_payload_from_msg(self, parsed_email): """ Generator for extracting all message boundles from email """ if parsed_email.is_multipart(): for msg_from_multipart in parsed_email.get_payload(): # proccesing recursively all multipart messages for sub_msg in self._get_payload_from_msg(msg_from_multipart): yield sub_msg #for #for else: yield parsed_email.get_payload().split("\n") #if #def def _thread_routine(self, m_from, command): self._send_response(m_from, self._perform_user_cmd(command)) self.__active_mails_count -= 1 #def def _check_user(self, credentials_str): try: user, passwd = credentials_str.strip().split(":") return self.__users_db.check(user, passwd) except ValueError: return False; #try #def def _perform_user_cmd(self, command): if 0 >= len(command): return None #if print "[%s] Going to process command '%s'" % (datetime.today().strftime('%d/%m/%y %H:%M'), command) buff = "[%s] %s \r\n" % (datetime.today().strftime('%d/%m/%y %H:%M'), command) if ":list" == command: pass elif command.startswith(":stop"): id = 0 try: id = int(command[5:]) pass except ValueError as e: buf += "Error! Got incorrect parameter for 'stop' command '%s'\n" % (command[5:]) sys.stderr.write("Error! Got incorrect parameter for 'stop' command '%s'\n" % (command[5:])) #try else: time = None if command.startswith(":time="): try: ind = command.index(" ") try: time = int(command[6:ind]) command = command[ind+1:] except ValueError as e: buff += "Error! Got incorrect parameter for 'time' command '%s'\n" % (command[6:ind]) sys.stderr.write("Error! Got incorrect parameter for 'time' command '%s'\n" % (command[6:ind])) return buff #try except ValueError as e: buff += "Error! Wrong format of 'time' command '%s'\n" % (command[6:]) sys.stderr.write("Error! Wrong format of 'time' command '%s'\n" % (command[6:])) return buff #try #if out_buf = [] t = threading.Thread(target=self._run_popen, args=(command, out_buf)) t.start() t.join(time) buff += "\n".join(out_buf) if t.isAlive(): try: t._Thread__stop() buff += "Thread has timeouted after timeout = %i!" % (time) except: sys.stream.write("Thread with command '%s' could not be terminated" % (command)) #try #if #if return buff #def def _run_popen(self, cmd, out_buf_list): get_rev = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) get_rev.wait() for str in get_rev.stdout.readlines(): out_buf_list.append(str) #for out_buf_list.append("retcode = %d\r\n" % get_rev.returncode) #def def check_for_new_commands(self): print "[%s] Checking for new commands\n" % (datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str('Mail', 'USE_IMAP')): return self._check_imap() else: return self._check_pop() #if #def def add_new_user(self, user, passwd): return self.__users_db.add(user, passwd) #def def _get_param(self, sect, param): res = None try: res = self.__config.get(sect, param) except NoOptionError as e: sys.stderr.write("%s\n" % (str(e))) #try return res #def def get_param_int(self, sect, param): res = 0 try: res = int(self._get_param(sect, param)) except ValueError as e: sys.stderr.write("%s\n" % (str(e))) except TypeError as e: sys.stderr.write("%s\n" % (str(e))) #try return res #def def get_param_str(self, sect, param): return self._get_param(sect, param)
#fastcup.py --hospital --servicecode P395 --priority P if args.hospital: c = CUP() hospitals = c.getHospitals(args.servicecode, args.priority) for hospital in hospitals: print(hospital) #python fastcup.py --book --servicecode P3039 --priority D --hospitalcode 30063 --ssn <AAABBB12X34Y567Z> if args.book: c = CUP() services = c.getHospitalServices(args.servicecode, args.priority, args.hospitalcode, args.ssn) fl = FilterList(services) f = DateFilter() f.setGreaterThan(DateConverter.today()) f.setSmallerThan(DateConverter.today() + DateConverter.delta(7)) fl.addFilter(f) results = fl.getFiltered() for result in results: print(result) #python fastcup.py --notify --servicecode P3039 --priority D --hospitalcode 30063 --ssn <AAABBB12X34Y567Z> if args.notify: notify = Notify() qr = notify.register() secs = 120
def __init__(self): super(Window, self).__init__() self.setWindowTitle('Photo Editor') self.viewer = PhotoViewer(self) bw = 32 # buttonWidth iw = 24 # iconWidth self.list = FilterList(self) # self.list.setFixedWidth(350) # 'Load image' button self.btnLoad = QToolButton(self) self.btnLoad.setIcon(QtGui.QIcon("icons/load.png")) self.btnLoad.setFixedSize(bw, bw) self.btnLoad.setIconSize(QtCore.QSize(iw, iw)) self.btnLoad.clicked.connect(self.open_image) # 'Export image' button self.btnExport = QToolButton(self) self.btnExport.setIcon(QtGui.QIcon("icons/export.png")) self.btnExport.setFixedSize(bw, bw) self.btnExport.setIconSize(QtCore.QSize(iw, iw)) self.btnExport.clicked.connect(self.save_image) # 'Zoom in' button self.btnZoomIn = QToolButton(self) self.btnZoomIn.setIcon(QtGui.QIcon("icons/zoom_in.png")) self.btnZoomIn.setFixedSize(bw, bw) self.btnZoomIn.setIconSize(QtCore.QSize(iw, iw)) self.btnZoomIn.clicked.connect(self.zoom_in) # 'Zoom out' button self.btnZoomOut = QToolButton(self) self.btnZoomOut.setIcon(QtGui.QIcon("icons/zoom_out.png")) self.btnZoomOut.setFixedSize(bw, bw) self.btnZoomOut.setIconSize(QtCore.QSize(iw, iw)) self.btnZoomOut.clicked.connect(self.zoom_out) # 'Undo' button self.btnUndo = QToolButton(self) self.btnUndo.setIcon(QtGui.QIcon("icons/undo.png")) self.btnUndo.setFixedSize(bw, bw) self.btnUndo.setIconSize(QtCore.QSize(iw, iw)) self.btnUndo.clicked.connect(self.list.undo) self.btnUndo.setEnabled(False) # 'Redo' button self.btnRedo = QToolButton(self) self.btnRedo.setIcon(QtGui.QIcon("icons/redo.png")) self.btnRedo.setFixedSize(bw, bw) self.btnRedo.setIconSize(QtCore.QSize(iw, iw)) self.btnRedo.clicked.connect(self.list.redo) self.btnRedo.setEnabled(False) # 'Add' button self.btnAdd = QPushButton(self) self.btnAdd.setText("Add") font = QtGui.QFont() font.setPointSize(12) self.btnAdd.setFont(font) self.btnAdd.setFixedSize(bw * 2, bw) mapper = QtCore.QSignalMapper(self) menulabels = [ 'Brightness', 'Nega', 'Median', 'Linear', 'FFT2D', 'Grayscale', 'Thiza', 'Error_diffusion', 'Contrast' ] actions = [] for f in menulabels: action = QAction(self) mapper.setMapping(action, f) action.setText(f) action.triggered.connect(mapper.map) actions.append(action) mapper.mapped['QString'].connect(self.list.add_event) menu = QMenu(self) menu.addActions(actions) self.btnAdd.setMenu(menu) # 'Apply' button self.btnApply = QPushButton(self) self.btnApply.setText("Apply") font = QtGui.QFont() font.setPointSize(12) self.btnApply.setFont(font) self.btnApply.setFixedSize(bw * 2, bw) self.btnApply.clicked.connect(self.list.apply_filters) # Arrange layout vb_layout = QtWidgets.QVBoxLayout(self) top_bar = QtWidgets.QHBoxLayout() top_bar.addWidget(self.btnLoad) top_bar.addStretch(1) top_bar.addWidget(self.btnExport) vb_layout.addLayout(top_bar) splitter = QSplitter(QtCore.Qt.Horizontal) splitter.addWidget(self.viewer) splitter.addWidget(self.list) splitter.setSizes((600, 300)) vb_layout.addWidget(splitter) edit_bar = QtWidgets.QHBoxLayout() edit_bar.addWidget(self.btnZoomIn) edit_bar.addWidget(self.btnZoomOut) edit_bar.addWidget(self.btnUndo) edit_bar.addWidget(self.btnRedo) edit_bar.addStretch(1) edit_bar.addWidget(self.btnAdd) edit_bar.addWidget(self.btnApply) vb_layout.addLayout(edit_bar)
class Window(QtWidgets.QWidget): def __init__(self): super(Window, self).__init__() self.setWindowTitle('Photo Editor') self.viewer = PhotoViewer(self) bw = 32 # buttonWidth iw = 24 # iconWidth self.list = FilterList(self) # self.list.setFixedWidth(350) # 'Load image' button self.btnLoad = QToolButton(self) self.btnLoad.setIcon(QtGui.QIcon("icons/load.png")) self.btnLoad.setFixedSize(bw, bw) self.btnLoad.setIconSize(QtCore.QSize(iw, iw)) self.btnLoad.clicked.connect(self.open_image) # 'Export image' button self.btnExport = QToolButton(self) self.btnExport.setIcon(QtGui.QIcon("icons/export.png")) self.btnExport.setFixedSize(bw, bw) self.btnExport.setIconSize(QtCore.QSize(iw, iw)) self.btnExport.clicked.connect(self.save_image) # 'Zoom in' button self.btnZoomIn = QToolButton(self) self.btnZoomIn.setIcon(QtGui.QIcon("icons/zoom_in.png")) self.btnZoomIn.setFixedSize(bw, bw) self.btnZoomIn.setIconSize(QtCore.QSize(iw, iw)) self.btnZoomIn.clicked.connect(self.zoom_in) # 'Zoom out' button self.btnZoomOut = QToolButton(self) self.btnZoomOut.setIcon(QtGui.QIcon("icons/zoom_out.png")) self.btnZoomOut.setFixedSize(bw, bw) self.btnZoomOut.setIconSize(QtCore.QSize(iw, iw)) self.btnZoomOut.clicked.connect(self.zoom_out) # 'Undo' button self.btnUndo = QToolButton(self) self.btnUndo.setIcon(QtGui.QIcon("icons/undo.png")) self.btnUndo.setFixedSize(bw, bw) self.btnUndo.setIconSize(QtCore.QSize(iw, iw)) self.btnUndo.clicked.connect(self.list.undo) self.btnUndo.setEnabled(False) # 'Redo' button self.btnRedo = QToolButton(self) self.btnRedo.setIcon(QtGui.QIcon("icons/redo.png")) self.btnRedo.setFixedSize(bw, bw) self.btnRedo.setIconSize(QtCore.QSize(iw, iw)) self.btnRedo.clicked.connect(self.list.redo) self.btnRedo.setEnabled(False) # 'Add' button self.btnAdd = QPushButton(self) self.btnAdd.setText("Add") font = QtGui.QFont() font.setPointSize(12) self.btnAdd.setFont(font) self.btnAdd.setFixedSize(bw * 2, bw) mapper = QtCore.QSignalMapper(self) menulabels = [ 'Brightness', 'Nega', 'Median', 'Linear', 'FFT2D', 'Grayscale', 'Thiza', 'Error_diffusion', 'Contrast' ] actions = [] for f in menulabels: action = QAction(self) mapper.setMapping(action, f) action.setText(f) action.triggered.connect(mapper.map) actions.append(action) mapper.mapped['QString'].connect(self.list.add_event) menu = QMenu(self) menu.addActions(actions) self.btnAdd.setMenu(menu) # 'Apply' button self.btnApply = QPushButton(self) self.btnApply.setText("Apply") font = QtGui.QFont() font.setPointSize(12) self.btnApply.setFont(font) self.btnApply.setFixedSize(bw * 2, bw) self.btnApply.clicked.connect(self.list.apply_filters) # Arrange layout vb_layout = QtWidgets.QVBoxLayout(self) top_bar = QtWidgets.QHBoxLayout() top_bar.addWidget(self.btnLoad) top_bar.addStretch(1) top_bar.addWidget(self.btnExport) vb_layout.addLayout(top_bar) splitter = QSplitter(QtCore.Qt.Horizontal) splitter.addWidget(self.viewer) splitter.addWidget(self.list) splitter.setSizes((600, 300)) vb_layout.addWidget(splitter) edit_bar = QtWidgets.QHBoxLayout() edit_bar.addWidget(self.btnZoomIn) edit_bar.addWidget(self.btnZoomOut) edit_bar.addWidget(self.btnUndo) edit_bar.addWidget(self.btnRedo) edit_bar.addStretch(1) edit_bar.addWidget(self.btnAdd) edit_bar.addWidget(self.btnApply) vb_layout.addLayout(edit_bar) """ *** Function Name : open_image() *** Designer : 井村 舜 *** Date : 2018.06.05 *** Function : 画像データを読み込む *** Return : 読み込んだ画像 """ def open_image(self): if os.name == 'nt': fname = QFileDialog.getOpenFileName( self, 'Open file', os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + "\\Desktop", filter="JPG(*.jpg);;PNG(*.png);;BMP(*.bmp)") else: fname = QFileDialog.getOpenFileName( self, 'Open file', "./", filter="JPG(*.jpg);;PNG(*.png);;BMP(*.bmp)") if fname[0]: try: self.array = np.array( Image.open(fname[0]).convert("RGBA"), np.float32) self.update_image(self.array) self.list.set_array(self.array) self.btnUndo.setEnabled(False) self.btnRedo.setEnabled(False) except OSError: QMessageBox.critical(self, 'Error', "The image file is broken.", QMessageBox.Ok) """ *** Function Name : save_image() *** Designer : 高田 康平 *** Date : 2018.06.05 *** Function : 画像データを読み込む *** Return : 読み込んだ画像 """ def save_image(self): if os.name == 'nt': fname = QFileDialog.getSaveFileName( self, 'Save file', os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + "\\Desktop", filter="JPG(*.jpg);;PNG(*.png);;BMP(*.bmp)") else: fname = QFileDialog.getSaveFileName( self, 'Save file', "./", filter="JPG(*.jpg);;PNG(*.png);;BMP(*.bmp)") if fname[0]: try: pil_img = Image.fromarray(self.array.astype( np.uint8)).convert("RGB") pil_img.save(fname[0]) except AttributeError: QMessageBox.critical(self, 'Error', "The image file is not selcted.", QMessageBox.Ok) """ *** Function Name : update_image() *** Designer : 稲垣 大輔 *** Date : 2018.06.05 *** Function : 画像データを更新する *** Return : なし """ def update_image(self, array): self.array = array self.viewer.set_photo(self.ndarray_to_qpixmap(array.astype(np.uint8))) """ *** Function Name : ndarray_to_qpixmap() *** Designer : 稲垣 大輔 *** Date : 2018.06.19 *** Function : ndarray型からQPixMap型への変換 *** Return : QPixMapのデータ """ def ndarray_to_qpixmap(self, image): qimage = QtGui.QImage(image.data, image.shape[1], image.shape[0], image.shape[1] * 4, QtGui.QImage.Format_RGBA8888) pixmap = QtGui.QPixmap.fromImage(qimage) return pixmap """ *** Function Name : zoom_in() *** Designer : 劉 号 *** Date : 2018.06.05 *** Function : _zoomの値増加 *** Return : なし """ def zoom_in(self): if self.viewer.has_photo(): factor = 1.25 self.viewer._zoom += 1 if self.viewer._zoom > 0: self.viewer.scale(factor, factor) elif self.viewer._zoom == 0: self.viewer.fitInView() else: self.viewer._zoom = 0 """ *** Function Name : zoom_out() *** Designer : 劉 号 *** Date : 2018.06.05 *** Function : _zoomの値減少 *** Return : なし """ def zoom_out(self): if self.viewer.has_photo(): factor = 0.8 self.viewer._zoom -= 1 if self.viewer._zoom > 0: self.viewer.scale(factor, factor) elif self.viewer._zoom == 0: self.viewer.fitInView() else: self.viewer._zoom = 0
def getStateList(self, torrentList): states = FilterList() if len(torrentList) > 0: states.append(Filter('All', len(torrentList))) for torrent in torrentList: states.append(Filter(torrent.state, 1)) finishedCount = torrentList.finishedCount() if finishedCount > 0: states.append(Filter('Finished', finishedCount)) unfinishedCount = torrentList.unfinishedCount() if unfinishedCount > 0: states.append(Filter('Unfinished', unfinishedCount)) unstartedCount = torrentList.unstartedCount() if unstartedCount > 0: states.append(Filter('Unstarted', unstartedCount)) return states
def getLabelList(self, torrentList): labels = FilterList() for torrent in torrentList: labels.append(Filter(torrent.label, 1)) return labels
def setupUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setObjectName( _fromUtf8("EventDetectionCtrlForm")) EventDetectionCtrlForm.resize(264, 340) self.verticalLayout_3 = QtGui.QVBoxLayout(EventDetectionCtrlForm) self.verticalLayout_3.setSpacing(0) self.verticalLayout_3.setMargin(0) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.groupBox_2 = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(100) sizePolicy.setHeightForWidth( self.groupBox_2.sizePolicy().hasHeightForWidth()) self.groupBox_2.setSizePolicy(sizePolicy) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.gridLayout_3 = QtGui.QGridLayout(self.groupBox_2) self.gridLayout_3.setMargin(0) self.gridLayout_3.setSpacing(0) self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.preFilterList = FilterList(self.groupBox_2) self.preFilterList.setObjectName(_fromUtf8("preFilterList")) self.gridLayout_3.addWidget(self.preFilterList, 0, 0, 1, 1) self.verticalLayout_3.addWidget(self.groupBox_2) self.groupBox = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.groupBox.sizePolicy().hasHeightForWidth()) self.groupBox.setSizePolicy(sizePolicy) self.groupBox.setObjectName(_fromUtf8("groupBox")) self.verticalLayout = QtGui.QVBoxLayout(self.groupBox) self.verticalLayout.setSpacing(0) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.detectMethodCombo = QtGui.QComboBox(self.groupBox) self.detectMethodCombo.setObjectName(_fromUtf8("detectMethodCombo")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.detectMethodCombo) self.detectMethodStack = QtGui.QStackedWidget(self.groupBox) self.detectMethodStack.setObjectName(_fromUtf8("detectMethodStack")) self.page_3 = QtGui.QWidget() self.page_3.setObjectName(_fromUtf8("page_3")) self.gridLayout_4 = QtGui.QGridLayout(self.page_3) self.gridLayout_4.setMargin(0) self.gridLayout_4.setSpacing(0) self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) self.label_6 = QtGui.QLabel(self.page_3) self.label_6.setObjectName(_fromUtf8("label_6")) self.gridLayout_4.addWidget(self.label_6, 0, 0, 1, 1) self.stThresholdSpin = SpinBox(self.page_3) self.stThresholdSpin.setProperty("value", 3.0) self.stThresholdSpin.setObjectName(_fromUtf8("stThresholdSpin")) self.gridLayout_4.addWidget(self.stThresholdSpin, 0, 1, 1, 1) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_4.addItem(spacerItem, 1, 0, 1, 1) self.detectMethodStack.addWidget(self.page_3) self.page_2 = QtGui.QWidget() self.page_2.setObjectName(_fromUtf8("page_2")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.page_2) self.verticalLayout_4.setSpacing(0) self.verticalLayout_4.setMargin(0) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.gridLayout = QtGui.QGridLayout() self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.label = QtGui.QLabel(self.page_2) self.label.setObjectName(_fromUtf8("label")) self.gridLayout.addWidget(self.label, 1, 0, 1, 1) self.label_3 = QtGui.QLabel(self.page_2) self.label_3.setObjectName(_fromUtf8("label_3")) self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) self.zcSumAbsThresholdSpin = SpinBox(self.page_2) self.zcSumAbsThresholdSpin.setObjectName( _fromUtf8("zcSumAbsThresholdSpin")) self.gridLayout.addWidget(self.zcSumAbsThresholdSpin, 1, 2, 1, 1) self.zcAmpAbsThresholdSpin = SpinBox(self.page_2) self.zcAmpAbsThresholdSpin.setEnabled(True) self.zcAmpAbsThresholdSpin.setObjectName( _fromUtf8("zcAmpAbsThresholdSpin")) self.gridLayout.addWidget(self.zcAmpAbsThresholdSpin, 2, 2, 1, 1) self.label_8 = QtGui.QLabel(self.page_2) self.label_8.setObjectName(_fromUtf8("label_8")) self.gridLayout.addWidget(self.label_8, 0, 2, 1, 1) self.label_9 = QtGui.QLabel(self.page_2) self.label_9.setObjectName(_fromUtf8("label_9")) self.gridLayout.addWidget(self.label_9, 3, 0, 1, 1) self.zcAmpRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcAmpRelThresholdSpin.setEnabled(False) self.zcAmpRelThresholdSpin.setProperty("value", 8.0) self.zcAmpRelThresholdSpin.setObjectName( _fromUtf8("zcAmpRelThresholdSpin")) self.gridLayout.addWidget(self.zcAmpRelThresholdSpin, 2, 3, 1, 1) self.zcSumRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcSumRelThresholdSpin.setProperty("value", 8.0) self.zcSumRelThresholdSpin.setObjectName( _fromUtf8("zcSumRelThresholdSpin")) self.gridLayout.addWidget(self.zcSumRelThresholdSpin, 1, 3, 1, 1) self.label_7 = QtGui.QLabel(self.page_2) self.label_7.setObjectName(_fromUtf8("label_7")) self.gridLayout.addWidget(self.label_7, 0, 3, 1, 1) self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.page_2) self.doubleSpinBox_2.setEnabled(False) self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2")) self.gridLayout.addWidget(self.doubleSpinBox_2, 3, 3, 1, 1) self.zcLenAbsThresholdSpin = QtGui.QSpinBox(self.page_2) self.zcLenAbsThresholdSpin.setMaximum(100000) self.zcLenAbsThresholdSpin.setProperty("value", 3) self.zcLenAbsThresholdSpin.setObjectName( _fromUtf8("zcLenAbsThresholdSpin")) self.gridLayout.addWidget(self.zcLenAbsThresholdSpin, 3, 2, 1, 1) self.verticalLayout_4.addLayout(self.gridLayout) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem1) self.detectMethodStack.addWidget(self.page_2) self.page = QtGui.QWidget() self.page.setObjectName(_fromUtf8("page")) self.verticalLayout_5 = QtGui.QVBoxLayout(self.page) self.verticalLayout_5.setSpacing(0) self.verticalLayout_5.setMargin(0) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.label_2 = QtGui.QLabel(self.page) self.label_2.setObjectName(_fromUtf8("label_2")) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1) self.cbThresholdSpin = QtGui.QDoubleSpinBox(self.page) self.cbThresholdSpin.setProperty("value", 4.0) self.cbThresholdSpin.setObjectName(_fromUtf8("cbThresholdSpin")) self.gridLayout_2.addWidget(self.cbThresholdSpin, 0, 1, 1, 1) self.label_4 = QtGui.QLabel(self.page) self.label_4.setObjectName(_fromUtf8("label_4")) self.gridLayout_2.addWidget(self.label_4, 1, 0, 1, 1) self.cbRiseTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbRiseTauSpin.setProperty("value", 0.01) self.cbRiseTauSpin.setObjectName(_fromUtf8("cbRiseTauSpin")) self.gridLayout_2.addWidget(self.cbRiseTauSpin, 1, 1, 1, 1) self.label_5 = QtGui.QLabel(self.page) self.label_5.setObjectName(_fromUtf8("label_5")) self.gridLayout_2.addWidget(self.label_5, 2, 0, 1, 1) self.cbFallTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbFallTauSpin.setProperty("value", 0.01) self.cbFallTauSpin.setObjectName(_fromUtf8("cbFallTauSpin")) self.gridLayout_2.addWidget(self.cbFallTauSpin, 2, 1, 1, 1) self.verticalLayout_5.addLayout(self.gridLayout_2) self.detectMethodStack.addWidget(self.page) self.verticalLayout.addWidget(self.detectMethodStack) self.verticalLayout_3.addWidget(self.groupBox) self.retranslateUi(EventDetectionCtrlForm) self.detectMethodCombo.setCurrentIndex(1) self.detectMethodStack.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(EventDetectionCtrlForm)
class Ui_EventDetectionCtrlForm(object): def setupUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setObjectName( _fromUtf8("EventDetectionCtrlForm")) EventDetectionCtrlForm.resize(264, 340) self.verticalLayout_3 = QtGui.QVBoxLayout(EventDetectionCtrlForm) self.verticalLayout_3.setSpacing(0) self.verticalLayout_3.setMargin(0) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.groupBox_2 = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(100) sizePolicy.setHeightForWidth( self.groupBox_2.sizePolicy().hasHeightForWidth()) self.groupBox_2.setSizePolicy(sizePolicy) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.gridLayout_3 = QtGui.QGridLayout(self.groupBox_2) self.gridLayout_3.setMargin(0) self.gridLayout_3.setSpacing(0) self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.preFilterList = FilterList(self.groupBox_2) self.preFilterList.setObjectName(_fromUtf8("preFilterList")) self.gridLayout_3.addWidget(self.preFilterList, 0, 0, 1, 1) self.verticalLayout_3.addWidget(self.groupBox_2) self.groupBox = QtGui.QGroupBox(EventDetectionCtrlForm) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.groupBox.sizePolicy().hasHeightForWidth()) self.groupBox.setSizePolicy(sizePolicy) self.groupBox.setObjectName(_fromUtf8("groupBox")) self.verticalLayout = QtGui.QVBoxLayout(self.groupBox) self.verticalLayout.setSpacing(0) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.detectMethodCombo = QtGui.QComboBox(self.groupBox) self.detectMethodCombo.setObjectName(_fromUtf8("detectMethodCombo")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.detectMethodCombo.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.detectMethodCombo) self.detectMethodStack = QtGui.QStackedWidget(self.groupBox) self.detectMethodStack.setObjectName(_fromUtf8("detectMethodStack")) self.page_3 = QtGui.QWidget() self.page_3.setObjectName(_fromUtf8("page_3")) self.gridLayout_4 = QtGui.QGridLayout(self.page_3) self.gridLayout_4.setMargin(0) self.gridLayout_4.setSpacing(0) self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) self.label_6 = QtGui.QLabel(self.page_3) self.label_6.setObjectName(_fromUtf8("label_6")) self.gridLayout_4.addWidget(self.label_6, 0, 0, 1, 1) self.stThresholdSpin = SpinBox(self.page_3) self.stThresholdSpin.setProperty("value", 3.0) self.stThresholdSpin.setObjectName(_fromUtf8("stThresholdSpin")) self.gridLayout_4.addWidget(self.stThresholdSpin, 0, 1, 1, 1) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_4.addItem(spacerItem, 1, 0, 1, 1) self.detectMethodStack.addWidget(self.page_3) self.page_2 = QtGui.QWidget() self.page_2.setObjectName(_fromUtf8("page_2")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.page_2) self.verticalLayout_4.setSpacing(0) self.verticalLayout_4.setMargin(0) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.gridLayout = QtGui.QGridLayout() self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.label = QtGui.QLabel(self.page_2) self.label.setObjectName(_fromUtf8("label")) self.gridLayout.addWidget(self.label, 1, 0, 1, 1) self.label_3 = QtGui.QLabel(self.page_2) self.label_3.setObjectName(_fromUtf8("label_3")) self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) self.zcSumAbsThresholdSpin = SpinBox(self.page_2) self.zcSumAbsThresholdSpin.setObjectName( _fromUtf8("zcSumAbsThresholdSpin")) self.gridLayout.addWidget(self.zcSumAbsThresholdSpin, 1, 2, 1, 1) self.zcAmpAbsThresholdSpin = SpinBox(self.page_2) self.zcAmpAbsThresholdSpin.setEnabled(True) self.zcAmpAbsThresholdSpin.setObjectName( _fromUtf8("zcAmpAbsThresholdSpin")) self.gridLayout.addWidget(self.zcAmpAbsThresholdSpin, 2, 2, 1, 1) self.label_8 = QtGui.QLabel(self.page_2) self.label_8.setObjectName(_fromUtf8("label_8")) self.gridLayout.addWidget(self.label_8, 0, 2, 1, 1) self.label_9 = QtGui.QLabel(self.page_2) self.label_9.setObjectName(_fromUtf8("label_9")) self.gridLayout.addWidget(self.label_9, 3, 0, 1, 1) self.zcAmpRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcAmpRelThresholdSpin.setEnabled(False) self.zcAmpRelThresholdSpin.setProperty("value", 8.0) self.zcAmpRelThresholdSpin.setObjectName( _fromUtf8("zcAmpRelThresholdSpin")) self.gridLayout.addWidget(self.zcAmpRelThresholdSpin, 2, 3, 1, 1) self.zcSumRelThresholdSpin = QtGui.QDoubleSpinBox(self.page_2) self.zcSumRelThresholdSpin.setProperty("value", 8.0) self.zcSumRelThresholdSpin.setObjectName( _fromUtf8("zcSumRelThresholdSpin")) self.gridLayout.addWidget(self.zcSumRelThresholdSpin, 1, 3, 1, 1) self.label_7 = QtGui.QLabel(self.page_2) self.label_7.setObjectName(_fromUtf8("label_7")) self.gridLayout.addWidget(self.label_7, 0, 3, 1, 1) self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.page_2) self.doubleSpinBox_2.setEnabled(False) self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2")) self.gridLayout.addWidget(self.doubleSpinBox_2, 3, 3, 1, 1) self.zcLenAbsThresholdSpin = QtGui.QSpinBox(self.page_2) self.zcLenAbsThresholdSpin.setMaximum(100000) self.zcLenAbsThresholdSpin.setProperty("value", 3) self.zcLenAbsThresholdSpin.setObjectName( _fromUtf8("zcLenAbsThresholdSpin")) self.gridLayout.addWidget(self.zcLenAbsThresholdSpin, 3, 2, 1, 1) self.verticalLayout_4.addLayout(self.gridLayout) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem1) self.detectMethodStack.addWidget(self.page_2) self.page = QtGui.QWidget() self.page.setObjectName(_fromUtf8("page")) self.verticalLayout_5 = QtGui.QVBoxLayout(self.page) self.verticalLayout_5.setSpacing(0) self.verticalLayout_5.setMargin(0) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.label_2 = QtGui.QLabel(self.page) self.label_2.setObjectName(_fromUtf8("label_2")) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1) self.cbThresholdSpin = QtGui.QDoubleSpinBox(self.page) self.cbThresholdSpin.setProperty("value", 4.0) self.cbThresholdSpin.setObjectName(_fromUtf8("cbThresholdSpin")) self.gridLayout_2.addWidget(self.cbThresholdSpin, 0, 1, 1, 1) self.label_4 = QtGui.QLabel(self.page) self.label_4.setObjectName(_fromUtf8("label_4")) self.gridLayout_2.addWidget(self.label_4, 1, 0, 1, 1) self.cbRiseTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbRiseTauSpin.setProperty("value", 0.01) self.cbRiseTauSpin.setObjectName(_fromUtf8("cbRiseTauSpin")) self.gridLayout_2.addWidget(self.cbRiseTauSpin, 1, 1, 1, 1) self.label_5 = QtGui.QLabel(self.page) self.label_5.setObjectName(_fromUtf8("label_5")) self.gridLayout_2.addWidget(self.label_5, 2, 0, 1, 1) self.cbFallTauSpin = QtGui.QDoubleSpinBox(self.page) self.cbFallTauSpin.setProperty("value", 0.01) self.cbFallTauSpin.setObjectName(_fromUtf8("cbFallTauSpin")) self.gridLayout_2.addWidget(self.cbFallTauSpin, 2, 1, 1, 1) self.verticalLayout_5.addLayout(self.gridLayout_2) self.detectMethodStack.addWidget(self.page) self.verticalLayout.addWidget(self.detectMethodStack) self.verticalLayout_3.addWidget(self.groupBox) self.retranslateUi(EventDetectionCtrlForm) self.detectMethodCombo.setCurrentIndex(1) self.detectMethodStack.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(EventDetectionCtrlForm) def retranslateUi(self, EventDetectionCtrlForm): EventDetectionCtrlForm.setWindowTitle( _translate("EventDetectionCtrlForm", "Form", None)) self.groupBox_2.setToolTip( _translate( "EventDetectionCtrlForm", "Pre-processing options. Used for processing data before any event detection takes place. Processing is performed in the order listed.", None)) self.groupBox_2.setTitle( _translate("EventDetectionCtrlForm", "Pre-processing", None)) self.groupBox.setTitle( _translate("EventDetectionCtrlForm", "Event Detection", None)) self.detectMethodCombo.setItemText( 0, _translate("EventDetectionCtrlForm", "Stdev. Threshold", None)) self.detectMethodCombo.setItemText( 1, _translate("EventDetectionCtrlForm", "Zero-crossing", None)) self.detectMethodCombo.setItemText( 2, _translate("EventDetectionCtrlForm", "Clements-Bekkers", None)) self.label_6.setText( _translate("EventDetectionCtrlForm", "Threshold", None)) self.label.setText( _translate("EventDetectionCtrlForm", "Sum Thresh.", None)) self.label_3.setText( _translate("EventDetectionCtrlForm", "Amp. Thresh.", None)) self.label_8.setText(_translate("EventDetectionCtrlForm", "Abs.", None)) self.label_9.setText( _translate("EventDetectionCtrlForm", "Len. Thresh.", None)) self.label_7.setText(_translate("EventDetectionCtrlForm", "Rel.", None)) self.label_2.setText( _translate("EventDetectionCtrlForm", "Threshold", None)) self.label_4.setText( _translate("EventDetectionCtrlForm", "Rise Tau", None)) self.label_5.setText( _translate("EventDetectionCtrlForm", "Fall Tau", None))
class msh: def __init__(self, config_path): if not os.path.exists(config_path): raise ValueError("Can't find config file \"" + config_path + "\"") #if sys.stdout = Unbuffered(sys.stdout) sys.stderr = Unbuffered(sys.stderr) self.__config = ConfigParser() self.__config.read(config_path) self.__active_mails_count = 0 self.__send_lock = Lock() self.__users_db = Users(self.get_param_str('Main', 'ACCESS_FILE_PATH')) self.__whitelist = FilterList( self.get_param_str('Main', 'WHITELIST_SENDERS')) self.__blacklist = FilterList( self.get_param_str('Main', 'BLACKLIST_SENDERS')) #def def _send_response(self, email_from, msg): self.__send_lock.acquire() if not msg is None: print "[%s] Sending response to '%s'" % ( datetime.today().strftime('%d/%m/%y %H:%M'), email_from) recipients = [ email_from, self.get_param_str('Mail', 'SEND_COPY_TO') ] message = "%s%s%s\n%s" % ( 'From: %s \n' % (self.get_param_str('Main', 'BOT_NAME')), 'To: %s \n' % (email_from), 'Subject: Report %s \n' % (datetime.today().strftime('%d/%m/%y %H:%M')), msg) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = smtplib.SMTP_SSL( self.get_param_str("Mail", "SMTP_SERVER"), self.get_param_int("Mail", "SMTP_SSL_PORT")) else: session = smtplib.SMTP( self.get_param_str("Mail", "SMTP_SERVER"), self.get_param_int("Mail", "SMTP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.set_debuglevel(100) #if session.login(self.get_param_str("Mail", "EMAIL_USER"), self.get_param_str("Mail", "EMAIL_PASS")) session.sendmail(self.get_param_str("Mail", "EMAIL_USER"), recipients, message) session.quit() #if self.__send_lock.release() #def def _check_pop(self): print "[%s] Going to get messages by POP" % ( datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = poplib.POP3_SSL( self.get_param_str("Mail", "POP_SERVER"), self.get_param_int("Mail", "POP_SSL_PORT")) else: session = poplib.POP3(self.get_param_str("Mail", "POP_SERVER"), self.get_param_int("Mail", "POP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.set_debuglevel(100) #if try: session.user(self.get_param_str("Mail", "EMAIL_USER")) session.pass_(self.get_param_str("Mail", "EMAIL_PASS")) except poplib.error_proto as e: sys.stderr.write( "Got an error while conencting to POP server: '%s'\n" % (e)) return False #try numMessages = len(session.list()[1]) for i in range(numMessages): m_parsed = Parser().parsestr("\n".join(session.top(i + 1, 0)[1])) if self.get_param_str( 'Main', 'SUBJECT_CODE_PHRASE') == m_parsed['subject']: #Looks like valid cmd for bot, continue if self._process_msg("\n".join(session.retr(i + 1)[1])): session.dele(i + 1) #if #if #for session.quit() #def def _check_imap(self): print "[%s] Going to get messages by IMAP" % ( datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str("Mail", "USE_SSL")): session = imaplib.IMAP4_SSL( self.get_param_str("Mail", "IMAP_SERVER"), self.get_param_int("Mail", "IMAP_SSL_PORT")) else: session = imaplib.IMAP4(self.get_param_str("Mail", "IMAP_SERVER"), self.get_param_int("Mail", "IMAP_PORT")) #if if is_enabled(self.get_param_str("Debug", "NETWORK_COMM_LOGGING")): session.debug = 100 #if try: session.login(self.get_param_str("Mail", "EMAIL_USER"), self.get_param_str("Mail", "EMAIL_PASS")) except imaplib.IMAP4.error as e: sys.stderr.write( "Got an error while connecting to IMAP server: '%s'\n" % (e)) return False #try session.select(self.get_param_str('Mail', 'IMAP_MAILBOX_NAME')) typ, data = session.search( None, 'SUBJECT', self.get_param_str("Main", "SUBJECT_CODE_PHRASE")) # 'UNSEEN') if not data[0] is None: for num in data[0].split(): typ, data = session.fetch(num, '(RFC822)') if self._process_msg(data[0][1]): session.store(num, '+FLAGS', '\\Deleted') # session.store(num, '+FLAGS', '\\Seen') #if #for #if session.expunge() session.close() session.logout() #def def _process_msg(self, raw_email): if not type(raw_email) is types.StringType: return True #if m_parsed = Parser().parsestr(raw_email) m_from = m_parsed['from'] if self.__active_mails_count > self.get_param_int( 'Main', 'NUMBER_OF_PROCESSING_THREADS'): print "[%s] All processing threads are busy. Will try in next iteratio" % ( datetime.today().strftime('%d/%m/%y %H:%M')) return False #if print "[%s] Processing message from user '%s'" % ( datetime.today().strftime('%d/%m/%y %H:%M'), m_from) #check it in white/black lists if not self.__whitelist.has_elem( m_from, is_enabled( self.get_param_str('Main', 'USE_REGEXP_IN_FILTERING'))): print "Got command from unknown email (%s)" % (m_from) return True #if if self.__blacklist.has_elem( m_from, is_enabled( self.get_param_str('Main', 'USE_REGEXP_IN_FILTERING'))): print "Got command from blacklisted email (%s)" % (m_from) return True #if self.__active_mails_count += 1 for m_body in self._get_payload_from_msg(m_parsed): if self._check_user(m_body[0]): for i in xrange(1, len(m_body)): #self._thread_routine(ddm_from, m_body[i].strip()) Process(target=self._thread_routine, args=(m_from, m_body[i].strip())).start() #for else: print "Received an incorrect pair of user+password!" #if #for return True #def def _get_payload_from_msg(self, parsed_email): """ Generator for extracting all message boundles from email """ if parsed_email.is_multipart(): for msg_from_multipart in parsed_email.get_payload(): # proccesing recursively all multipart messages for sub_msg in self._get_payload_from_msg(msg_from_multipart): yield sub_msg #for #for else: yield parsed_email.get_payload().split("\n") #if #def def _thread_routine(self, m_from, command): self._send_response(m_from, self._perform_user_cmd(command)) self.__active_mails_count -= 1 #def def _check_user(self, credentials_str): try: user, passwd = credentials_str.strip().split(":") return self.__users_db.check(user, passwd) except ValueError: return False #try #def def _perform_user_cmd(self, command): if 0 >= len(command): return None #if print "[%s] Going to process command '%s'" % ( datetime.today().strftime('%d/%m/%y %H:%M'), command) buff = "[%s] %s \r\n" % (datetime.today().strftime('%d/%m/%y %H:%M'), command) if ":list" == command: pass elif command.startswith(":stop"): id = 0 try: id = int(command[5:]) pass except ValueError as e: buf += "Error! Got incorrect parameter for 'stop' command '%s'\n" % ( command[5:]) sys.stderr.write( "Error! Got incorrect parameter for 'stop' command '%s'\n" % (command[5:])) #try else: time = None if command.startswith(":time="): try: ind = command.index(" ") try: time = int(command[6:ind]) command = command[ind + 1:] except ValueError as e: buff += "Error! Got incorrect parameter for 'time' command '%s'\n" % ( command[6:ind]) sys.stderr.write( "Error! Got incorrect parameter for 'time' command '%s'\n" % (command[6:ind])) return buff #try except ValueError as e: buff += "Error! Wrong format of 'time' command '%s'\n" % ( command[6:]) sys.stderr.write( "Error! Wrong format of 'time' command '%s'\n" % (command[6:])) return buff #try #if out_buf = [] t = threading.Thread(target=self._run_popen, args=(command, out_buf)) t.start() t.join(time) buff += "\n".join(out_buf) if t.isAlive(): try: t._Thread__stop() buff += "Thread has timeouted after timeout = %i!" % (time) except: sys.stream.write( "Thread with command '%s' could not be terminated" % (command)) #try #if #if return buff #def def _run_popen(self, cmd, out_buf_list): get_rev = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) get_rev.wait() for str in get_rev.stdout.readlines(): out_buf_list.append(str) #for out_buf_list.append("retcode = %d\r\n" % get_rev.returncode) #def def check_for_new_commands(self): print "[%s] Checking for new commands\n" % ( datetime.today().strftime('%d/%m/%y %H:%M')) if is_enabled(self.get_param_str('Mail', 'USE_IMAP')): return self._check_imap() else: return self._check_pop() #if #def def add_new_user(self, user, passwd): return self.__users_db.add(user, passwd) #def def _get_param(self, sect, param): res = None try: res = self.__config.get(sect, param) except NoOptionError as e: sys.stderr.write("%s\n" % (str(e))) #try return res #def def get_param_int(self, sect, param): res = 0 try: res = int(self._get_param(sect, param)) except ValueError as e: sys.stderr.write("%s\n" % (str(e))) except TypeError as e: sys.stderr.write("%s\n" % (str(e))) #try return res #def def get_param_str(self, sect, param): return self._get_param(sect, param)