Exemple #1
0
 def run(self, retry, smtpServer, emailFrom, emailTo, archive_file):
     
     self._buildInputfile()
     IOService.run(self, retry)
     
     if not os.path.exists(self.output_file):
         logging.warning("The Daily Archiving failed, missing output file")
         subject = 'Daily Archiving Failed'
         body = 'The Daily Archiving failed with error: missing output file.  Imagine logfile attached if it exists.'
         send_email(smtpServer, emailFrom, emailTo, subject, body, {os.path.dirname(self.log_file):os.path.basename(self.log_file)})
         return
         
     paths = os.path.split(archive_file)
     archive_file = os.path.join(paths[0], "%s_%s" % (self.asofdate, paths[1]))
     
     outputFile= file(archive_file, 'wb')
     for tempFile in [self.output_file]:
         logging.info('Reading part file %s' % tempFile)
         tfile = file(tempFile, 'rb')
         line = tfile.readline()                
         while line:
             outputFile.write(line)
             line = tfile.readline()
     outputFile.close()
                 
     logging.info("Done")  
     return archive_file
Exemple #2
0
    def run(self):

        # 1. Run Trade Extract
        archive_filename = self.trade_extract_ios.run(
            self.retry, self.smtp_server, self.email_from, self.email_to, self.trade_extract_filename
        )

        message = "created %s" % archive_filename
        dispatch_archive_event(
            sender=self, path=archive_filename, rpath=None, source="imagine_maintenance", message=message
        )

        # 2. Run Daily Movers

        self.daily_movers_ios.run(self.retry, self.smtp_server, self.email_from, self.email_to)

        # 3. Run Credit Spread

        self.credit_spread_ios.run(self.retry, self.smtp_server, self.email_from, self.email_to)

        # 4. Send email to confirm all complete.

        logging.info("Daily OPS Process Complete")
        subject = "Daily OPS Process Complete"
        body = ""
        logging.info("Sending email to %s" % repr(self.email_to))
        send_email(self.smtp_server, self.email_from, self.email_to, subject, body, {})

        return
Exemple #3
0
    def run(self, retry, smtpServer, emailFrom, emailTo):
        """Runs the service to update security level credit spread overrides in Imagine."""

        # Get indices of arguments we'll need to change
        ios = self.args.index("-ios") + 1
        f = self.args.index("-f") + 1
        o = self.args.index("-o") + 1

        try:
            # Run print portfolio i/o service
            self._buildPPInputFile()
            result = IOService.run(self, retry)
            if result != 0:
                raise Exception, "IO Service failure"

            # Run update security environment i/o service
            self.args[ios] = "updateSecurityEnvironment"
            self.args[f] = self.use_input_file
            self.args[o] = self.use_output_file

            self._parsePPOutputFile()
            self._buildUSEInputFile(credit_spread=0.01)
            result = IOService.run(self, retry)
            if result != 0:
                raise Exception, "IO Service failure"

            # Run print portfolio i/o service again
            self.args[ios] = "printPortfolio"
            self.args[f] = self.pp_input_file
            self.args[o] = self.pp_output_file
            result = IOService.run(self, retry)
            if result != 0:
                raise Exception, "IO Service failure"

            # Run update security environment i/o service with Implied Credit Spreads inserted
            self.args[ios] = "updateSecurityEnvironment"
            self.args[f] = self.use_input_file
            self.args[o] = self.use_output_file

            self._parsePPOutputFile()
            self._buildUSEInputFile()
            result = IOService.run(self, retry)
            if result != 0:
                raise Exception, "IO Service failure"

        except NoCreditSpreadHoldings:
            logging.info("All credit spread holdings in imagine have zero quantity, bypassing further downloads.")

        except Exception, e:
            logging.exception("The Credit Spread extract failed with error %s" % e)
            subject = "Credit Spread extract failed"
            body = "The Credit Spread service failed with error message %s.  Imagine logfile attached." % e
            send_email(
                smtpServer,
                emailFrom,
                emailTo,
                subject,
                body,
                {os.path.dirname(self.log_file): os.path.basename(self.log_file)},
            )
Exemple #4
0
    def run(self, retry, smtpServer, emailFrom, emailTo, archive_file):

        self._buildInputfile()
        IOService.run(self, retry)

        if not os.path.exists(self.output_file):
            logging.warning("The Trade Extract failed, missing output file")
            subject = "Trade Extract Failed"
            body = "The Trade Extract failed, missing output file.  Imagine logfile attached."
            send_email(
                smtpServer,
                emailFrom,
                emailTo,
                subject,
                body,
                {os.path.dirname(self.log_file): os.path.basename(self.log_file)},
            )
            return

        paths = os.path.split(archive_file)
        archive_file = os.path.join(paths[0], "%s_%s" % (self.asofdate, paths[1]))

        self._formatOutputFile(archive_file)

        logging.info("Done")
        return archive_file
