### Home Classes Methods

### In Files

- lib/taskjuggler/SheetHandlerBase.rb

### Parent

Object

### Methods

- ::new
- #addToScm
- #cutOut
- #error
- #htmlMailBody
- #info
- #log
- #sendEmail
- #sendRichTextEmail
- #setWorkingDir
- #warning

### Files

- CHANGELOG
- COPYING
- README.rdoc

### Class/Module Index

Quicksearch

- TaskJuggler
- TaskJuggler::Account
- TaskJuggler::AccountAttribute
- TaskJuggler::AccountCredit
- TaskJuggler::AccountCreditListAttribute
- TaskJuggler::AccountListRE
- TaskJuggler::AccountScenario
- TaskJuggler::AlertLevelDefinition
- TaskJuggler::AlertLevelDefinitions
- TaskJuggler::Allocation
- TaskJuggler::AllocationAttribute
- TaskJuggler::AttributeBase
- TaskJuggler::AttributeDefinition
- TaskJuggler::AttributeOverwrite
- TaskJuggler::BatchProcessor
- TaskJuggler::Booking
- TaskJuggler::BookingListAttribute
- TaskJuggler::BooleanAttribute
- TaskJuggler::CSVFile
- TaskJuggler::CellSettingPattern
- TaskJuggler::CellSettingPatternList
- TaskJuggler::Charge
- TaskJuggler::ChargeListAttribute
- TaskJuggler::ChargeSet
- TaskJuggler::ChargeSetListAttribute
- TaskJuggler::ChartPlotter
- TaskJuggler::ChartPlotterError
- TaskJuggler::CollisionDetector
- TaskJuggler::ColumnListAttribute
- TaskJuggler::ColumnTable
- TaskJuggler::Daemon
- TaskJuggler::DaemonConnector
- TaskJuggler::DaemonConnectorMixin
- TaskJuggler::DataCache
- TaskJuggler::DataCacheEntry
- TaskJuggler::DateAttribute
- TaskJuggler::DefinitionListAttribute
- TaskJuggler::DependencyListAttribute
- TaskJuggler::DurationAttribute
- TaskJuggler::ExportRE
- TaskJuggler::FileList
- TaskJuggler::FileRecord
- TaskJuggler::FixnumAttribute
- TaskJuggler::FlagListAttribute
- TaskJuggler::FloatAttribute
- TaskJuggler::FormatListAttribute
- TaskJuggler::GanttChart
- TaskJuggler::GanttContainer
- TaskJuggler::GanttHeader
- TaskJuggler::GanttHeaderScaleItem
- TaskJuggler::GanttLine
- TaskJuggler::GanttLoadStack
- TaskJuggler::GanttMilestone
- TaskJuggler::GanttRouter
- TaskJuggler::GanttTaskBar
- TaskJuggler::HTMLDocument
- TaskJuggler::HTMLElements
- TaskJuggler::HTMLGraphics
- TaskJuggler::ICalReport
- TaskJuggler::ICalendar
- TaskJuggler::ICalendar::Component
- TaskJuggler::ICalendar::Event
- TaskJuggler::ICalendar::Journal
- TaskJuggler::ICalendar::Person
- TaskJuggler::ICalendar::Todo
- TaskJuggler::Interval
- TaskJuggler::IntervalList
- TaskJuggler::JobInfo
- TaskJuggler::Journal
- TaskJuggler::JournalEntry
- TaskJuggler::JournalEntryList
- TaskJuggler::JournalSortListAttribute
- TaskJuggler::KateSyntax
- TaskJuggler::KeywordArray
- TaskJuggler::KeywordDocumentation
- TaskJuggler::Leave
- TaskJuggler::LeaveAllowance
- TaskJuggler::LeaveAllowanceList
- TaskJuggler::LeaveAllowanceListAttribute
- TaskJuggler::LeaveList
- TaskJuggler::LeaveListAttribute
- TaskJuggler::Limits
- TaskJuggler::Limits::Limit
- TaskJuggler::LimitsAttribute
- TaskJuggler::ListAttributeBase
- TaskJuggler::Log
- TaskJuggler::LogicalAttribute
- TaskJuggler::LogicalExpression
- TaskJuggler::LogicalExpressionAttribute
- TaskJuggler::LogicalExpressionListAttribute
- TaskJuggler::LogicalFlag
- TaskJuggler::LogicalFunction
- TaskJuggler::LogicalOperation
- TaskJuggler::ManagerResponsibilities
- TaskJuggler::ManagerStatusRecord
- TaskJuggler::Message
- TaskJuggler::MessageHandler
- TaskJuggler::MessageHandlerInstance
- TaskJuggler::MspXmlRE
- TaskJuggler::Navigator
- TaskJuggler::NavigatorElement
- TaskJuggler::NikuProject
- TaskJuggler::NikuReport
- TaskJuggler::NikuResource
- TaskJuggler::NodeListAttribute
- TaskJuggler::PTNProxy
- TaskJuggler::Painter
- TaskJuggler::Painter::Circle
- TaskJuggler::Painter::Color
- TaskJuggler::Painter::Element
- TaskJuggler::Painter::Ellipse
- TaskJuggler::Painter::FontMetrics
- TaskJuggler::Painter::FontMetricsData
- TaskJuggler::Painter::Group
- TaskJuggler::Painter::Line
- TaskJuggler::Painter::Points
- TaskJuggler::Painter::PolyLine
- TaskJuggler::Painter::Primitives
- TaskJuggler::Painter::Rect
- TaskJuggler::Painter::SVGSupport
- TaskJuggler::Painter::Text
- TaskJuggler::PlaceHolderCell
- TaskJuggler::ProcessIntercom
- TaskJuggler::ProcessIntercomIface
- TaskJuggler::Project
- TaskJuggler::ProjectBroker
- TaskJuggler::ProjectBrokerIface
- TaskJuggler::ProjectFileParser
- TaskJuggler::ProjectFileScanner
- TaskJuggler::ProjectRecord
- TaskJuggler::ProjectServer
- TaskJuggler::ProjectServerIface
- TaskJuggler::PropertyAttribute
- TaskJuggler::PropertyList
- TaskJuggler::PropertySet
- TaskJuggler::PropertyTreeNode
- TaskJuggler::Query
- TaskJuggler::RTFHandlers
- TaskJuggler::RTFNavigator
- TaskJuggler::RTFQuery
- TaskJuggler::RTFReport
- TaskJuggler::RTFReportLink
- TaskJuggler::RTFWithQuerySupport
- TaskJuggler::RealFormat
- TaskJuggler::RealFormatAttribute
- TaskJuggler::ReferenceAttribute
- TaskJuggler::Report
- TaskJuggler::ReportBase
- TaskJuggler::ReportContext
- TaskJuggler::ReportScenario
- TaskJuggler::ReportServer
- TaskJuggler::ReportServerIface
- TaskJuggler::ReportServerRecord
- TaskJuggler::ReportServlet
- TaskJuggler::ReportTable
- TaskJuggler::ReportTableCell
- TaskJuggler::ReportTableColumn
- TaskJuggler::ReportTableLegend
- TaskJuggler::ReportTableLine
- TaskJuggler::Resource
- TaskJuggler::ResourceListAttribute
- TaskJuggler::ResourceListRE
- TaskJuggler::ResourceScenario
- TaskJuggler::RichText
- TaskJuggler::RichTextAttribute
- TaskJuggler::RichTextDocument
- TaskJuggler::RichTextElement
- TaskJuggler::RichTextFunctionExample
- TaskJuggler::RichTextFunctionHandler
- TaskJuggler::RichTextImage
- TaskJuggler::RichTextIntermediate
- TaskJuggler::RichTextParser
- TaskJuggler::RichTextScanner
- TaskJuggler::RichTextSnip
- TaskJuggler::RichTextSyntaxRules
- TaskJuggler::Scenario
- TaskJuggler::ScenarioData
- TaskJuggler::ScenarioListAttribute
- TaskJuggler::Scoreboard
- TaskJuggler::ScoreboardInterval
- TaskJuggler::SheetHandlerBase
- TaskJuggler::SheetReceiver
- TaskJuggler::SheetSender
- TaskJuggler::Shift
- TaskJuggler::ShiftAssignment
- TaskJuggler::ShiftAssignments
- TaskJuggler::ShiftAssignmentsAttribute
- TaskJuggler::ShiftScenario
- TaskJuggler::SimpleQueryExpander
- TaskJuggler::SortListAttribute
- TaskJuggler::StatusSheetReceiver
- TaskJuggler::StatusSheetReport
- TaskJuggler::StatusSheetSender
- TaskJuggler::StdIoWrapper
- TaskJuggler::StringAttribute
- TaskJuggler::SymbolAttribute
- TaskJuggler::SymbolListAttribute
- TaskJuggler::SyntaxReference
- TaskJuggler::TOCEntry
- TaskJuggler::TSResourceRecord
- TaskJuggler::TSTaskRecord
- TaskJuggler::TableColumnDefinition
- TaskJuggler::TableColumnSorter
- TaskJuggler::TableOfContents
- TaskJuggler::TableReport
- TaskJuggler::TableReportColumn
- TaskJuggler::TagFile
- TaskJuggler::TagFile::TagFileEntry
- TaskJuggler::Task
- TaskJuggler::TaskDepListAttribute
- TaskJuggler::TaskDependency
- TaskJuggler::TaskListAttribute
- TaskJuggler::TaskListRE
- TaskJuggler::TaskScenario
- TaskJuggler::TernarySearchTree
- TaskJuggler::TextFormatter
- TaskJuggler::TextParser
- TaskJuggler::TextParser::Macro
- TaskJuggler::TextParser::MacroTable
- TaskJuggler::TextParser::Pattern
- TaskJuggler::TextParser::Rule
- TaskJuggler::TextParser::Scanner
- TaskJuggler::TextParser::Scanner::BufferStreamHandle
- TaskJuggler::TextParser::Scanner::FileStreamHandle
- TaskJuggler::TextParser::Scanner::MacroStackEntry
- TaskJuggler::TextParser::Scanner::StreamHandle
- TaskJuggler::TextParser::SourceFileInfo
- TaskJuggler::TextParser::StackElement
- TaskJuggler::TextParser::State
- TaskJuggler::TextParser::StateTransition
- TaskJuggler::TextParser::TextParserResultArray
- TaskJuggler::TextParser::TokenDoc
- TaskJuggler::TextReport
- TaskJuggler::TimeInterval
- TaskJuggler::TimeIntervalListAttribute
- TaskJuggler::TimeSheet
- TaskJuggler::TimeSheetReceiver
- TaskJuggler::TimeSheetRecord
- TaskJuggler::TimeSheetReport
- TaskJuggler::TimeSheetSender
- TaskJuggler::TimeSheetSummary
- TaskJuggler::TimeSheets
- TaskJuggler::Tj3
- TaskJuggler::Tj3AppBase
- TaskJuggler::Tj3Client
- TaskJuggler::Tj3Daemon
- TaskJuggler::Tj3Man
- TaskJuggler::Tj3SheetAppBase
- TaskJuggler::Tj3SsReceiver
- TaskJuggler::Tj3SsSender
- TaskJuggler::Tj3TsReceiver
- TaskJuggler::Tj3TsSender
- TaskJuggler::Tj3TsSummary
- TaskJuggler::Tj3WebD
- TaskJuggler::TjException
- TaskJuggler::TjRuntimeError
- TaskJuggler::TjTime
- TaskJuggler::TjpExample
- TaskJuggler::TjpExportRE
- TaskJuggler::TjpSyntaxRules
- TaskJuggler::TraceReport
- TaskJuggler::URLParameter
- TaskJuggler::UserManual
- TaskJuggler::VimSyntax
- TaskJuggler::WebServer
- TaskJuggler::WelcomePage
- TaskJuggler::WorkingHours
- TaskJuggler::WorkingHoursAttribute
- TaskJuggler::XMLBlob
- TaskJuggler::XMLComment
- TaskJuggler::XMLDocument
- TaskJuggler::XMLElement
- TaskJuggler::XMLNamedText
- TaskJuggler::XMLText
- Diff
- Diff::Hunk
- AppConfig
- Diffable
- DiffableString
- Object
- RuntimeConfig
- String

