def sendMail(self, app, mailContents):
        smtpServer = app.getConfigValue("smtp_server")
        smtpUsername = app.getConfigValue("smtp_server_username")
        smtpPassword = app.getConfigValue("smtp_server_password")
        fromAddress = app.getBatchConfigValue("batch_sender")
        toAddresses = plugins.commasplit(app.getBatchConfigValue("batch_recipients"))
        import smtplib

        smtp = smtplib.SMTP()
        try:
            smtp.connect(smtpServer)
        except Exception:  # Can't use SMTPException, because this raises socket.error usually
            return "Could not connect to SMTP server at " + smtpServer + "\n" + self.exceptionOutput()
        if smtpUsername:
            try:
                smtp.login(smtpUsername, smtpPassword)
            except smtplib.SMTPException:
                return (
                    "Failed to login as '"
                    + smtpUsername
                    + "' to SMTP server at "
                    + smtpServer
                    + "\n"
                    + self.exceptionOutput()
                )
        try:
            smtp.sendmail(fromAddress, toAddresses, mailContents)
        except smtplib.SMTPException:
            return "Mail could not be sent\n" + self.exceptionOutput()
        smtp.quit()
 def __init__(self, args):
     argDict = self.parseArguments(args, [ "old", "new", "file" ])
     self.oldTextTrigger = plugins.TextTrigger(argDict["old"])
     self.newText = argDict["new"].replace("\\n", "\n")
     self.stems = []
     fileStr = argDict.get("file")
     if fileStr:
         self.stems = plugins.commasplit(fileStr)
 def addValuesToTotal(self, localName, valuesLine, totalValues):
     catValues = plugins.commasplit(valuesLine.strip())
     try:
         for value in catValues:
             catName, count = value.split("=")
             if not totalValues.has_key(catName):
                 totalValues[catName] = 0
             totalValues[catName] += int(count)
     except ValueError:
         plugins.printWarning("Found truncated or old format batch report (" + localName + ") - could not parse result correctly.")
 def __init__(self, args):
     argDict = self.parseArguments(args, [ "old", "new", "file", "regexp", "argsReplacement", "includeShortcuts" ])
     tryAsRegexp = "regexp" not in argDict or argDict["regexp"] == "1"
     self.argsReplacement = "argsReplacement" in argDict and argDict["argsReplacement"] == "1"
     self.oldText = argDict["old"].replace("\\n", "\n")
     self.newText = argDict["new"].replace("\\n", "\n")
     if self.newText.endswith("\n") and self.oldText.endswith("\n"):
         self.oldText = self.oldText.rstrip()
     self.newText = self.newText.rstrip()
     self.trigger = plugins.MultilineTextTrigger(self.oldText, tryAsRegexp, False) if not self.argsReplacement else plugins.TextTrigger(self.oldText, tryAsRegexp, False)
     self.newMultiLineText = self.newText.split("\n")
     self.stems = []
     fileStr = argDict.get("file")
     if fileStr:
         self.stems = plugins.commasplit(fileStr)
     self.includeShortcuts = "includeShortcuts" in argDict and argDict["includeShortcuts"] == "1"
Exemple #5
0
 def sendMail(self, app, mailContents):
     smtpServer = app.getConfigValue("smtp_server")
     smtpUsername = app.getConfigValue("smtp_server_username")
     smtpPassword = app.getConfigValue("smtp_server_password")
     fromAddress = app.getCompositeConfigValue("batch_sender", self.sessionName)
     toAddresses = plugins.commasplit(app.getCompositeConfigValue("batch_recipients", self.sessionName))
     from smtplib import SMTP
     smtp = SMTP()    
     try:
         smtp.connect(smtpServer)
     except:
         return "Could not connect to SMTP server at " + smtpServer + "\n" + self.exceptionOutput()
     if smtpUsername:
         try:
             smtp.login(smtpUsername, smtpPassword)
         except:
             return "Failed to login as '" + smtpUsername + "' to SMTP server at " + smtpServer + \
                 "\n" + self.exceptionOutput()
     try:
         smtp.sendmail(fromAddress, toAddresses, mailContents)
     except:
         return "Mail could not be sent\n" + self.exceptionOutput()
     smtp.quit()
 def __init__(self, timeLimit, *args):
     self.minTime = 0.0
     self.maxTime = sys.maxint
     times = plugins.commasplit(timeLimit)
     if timeLimit.count("<") == 0 and timeLimit.count(">") == 0: # Backwards compatible
         if len(times) == 1:
             self.maxTime = plugins.getNumberOfSeconds(timeLimit)
         else:
             self.minTime = plugins.getNumberOfSeconds(times[0])
             if len(times[1]):
                 self.maxTime = plugins.getNumberOfSeconds(times[1])
     else:
         for expression in times:
             parsedExpression = parseTimeExpression(expression)
             if parsedExpression[0] == "":
                 continue
             elif parsedExpression[0] == "<":
                 self.adjustMaxTime(parsedExpression[1] - 1) # We don't care about fractions of seconds ...
             elif parsedExpression[0] == "<=":
                 self.adjustMaxTime(parsedExpression[1]) 
             elif parsedExpression[0] == ">":
                 self.adjustMinTime(parsedExpression[1] + 1) # We don't care about fractions of seconds ...
             else:
                 self.adjustMinTime(parsedExpression[1])
Exemple #7
0
 def getBackupVersions(self):
     versionString = self.optionGroup.getOptionValue("old")
     if versionString:
         return plugins.commasplit(versionString)
     else:
         return []
Exemple #8
0
 def extractOrder(self, line):
     startPos = line.find("order=") + 6
     endPos = line.rfind("-->")
     return plugins.commasplit(line[startPos:endPos])
 def __init__(self, args):
     argDict = self.parseArguments(args, [ "script", "types", "file" ])
     self.script = argDict.get("script")
     self.fileName = argDict.get("file", "traffic")
     self.trafficTypes = plugins.commasplit(argDict.get("types", "CLI,SRV"))
 def _getDescriptor(self, configEntry, configName):
     fromConfig = self.configMethod(configEntry, configName)
     if len(fromConfig) > 0:
         name, briefDesc, longDesc = plugins.commasplit(fromConfig)
         plugins.addCategory(name, briefDesc, longDesc)
         return name