示例#1
0
    def execute(self):
        """This method gets called automatically by CmdLineTool, and is the core logic of the program."""
        self.config = EngineConfig.EngineConfig(self.configDir(),
                                                self.installDir())
        # check that process is owned by proper user; files will be owned by that user
        processOwner = osutil.getusername()
        dataDirOwner = osutil.ownerForPath(self.config.pgDataDir())
        configuredOwner = self.config.tractorEngineOwner()
        if configuredOwner and processOwner != configuredOwner:
            raise DBControlToolError, "tractor-dbctl is configured to be run by %s; the owner of this process is %s." \
                  % (configuredOwner, processOwner)
        # check that engine owner owns the data directory
        if dataDirOwner != processOwner:
            raise DBControlToolError, "The database data dir %s is owned by %s; the owner of this process is %s." \
                  % (self.config.pgDataDir(), dataDirOwner, processOwner)

        if self.opts.status:
            self.status()
        elif self.opts.start:
            self.start()
        elif self.opts.stop:
            self.stop()
        elif self.opts.startForEngine:
            self.startForEngine()
        elif self.opts.stopForEngine:
            self.stopForEngine()
        elif self.opts.init:
            self.init()
        elif self.opts.build:
            self.build()
        elif self.opts.destroy:
            self.destroy()
        elif self.opts.checkUpgrade:
            self.checkUpgrade()
        elif self.opts.upgrade:
            self.upgrade()
        elif self.opts.purgeJobs:
            self.purgeJobs()
        elif self.opts.purgeArchiveToYearMonth:
            self.purgeArchiveToYearMonth()
        elif self.opts.vacuum:
            self.vacuum()
        elif self.opts.backup:
            self.backup()
        elif self.opts.restore:
            self.restore()
        elif self.opts.purgeLogs:
            self.purgeLogs()
        elif self.opts.logsUsage:
            self.tailLog()
        elif self.opts.tailLog:
            self.tailLog()
        elif self.opts.showParams:
            self.showParams()
        elif self.opts.updateParams:
            self.updateParams()
        else:
            raise OptionParser.OptionParserError(
                "No operations were specified.  Use --help for options.")
示例#2
0
def sendmail(toaddrs, body, fromaddr=None, subject=None,
             replyto=None, multipart_alternative=True):
    """Sends an email to the addresses in toaddrs (can be a string if
    only one address is provided, otherwise must be a list)."""

    def adddomain(addrs):
        """appends the mail domain to each address if it isn't found."""
        if type(addrs) is not type([]):
            addrs = [addrs]
        # add mail domain where needed
        result = [x for x in addrs if "@" in x] + \
                 ["%s@%s" % (x, maildomain) for x in addrs if "@" not in x]
        return result

    if not fromaddr:
        fromaddr = getusername()

    # append the maildomain if need be
    myfromaddr = adddomain(fromaddr)[0]

    if multipart_alternative:
        # multipart mail for mailers
        msg = MIMEMultipart("alternative")
        msg.attach(MIMEText(body))
        msg.attach(MIMEText(htmlify(body), "html"))
    else:
        msg = MIMEText(body)
    # single part for txt msgs
    smsbody = body
    if len(smsbody) > MaxPagerMsgLen:
        smsbody = body[:MaxPagerMsgLen-3] + "..."
    smsmsg = MIMEText(smsbody)

    msg["From"] = myfromaddr
    smsmsg["From"] = myfromaddr

    # get a list of the to addresses
    mytoaddrs  = adddomain(toaddrs)

    # split up the addresses into mailtoaddrs and pagers
    mailtoaddrs = [a for a in mytoaddrs if "-pager" not in a]
    pagers = [a for a in mytoaddrs if "pager" in a]
    
    msg["To"] = ", ".join(mailtoaddrs)
    smsmsg["To"] = ", ".join(pagers)
    
    # add the reply to address
    if replyto:
        msg["Reply-To"] = adddomain(replyto)[0]

    if subject:
        msg["Subject"] = subject
        smsmsg["Subject"] = subject
    
    mail = smtplib.SMTP(mailserver)
    if mailtoaddrs:
        mail.sendmail(myfromaddr, mailtoaddrs, msg.as_string())
    if pagers:
        mail.sendmail(myfromaddr, pagers, smsmsg.as_string())
