Example #1
0
def _buildBody(sender, recipients, subject, msg, info=None, debug=None,
               failure=None, exception=None, documents=None):
    body = [msg]
    if info:
        body.append("Information:\n\n%s" % info)
    if debug:
        body.append("Additional Debug Info:\n\n%s" % debug)
    if exception:
        body.append("Exception Message: %s\n\nException Traceback:\n\n%s"
                    % (log.getExceptionMessage(exception),
                       log.getExceptionTraceback(exception)))
    if failure:
        body.append("Failure Message: %s\n\nFailure Traceback:\n%s"
                    % (log.getFailureMessage(failure),
                       log.getFailureTraceback(failure)))
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = recipients
    txt = MIMEText("\n\n\n".join(body))
    msg.attach(txt)
    if documents:
        for doc in documents:
            mimeType = doc.getMimeType()
            mainType, subType = mimeType.split('/', 1)
            data = MIMEBase(mainType, subType)
            data.set_payload(doc.asString())
            email.Encoders.encode_base64(data)
            data.add_header('Content-Disposition', 'attachment',
                            filename=doc.label)
            msg.attach(data)
    return str(msg)
Example #2
0
def notifyDebug(msg, info=None, debug=None, failure=None,
                exception=None, documents=None):
    """
    This function can be used from anywere to notify
    debug information (like traceback) when no
    Notifier reference is available.
    Do not raise any exception.
    """
    global _shutingDown
    if _shutingDown: return
    try:
        sender = _debugSender
        recipients = _debugRecipients
        log.info("Try sending a debug notification to %s from %s",
                 recipients, sender,
                 category=adminconsts.NOTIFIER_LOG_CATEGORY)
        body = _buildBody(sender, recipients, msg, msg, info, debug,
                          failure, exception, documents)
        d = _postNotification(_smtpServer, _smtpPort, _smtpRequireTLS,
                              sender, recipients, body)
        args = ("Debug",)
        d.addCallbacks(_cbNotificationDone, _ebNotificationFailed,
                       callbackArgs=args, errbackArgs=args)
    except Exception, e:
        log.warning("Debug Notification Failed: %s",
                    log.getExceptionMessage(e),
                    category=adminconsts.NOTIFIER_LOG_CATEGORY)
Example #3
0
 def __setNiceLevel(self, niceLevel):
     context = self._context
     reporter = context.reporter
     try:
         os.nice(niceLevel - os.nice(0))
         context.info("Changed the process nice level to %d", niceLevel)
         reporter.report.niceLevel = niceLevel
     except OSError, e:
         reporter.addError(e)
         context.warning("Failed to change process nice level: %s",
                         log.getExceptionMessage(e))
         reporter.report.niceLevel = os.nice(0)
 def do_render(self, buffer):
     if self._error or not self._segment:
         return gst.FLOW_ERROR
     try:
         streamTime = self._segment.to_stream_time(gst.FORMAT_TIME,
                                                   buffer.timestamp)
         self._sampler.update(streamTime, buffer)
         return gst.FLOW_OK
     except Exception, e:
         msg = "Failure during thumbnail sampling: " + str(e)
         debug = log.getExceptionMessage(e)
         self.postError(msg, debug)
         return gst.FLOW_ERROR
 def __loadReport(self, localPath):
     if not localPath:
         return None
     if not os.path.exists(localPath):
         message = ("Transcoder report file not found ('%s')" % localPath)
         self.warning("%s", message)
         raise errors.TranscoderError(message)
     loader = inifile.IniFile()
     report = transreport.TranscodingReport()
     try:
         loader.loadFromFile(report, localPath)
     except Exception, e:
         message = ("Failed to load transcoder report file '%s': %s"
                    % (localPath, log.getExceptionMessage(e)))
         self.warning("%s", message)
         raise errors.TranscoderError(message)
 def __deleteTempReport(self):
     if self._reportForcedPath:
         return
     current = self._reportDefaultPath
     temp = self._job.getTempReportPath()
     if ((current != temp)
         and os.path.isfile(current)
         and os.path.isfile(temp)):
         try:
             os.remove(temp)
         except OSError, e:
             msg = "Fail to delete temporary report"
             self.warning("%s '%s'", msg, temp)
             info = "File path: '%s'" % temp
             debug = log.getExceptionMessage(e)
             self.__notifyDebug(msg, info=info, debug=debug, exception=e)
 def prepare(self, workerCtx):
     adminCtx = workerCtx.getAdminContext()
     adminLocal = adminCtx.getLocal()
     localPath = self._configPath.localize(adminLocal)
     # The .ini file is created here...
     saver = inifile.IniFile()
     # Set the datetime of file creation
     self._config.touch()
     try:
         fileutils.ensureDirExists(os.path.dirname(localPath),
                                   "transcoding config", self._pathAttr)
         saver.saveToFile(self._config, localPath)
     except Exception, e:
         message = ("Failed to save transcoder config file '%s': %s"
                    % (localPath, log.getExceptionMessage(e)))
         log.warning("%s", message)
         raise admerrs.PropertiesError(message)