No matching classes.

# TaskJuggler::SheetHandlerBase

### Attributes

dryRun[RW]
workingDir[RW]

### Public Class Methods

new(appName) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 23
    def initialize(appName)
      @appName = appName
      # User specific settings
      @emailDeliveryMethod = 'smtp'
      @smtpServer = nil
      @senderEmail = nil
      @workingDir = nil
      @scmCommand = nil
      # The default project ID
      @projectId = 'prj'

      # Controls the amount of output that is sent to the terminal.
      # 0: No output
      # 1: only errors
      # 2: errors and warnings
      # 3: All messages
      @outputLevel = 2
      # Controls the amount of information that is added to the log file. The
      # levels are identical to @outputLevel.
      @logLevel = 3
      # Set to true to not send any emails. Instead the email (header + body) is
      # printed to the terminal.
      @dryRun = false

      @logFile = 'timesheets.log'
      @emailFailure = false
    end

### Public Instance Methods

addToScm(message, fileName) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 107
    def addToScm(message, fileName)
      return unless @scmCommand

      cmd = @scmCommand.gsub(/%m/, message)
      cmd.gsub!(/%f/, fileName)
      unless @dryRun
        `#{cmd}`
        if $? == 0
          info("Added #{fileName} to SCM")
        else
          error("SCM command #{cmd} failed: #{$?.class}")
        end
      end
    end

