lib/tj3client.rb in taskjuggler-0.0.8 vs lib/tj3client.rb in taskjuggler-0.0.9

- old
+ new

@@ -1,11 +1,12 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = tj3client.rb -- The TaskJuggler III Project Management Software # -# Copyright (c) 2006, 2007, 2008, 2009, 2010 by Chris Schlaeger <cs@kde.org> +# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 +# by Chris Schlaeger <chris@linux.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # @@ -41,10 +42,12 @@ # This must must be changed for the communication to work. @authKey = nil # Determines whether report IDs are fix IDs or regular expressions that # match a set of reports. @regExpMode = false + # List of requested output formats for reports. + @formats = nil @mandatoryArgs = '<command> [arg1 arg2 ...]' # This list describes the supported command line commands and their # parameter. @@ -129,14 +132,23 @@ format('If the port is 0, use this file to get the URI ' + 'of the server.')) do |arg| @uriFile = arg end @opts.on('-r', '--regexp', - format('The report IDs are not fixed but regular expressions ' + - 'that match a set of reports')) do |arg| + format('The report IDs are not fixed but regular expressions ' + + 'that match a set of reports')) do |arg| @regExpMode = true end + @opts.on('--format [FORMAT]', [ :csv, :html, :niku, :tjp ], + format('Request the report to be generated in the specified' + + 'format. Use multiple options to request multiple ' + + 'formats. Supported formats are csv, html, niku and ' + + 'tjp. By default, the formats specified in the report ' + + 'definition are used.')) do |arg| + @formats = [] unless @formats + @formats << arg + end end end def main args = super @@ -247,20 +259,13 @@ $stdout.puts callDaemon(:status, []) when 'terminate' callDaemon(:stop, []) info('Daemon terminated') when 'add' - # Ask the daemon to create a new ProjectServer process and return a - # DRbObject to access it. - connectToProjectServer - # Ask the server to load the files in _args_ into the ProjectServer. - begin - res = @projectServer.loadProject(@ps_authKey, [ Dir.getwd, *args ]) - rescue - error("Loading of project failed: #{$!}") - end - disconnectProjectServer + res = callDaemon(:addProject, [ Dir.getwd, args, + $stdout, $stderr, $stdin, @silent ]) + info("Project(s) #{args.join(', ')} added") return res ? 0 : 1 when 'remove' args.each do |arg| unless callDaemon(:removeProject, arg) error("Project '#{arg}' not found in list") @@ -287,11 +292,11 @@ failed = !addFiles(tjiFiles) # Ask the ReportServer to generate the reports with the provided IDs. unless failed reportIds.each do |reportId| unless @reportServer.generateReport(@rs_authKey, reportId, - @regExpMode, nil) + @regExpMode, @formats, nil) failed = true break end end end @@ -346,31 +351,9 @@ return res ? 0 : 1 else raise "Unknown command #{command}" end 0 - end - - def connectToProjectServer - @ps_uri, @ps_authKey = callDaemon(:addProject, []) - begin - @projectServer = DRbObject.new(nil, @ps_uri) - rescue - error("Can't get ProjectServer object: #{$!}") - end - begin - @projectServer.connect(@ps_authKey, $stdout, $stderr, $stdin, @silent) - rescue - error("Can't connect IO: #{$!}") - end - end - - def disconnectProjectServer - begin - @projectServer.disconnect(@ps_authKey) - rescue - error("Can't disconnect IO: #{$!}") - end end def connectToReportServer(projectId) @ps_uri, @ps_authKey = callDaemon(:getProject, projectId) if @ps_uri.nil?