Exemple #5
0
    def _emailReport(self, server, email_from, email_to):
        """Generates daily flash report email in html format."""
        
        if self.docs:
            
            # Get data for header
            headers = self.report_control.model.fund.columns
            data = {}
            for row in self.report_control.model.fund.data:
                row = dict(zip(headers, row))
                if row['Deals'] == 'Whiteclif':
                    data = row
            
            navstring = '${:,.0f}M'.format(data['Total Value']/1000000)
            if abs(data['Day P&L']) < 1000000:
                pnl_string = '${:.0f}K'.format(abs(data['Day P&L']/1000))
            else:
                pnl_string = '${:,.2f}M'.format(abs(data['Day P&L']/1000000))
            if data['Day P&L'] < 0 :
                pnl_string = '(' + pnl_string + ')'
            subject = 'Whiteclif Valuation {0} / Day P&L {1} / Prior Period Adjustment $0K'.format(navstring, pnl_string)
            
            # Get attachments
            
            html = [doc[1] for doc in self.docs if doc[0]=='html'][0]
            pdf = [doc[1] for doc in self.docs if doc[0]=='pdf'][0]

            logging.info("Convert html to image")
            name = os.path.splitext(os.path.split(html)[1])[0]
            imagefile = os.path.join(self.working_path, '{}.png'.format(name))

            convert(html, imagefile, ["--width","800","--quality","50"])
            
            message = "Flash PnL attachments can also be accessed here: \n\n"

            tail, head = os.path.split(pdf)
            href = os.path.join(self.reports_url, self.asofdate.strftime("%Y/%B/%d"), head)
            message = '%s\t<a href="%s">%s</a>\n' % (message, href, head)
        
            message = """<img src="%s"/>

%s\n\nLinks to Operation's files:

    <a href="file:///\\corp.local\shared\Company%%20Shared\Kew%%20Portal\WhiteclifPnL">S:\Kew Portal\Whiteclif P&amp;L</a>
    <a href="file:///\\corp.local\shared\Company%%20Shared\Kew%%20Portal\Trade%%20Extract">S:\Kew Portal\Trade Extract</a>

""" % (imagefile, message)

            message = "<pre>\n\n%s</pre>" % message
            
            logging.info("Sending email to {}".format(email_to))
            send_email(server, email_from, email_to, subject, body='', attachments={tail:head}, html=message)
            
        else:
            raise Exception, "No report files produced for Flash Report"
Exemple #6
0
    def run(self, retry, smtpServer, emailFrom, emailTo):
        """Runs the daily movers service."""

        self._buildInputfile()
        IOService.run(self, retry)

        if not os.path.exists(self.output_file):
            logging.warning("The Daily Movers extract failed, missing output file")
            subject = "Daily Movers extract failed"
            body = "The Daily Movers failed, missing output file.  Imagine logfile attached."
            send_email(
                smtpServer,
                emailFrom,
                emailTo,
                subject,
                body,
                {os.path.dirname(self.log_file): os.path.basename(self.log_file)},
            )
            return

        body = self._parseOutputFile()
        subject = "Daily Movers %s" % self.asofdate.strftime("%d-%b-%Y")
        send_email(smtpServer, emailFrom, emailTo, subject, body, {})
Exemple #7
0
 def run(self, retry, smtpServer, emailFrom, emailTo, reports_db):
     """Runs the service to generate the flash report from Imagine."""
     
     try:
         #Run print portfolio i/o service
         self._buildInputFile()
         result = IOService.run(self, retry)
         if result != 0:
             raise Exception, "IO Service failure"
         logging.info("Establishing session with database %s" % reports_db)
         engine = create_engine(reports_db)
         Session = sessionmaker(bind=engine)
         session = Session()
         
         self._loadDatabase(session)
         self._generateReport(session)
         self._emailReport(smtpServer, emailFrom, emailTo)
     
     except Exception, e:
         logging.exception("The Daily Flash extract failed with error %s" % e)
         subject = 'Daily Flash extract failed'
         body = 'The Daily Flash service failed with error message "%s".  Imagine logfile attached.' % e
         send_email(smtpServer, emailFrom, emailTo, subject, body, {os.path.dirname(self.log_file):os.path.basename(self.log_file)})
         return