cutOut(text) click to toggle source

Extract the text between the cut-marker lines and remove any email quotes from the beginnin of the line.

    # File lib/taskjuggler/SheetHandlerBase.rb, line 53
    def cutOut(text)
      # Pattern for the section start marker
      mark1 = /(.*)# --------8<--------8<--------/
      # Pattern for the section end marker
      mark2 = /# -------->8-------->8--------/
      # The cutOut section
      cutOutText = nil
      quoteLen = 0
      quoteMarks = emptyLine = ''
      text.each_line do |line|
        if cutOutText.nil?
          # We are looking for the line with the start marker (mark1)
          if (matches = mark1.match(line))
            quoteMarks = matches[1]
            quoteLen = quoteMarks.length
            # Special case for quoted empty lines without trailing spaces.
            emptyLine = quoteMarks.chomp.chomp(' ') + "\n"
            cutOutText = line[quoteLen..-1]
          end
        else
          # Remove quote marks from the beginning of the line.
          line = line[quoteLen..-1] if line[0, quoteLen] == quoteMarks
          line = "\n" if line == emptyLine

          cutOutText << line
          # We are gathering text until we hit the end marker (mark2)
          return cutOutText if mark2.match(line)
        end
      end

      # There are no cut markers. We just return the original text.
      text
    end