示例#3
0
    def execute(self):
        """This method gets called automatically by CmdLineTool, and is the core logic of the program."""
        self.config = EngineConfig.EngineConfig(self.configDir(), self.installDir())
        # check that process is owned by proper user; files will be owned by that user
        processOwner = osutil.getusername()
        dataDirOwner = osutil.ownerForPath(self.config.pgDataDir())
        configuredOwner = self.config.tractorEngineOwner()
        if configuredOwner and processOwner != configuredOwner:
            raise DBControlToolError, "tractor-dbctl is configured to be run by %s; the owner of this process is %s." \
                  % (configuredOwner, processOwner)
        # check that engine owner owns the data directory
        if dataDirOwner != processOwner:
            raise DBControlToolError, "The database data dir %s is owned by %s; the owner of this process is %s." \
                  % (self.config.pgDataDir(), dataDirOwner, processOwner)

        if self.opts.status:
            self.status()
        elif self.opts.start:
            self.start()
        elif self.opts.stop:
            self.stop()
        elif self.opts.startForEngine:
            self.startForEngine()
        elif self.opts.stopForEngine:
            self.stopForEngine()
        elif self.opts.init:
            self.init()
        elif self.opts.build:
            self.build()
        elif self.opts.destroy:
            self.destroy()
        elif self.opts.checkUpgrade:
            self.checkUpgrade()
        elif self.opts.upgrade:
            self.upgrade()
        elif self.opts.purgeJobs:
            self.purgeJobs()
        elif self.opts.purgeArchiveToYearMonth:
            self.purgeArchiveToYearMonth()
        elif self.opts.vacuum:
            self.vacuum()
        elif self.opts.backup:
            self.backup()
        elif self.opts.restore:
            self.restore()
        elif self.opts.purgeLogs:
            self.purgeLogs()
        elif self.opts.logsUsage:
            self.tailLog()
        elif self.opts.tailLog:
            self.tailLog()
        elif self.opts.showParams:
            self.showParams()
        elif self.opts.updateParams:
            self.updateParams()
        else:
            raise OptionParser.OptionParserError("No operations were specified.  Use --help for options.")
示例#4
0
def sendmail(toaddrs,
             body,
             fromaddr=None,
             subject=None,
             replyto=None,
             multipart_alternative=True):
    """Sends an email to the addresses in toaddrs (can be a string if
    only one address is provided, otherwise must be a list)."""
    def adddomain(addrs):
        """appends the mail domain to each address if it isn't found."""
        if type(addrs) is not type([]):
            addrs = [addrs]
        # add mail domain where needed
        result = [x for x in addrs if "@" in x] + \
                 ["%s@%s" % (x, maildomain) for x in addrs if "@" not in x]
        return result

    if not fromaddr:
        fromaddr = getusername()

    # append the maildomain if need be
    myfromaddr = adddomain(fromaddr)[0]

    if multipart_alternative:
        # multipart mail for mailers
        msg = MIMEMultipart("alternative")
        msg.attach(MIMEText(body))
        msg.attach(MIMEText(htmlify(body), "html"))
    else:
        msg = MIMEText(body)
    # single part for txt msgs
    smsbody = body
    if len(smsbody) > MaxPagerMsgLen:
        smsbody = body[:MaxPagerMsgLen - 3] + "..."
    smsmsg = MIMEText(smsbody)

    msg["From"] = myfromaddr
    smsmsg["From"] = myfromaddr

    # get a list of the to addresses
    mytoaddrs = adddomain(toaddrs)

    # split up the addresses into mailtoaddrs and pagers
    mailtoaddrs = [a for a in mytoaddrs if "-pager" not in a]
    pagers = [a for a in mytoaddrs if "pager" in a]

    msg["To"] = ", ".join(mailtoaddrs)
    smsmsg["To"] = ", ".join(pagers)

    # add the reply to address
    if replyto:
        msg["Reply-To"] = adddomain(replyto)[0]

    if subject:
        msg["Subject"] = subject
        smsmsg["Subject"] = subject

    mail = smtplib.SMTP(mailserver)
    if mailtoaddrs:
        mail.sendmail(myfromaddr, mailtoaddrs, msg.as_string())
    if pagers:
        mail.sendmail(myfromaddr, pagers, smsmsg.as_string())