class TaskJuggler::Tj3Client

The Tj3Client class provides the primary interface to the TaskJuggler daemon. It exposes a rich commandline interface that supports key operations like add/removing a project, generating a report or checking a time or status sheet. All connections are made via DRb and tj3client requires a properly configured tj3d to work.

Public Class Methods

new() click to toggle source
Calls superclass method TaskJuggler::Tj3AppBase::new
# File lib/taskjuggler/apps/Tj3Client.rb, line 33
def initialize
  super

  # For security reasons, this will probably not change. All DRb
  # operations are limited to localhost only. The client and the sever
  # must have access to the identical file system.
  @host = '127.0.0.1'
  # The default port. 'T' and 'J' in ASCII decimal
  @port = 8474
  # The file with the server URI in case port is 0.
  @uriFile = File.join(Dir.getwd, '.tj3d.uri')
  # 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
  # Prevents usage of protective sandbox if set to true.
  @unsafeMode = 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.
  # :label : The command name
  # :args : A list of parameters. If the first character is a '+' the
  # parameter must be provided 1 or more times. If the first character is
  # a '*' the parameter must be provided 0 or more times. Repeatable and
  # optional paramters must follow the mandatory ones.
  # :descr : A short description of the command used for the help text.
  @commands = [
    { :label => 'status',
      :args  => [],
      :descr => 'Display the status of the available projects' },
    { :label => 'terminate',
      :args  => [],
      :descr => 'Terminate the TaskJuggler daemon' },
    { :label => 'add',
      :args  => [ 'tjp file', '*tji file'],
      :descr => 'Add a new project or update and existing one' },
    { :label => 'update',
      :args => [],
      :descr => 'Reload all projects that have modified files and '+
                'are not being reloaded already' },
    { :label => 'remove',
      :args  => [ '+project ID' ],
      :descr => 'Remove the project with the specified ID from the ' +
                'daemon' },
    { :label => 'report',
      :args  => [ 'project ID', '+report ID', '!=', '*tji file'],
      :descr => 'Generate the report with the provided ID for ' +
                'the project with the given ID'},
    { :label => 'list-reports',
      :args  => [ 'project ID', '!report ID' ],
      :descr => 'List all available reports of the project or those ' +
                'that match the provided report ID' },
    { :label => 'check-ts',
      :args  => [ 'project ID', 'time sheet' ],
      :descr => 'Check the provided time sheet for correctness ' +
                'against the project with the given ID'},
    { :label => 'check-ss',
      :args  => [ 'project ID', 'status sheet' ],
      :descr => 'Check the provided status sheet for correctness ' +
                'against the project with the given ID'}
  ]
end

Public Instance Methods

appMain(args) click to toggle source
# File lib/taskjuggler/apps/Tj3Client.rb, line 165
def appMain(args)
  # Run a first check of the non-optional command line arguments.
  checkCommand(args)
  # Read some configuration variables. Except for the authKey, they are
  # all optional.
  @rc.configure(self, 'global')

  @broker = connectDaemon
  retVal = executeCommand(args[0], args[1..-1])
  disconnectDaemon
  @broker = nil

  retVal
end
processArguments(argv) click to toggle source
# File lib/taskjuggler/apps/Tj3Client.rb, line 101
    def processArguments(argv)
      super do
        prebanner = <<'EOT'
The TaskJuggler client is used to send commands and data to the TaskJuggler
daemon. The communication is done via TCP/IP.

The following commands are supported:

EOT

        # Convert the command list into a help text.
        @commands.each do |cmd|
          tail = ''
          args = cmd[:args].dup
          args.map! do |c|
            if c[0] == '*'
              "[<#{c[1..-1]}> ...]"
            elsif c[0] == '+'
              "<#{c[1..-1]}> [<#{c[1..-1]}> ...]"
            elsif c[0] == '!'
              tail += ']'
              "[#{c[1..-1]} "
            else
              "<#{c}>"
            end
          end
          args = args.join(' ')
          prebanner += "     #{cmd[:label] + ' ' + args + tail}" +
                          "\n\n#{' ' * 10 + format(cmd[:descr], 10)}\n"
        end
        @opts.banner.prepend(prebanner)
        @opts.on('-p', '--port <NUMBER>', Integer,
                 format('Use the specified TCP/IP port')) do |arg|
           @port = arg
        end
        @opts.on('--urifile <FILE>', String,
                 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|
          @regExpMode = true
        end
        @opts.on('--unsafe',
                 format('Run the program without sandbox protection. This ' +
                        'is not recommended for normal operation! It may ' +
                        'only be used for debugging or testing ' +
                        'purposes.')) do |arg|
          @unsafeMode = true
        end
        @opts.on('--format [FORMAT]', [ :csv, :html, :mspxml, :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