error(message) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 132
    def error(message)
      $stderr.puts message if @outputLevel >= 1
      log("ERROR", message) if @logLevel >= 1
      raise TjRuntimeError
    end

htmlMailBody(message) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 238
    def htmlMailBody(message)
      html = HTMLDocument.new
      head = html.generateHead("TaskJuggler Report - #{@name}",
                               'description' => 'TaskJuggler Report',
                               'keywords' => 'taskjuggler, project, management')

      auxSrcDir = AppConfig.dataDirs('data/css')[0]
      cssFileName = (auxSrcDir ? auxSrcDir + '/tjreport.css' : '')
      # Raise an error if we haven't found the data directory
      if auxSrcDir.nil? || !File.exists?(cssFileName)
        dataDirError(cssFileName)
      end
      cssFile = IO.read(cssFileName)
      if cssFile.empty?
        raise TjException.new, Cannot read '#{cssFileName}'. Make sure the file is not empty and you haveread access permission.
      end
      head << XMLElement.new('meta', 'http-equiv' => 'Content-Style-Type',
                             'content' => 'text/css; charset=utf-8')
      head << (style = XMLElement.new('style', 'type' => 'text/css'))
      style << XMLBlob.new("\n" + cssFile)

      html.html << (body = XMLElement.new('body'))
      body << message.to_html

      html.to_s
    end

info(message) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 122
    def info(message)
      puts message if @outputLevel >= 3
      log('INFO', message) if @logLevel >= 3
    end

