lib/TaskJuggler.rb in taskjuggler-0.0.5 vs lib/TaskJuggler.rb in taskjuggler-0.0.6
- old
+ new
@@ -18,11 +18,11 @@
# The TaskJuggler class models the object that provides access to the
# fundamental features of the TaskJuggler software. It can read project
# files, schedule them and generate the reports.
class TaskJuggler
- attr_reader :messageHandler
+ attr_reader :project, :messageHandler
attr_accessor :maxCpuCores, :warnTsDeltas
# Create a new TaskJuggler object. _console_ is a boolean that determines
# whether or not messsages can be written to $stderr.
def initialize(console)
@@ -71,13 +71,10 @@
# the name of the file. _rule_ is the TextParser::Rule to start with.
def parseFile(fileName, rule)
@parser.open(fileName, false)
@parser.setGlobalMacros
return nil if (res = @parser.parse(rule)).nil?
- # Make sure that _rule_ described the full content of the file. There
- # should be no more content left.
- @parser.checkForEnd
@parser.close
res
end
# Schedule all scenarios in the project. Return true if no error was
@@ -92,32 +89,39 @@
end
# Generate all specified reports. The project must have be scheduled before
# this method can be called. It returns true if no error occured, false
# otherwise.
- def generateReports(outputDir)
+ def generateReports(outputDir = './')
+ outputDir += '/' unless outputDir.empty? || outputDir[-1] == '/'
@project.outputDir = outputDir
Log.enter('reports', 'Generating reports ...')
res = @project.generateReports(@maxCpuCores)
Log.exit('reports')
res
end
- # Generate the report with the ID _reportId_.
- def generateReport(reportId, regExpMode)
+ # Generate the report with the ID _reportId_. If _regExpMode_ is true,
+ # _reportId_ is interpreted as a Regular Expression and all reports with
+ # matching IDs are generated. _dynamicAtributes_ is a String that may
+ # contain attributes to supplement the report definition. The String must be
+ # in TJP format and may be nil if no additional attributes are provided.
+ def generateReport(reportId, regExpMode, dynamicAttributes = nil)
begin
Log.enter('generateReport', 'Generating report #{reportId} ...')
- @project.generateReport(reportId, regExpMode)
+ @project.generateReport(reportId, regExpMode, dynamicAttributes)
rescue TjException
Log.exit('generateReport')
return false
end
Log.exit('generateReport')
true
end
- # Generate the report with the ID _reportId_.
+ # Generate the report with the ID _reportId_. If _regExpMode_ is true,
+ # _reportId_ is interpreted as a Regular Expression and all reports with
+ # matching IDs are listed.
def listReports(reportId, regExpMode)
begin
Log.enter('listReports', 'Generating report list for #{reportId} ...')
@project.listReports(reportId, regExpMode)
rescue TjException
@@ -135,11 +139,11 @@
begin
Log.enter('checkTimeSheet', 'Parsing #{fileName} ...')
# Make sure we don't use data from old time sheets or Journal entries.
@project.timeSheets.clear
@project['journal'] = Journal.new
- return false unless (ts = parseFile(fileName, 'timeSheet'))
+ return false unless (ts = parseFile(fileName, 'timeSheetFile'))
return false unless @project.checkTimeSheets
queryAttrs = { 'project' => @project,
'property' => ts.resource,
'scopeProperty' => nil,
'scenarioIdx' => @project['trackingScenarioIdx'],
@@ -167,11 +171,11 @@
# sheet. If the sheet is syntaxtically correct and matches the loaded
# project, true is returned. Otherwise false.
def checkStatusSheet(fileName)
begin
Log.enter('checkStatusSheet', 'Parsing #{fileName} ...')
- return false unless (ss = parseFile(fileName, 'statusSheet'))
+ return false unless (ss = parseFile(fileName, 'statusSheetFile'))
queryAttrs = { 'project' => @project,
'property' => ss[0],
'scopeProperty' => nil,
'scenarioIdx' => @project['trackingScenarioIdx'],
'timeFormat' => '%Y-%m-%d',
@@ -197,9 +201,15 @@
# Return the ID of the project or nil if no project has been loaded yet.
def projectId
return nil if @project.nil?
@project['projectid']
+ end
+
+ # Return the name of the project or nil if no project has been loaded yet.
+ def projectName
+ return nil if @project.nil?
+ @project['name']
end
# Return the number of errors that had been reported during processing.
def errors
@project.messageHandler.errors