Example #8
0
 def _notifyDebug(self, msg, info=None, debug=None, failure=None,
                   exception=None, documents=None):
     infoMsg = ["File Monitor Debug Notification: %s" % msg]
     debugMsg = []
     if info:
         infoMsg.append("Information:\n\n%s" % info)
     if debug:
         debugMsg.append("Additional Debug Info:\n\n%s" % debug)
     if failure:
         debugMsg.append("Failure Message: %s\nFailure Traceback:\n%s"
                         % (log.getFailureMessage(failure),
                            log.getFailureTraceback(failure)))
     if exception:
         debugMsg.append("Exception Message: %s\n\nException Traceback:\n%s"
                         % (log.getExceptionMessage(exception),
                            log.getExceptionTraceback(exception)))
     m = messages.Warning(_("\n\n".join(infoMsg)),
                          debug="\n\n".join(debugMsg))
     self.addMessage(m)
Example #9
0
def safe_mkdirs(dir, description, attr=None):
    """
    Ensure the given directory exists, creating it if not.
    Raises a SystemError if this fails, including the given description.
    If mkdir fail, verify the directory hasn't been created by another process.
    """
    dir = os.path.abspath(dir)
    try:
        os.makedirs(dir, 0755)
    except OSError, e:
        if not os.path.isdir(dir):
            if e.errno == 17:
                raise SystemError("Could not create %s directory '%s': "
                                  "it exists but it's not a directory"
                                  % (description, dir))
            else:
                raise SystemError("Could not create %s directory '%s': %s"
                                  % (description, dir, log.getExceptionMessage(e)),
                                  cause=e)
Example #10
0
 def createFromComponentDict(cls, workerCtx, props):
     niceLevel = props.get("nice-level", None)
     name = props.get("admin-id", "")
     configPath = virtualpath.VirtualPath(props.get("config", None))
     pathAttr = fileutils.PathAttributes.createFromComponentProperties(props)
     adminCtx = workerCtx.getAdminContext()
     adminLocal = adminCtx.getLocal()
     localPath = configPath.localize(adminLocal)
     if not os.path.exists(localPath):
         message = ("Transcoder config file not found ('%s')" % localPath)
         log.warning("%s", message)
         raise admerrs.PropertiesError(message)
     loader = inifile.IniFile()
     config = transconfig.TranscodingConfig()
     try:
         loader.loadFromFile(config, localPath)
     except Exception, e:
         message = ("Failed to load transcoder config file '%s': %s"
                    % (localPath, log.getExceptionMessage(e)))
         log.warning("%s", message)
         raise admerrs.PropertiesError(message)
 def _bus_message_callback(self, bus, message):
     try:
         if message.type == gst.MESSAGE_STATE_CHANGED:
             if message.src == self._pipeline:
                 new = message.parse_state_changed()[1]
                 if new == gst.STATE_PAUSED:
                     self.__onPipelinePrerolled()
             return
         if message.type == gst.MESSAGE_EOS:
             self.__onPipelineEOS()
             return
         if message.type == gst.MESSAGE_ERROR:
             gstgerror, debug = message.parse_error()
             self.__onPipelineError(gstgerror.message, debug)
             return
         self.log(
             "Unhandled GStreamer message in thumbnailing pipeline " "'%s': %s", self._getTranscodingTag(), message
         )
     except Exception, e:
         msg = "Error during thumbnailing pipeline " "message handling: " + str(e)
         debug = log.getExceptionMessage(e)
         self.__postError(msg, debug)
Example #12
0
            except Exception, e:
                parser.error("Default transcoder root directory '%s' cannot be created: %s"
                             % (rootDir, str(e)))

        try:
            upgrader = UpgradeConfig(options.tag, oldConfigFile,
                                     newConfigDir, rootDir,
                                     disableRequests=options.disableRequests,
                                     changeMail=options.changeMail,
                                     keepConfig=options.keepConfig,
                                     doBackup=options.doBackup)
            upgrader.upgrade()
        except Exception, e:
            print
            if options.verbose > 3:
                print "ERROR: %s" % log.getExceptionMessage(e)
            else:
                print "ERROR: %s" % str(e)
            if options.verbose > 4:
                print log.getExceptionTraceback(e)
            print

        return

    if args == ['upgrade']:
        print
        print "Not implemented yet"
        print
        sys.exit(0)

    print