log(type, message) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 138
    def log(type, message)
      timeStamp = Time.new.strftime("%Y-%m-%d %H:%M:%S")
      File.open(@logFile, 'a') do |f|
        f.write("#{timeStamp} #{type} #{@appName}: #{message}\n")
      end
    end

sendEmail(to, subject, message, attachment = nil, from = nil, inReplyTo = nil) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 163
    def sendEmail(to, subject, message, attachment = nil, from = nil,
                  inReplyTo = nil)
      case @emailDeliveryMethod
      when 'smtp'
        Mail.defaults do
          delivery_method :smtp, {
            :address => @smtpServer,
            :port => 25
          }
        end
      when 'sendmail'
        Mail.defaults do
          delivery_method :sendmail
        end
      else
        raise "Unknown email delivery method: #{@emailDeliveryMethod}"
      end

      begin
        self_ = self
        mail = Mail.new do
          subject subject
          text_part do
            content_type [ 'text', 'plain', { 'charset' => 'UTF-8' } ]
            content_transfer_encoding 'base64'
            body message.to_s.to_base64
          end
          if message.is_a?(RichTextIntermediate)
            html_part do
              content_type 'text/html; charset=UTF-8'
              content_transfer_encoding 'base64'
              body self_.htmlMailBody(message).to_base64
            end
          end
        end
        mail.to = to
        mail.from = from || @senderEmail
        mail.in_reply_to = inReplyTo if inReplyTo
        mail['User-Agent'] = "#{AppConfig.softwareName}/#{AppConfig.version}"
        mail['X-TaskJuggler'] = @appName
        if attachment
          mail.add_file ({
            :filename => File.basename(attachment),
            :content => File.read(attachment)
          })
        end
        #raise "Mail header problem" unless mail.errors.empty?
      rescue
        @emailFailure = true
        error("Email processing failed: #{$!}")
      end

      if @dryRun
        # For testing and debugging, we only print out the email.
        puts "-- Email Start #{'-' * 60}\n#{mail.to_s}-- Email End #{'-' * 62}"
        log('INFO', "Show email '#{subject}' to #{to}")
      else
        # Actually send out the email.
        begin
          mail.deliver
        rescue
          # We try to send out another email. If that fails again, we abort
          # without further attempts.
          if @emailFailure
            log('ERROR', "Email double fault: #{$!}")
            raise TjRuntimeError
          else
            @emailFailure = true
            error("Email transmission failed: #{$!}")
          end
        end
        log('INFO', "Sent email '#{subject}' to #{to}")
      end
    end

sendRichTextEmail(to, subject, message, attachment = nil, from = nil, inReplyTo = nil) click to toggle source

Like SheetHandlerBase::sendEmail but interpretes the message as RichText markup. The generated mail will have a text/plain and a text/html part.

    # File lib/taskjuggler/SheetHandlerBase.rb, line 148
    def sendRichTextEmail(to, subject, message, attachment = nil, from = nil,
                          inReplyTo = nil)
      rti = RichText.new(message).generateIntermediateFormat
      rti.lineWidth = 72
      rti.indent = 2
      rti.titleIndent = 0
      rti.listIndent = 2
      rti.parIndent = 2
      rti.preIndent = 4
      rti.sectionNumbers = false

      # Send out the email.
      sendEmail(to, subject, rti, attachment, from, inReplyTo)
    end

setWorkingDir() click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 87
    def setWorkingDir
      # Make sure the user has provided a properly setup config file.
      case @emailDeliveryMethod
      when 'smtp'
        error('\smtpServer\ not configured') unless @smtpServer
      when 'sendmail'
        # nothing to check
      else
        error("Unknown emailDeliveryMethod #{@emailDeliveryMethod}")
      end
      error('\senderEmail\ not configured') unless @senderEmail

      # Change into the specified working directory
      begin
        Dir.chdir(@workingDir) if @workingDir
      rescue
        error("Working directory #{@workingDir} not found")
      end
    end

warning(message) click to toggle source

    # File lib/taskjuggler/SheetHandlerBase.rb, line 127
    def warning(message)
      puts message if @outputLevel >= 2
      log('WARN', message) if @logLevel >= 2
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.