defaultclient.rb

Path: defaultclient.rb
Last Update: Fri Nov 19 17:20:25 GMT 2004

Introduction

      This script ensures that the default client view offered to users
      for new client workspaces is based on a template client specified
      in the trigger definition.

Synopsis

      defaultclient.rb <templatename> <clientname> <formfile>

Sample Trigger Definition

      Using a trigger spec like this:

 defaultclient out client "defaultclient.rb baseclient %formname% %formfile%"

      would make the default client view offered to any user based on
      the view defined in the client called 'baseclient'. Changing that
      client spec would change the default view.

Required files

P4  

Methods

Public Instance methods

Check whether or not a client already exists.

[Source]

    # File defaultclient.rb, line 59
59: def client_exists?( p4, name )
60:     p4.run_clients.each do
61:         |c|
62:         if( c[ "client" ] == name )
63:             return true
64:         end
65:     end
66:     return false
67: end

Show a message explaining correct usage of this script and exit.

[Source]

    # File defaultclient.rb, line 34
34: def croakusage()
35:     puts "\nUsage: defaultclient.rb <templatename> <clientname> <formfile>\n\nWhere:\n    <templatename>             - the name of an existing client workspace \n                                 on which all future client workspaces \n                                 should be based (by default).\n\n    <clientname>               - The name of the client spec the user's \n                                 asking for\n\n    <formfile>                 - The name of the temporary file in which the\n                                 current client spec is stored\n\n"
36:     exit( 1 )
37: end

Load the skeleton spec from the formfile

[Source]

    # File defaultclient.rb, line 72
72: def load_spec( formfile )
73:     f = File.open( formfile, "r" )
74:     buf = f.read
75:     f.close
76:     buf
77: end

Update the existing formfile with a new spec. Since the comments that appear at the top of a spec file are quite useful to the users, we preserve them and only update the end of the file with the new spec.

[Source]

     # File defaultclient.rb, line 85
 85: def write_spec( spec, formfile )
 86:     comments = ""
 87:     File.open( formfile, "r" ) do
 88:         |f|
 89:         f.each_line do
 90:             |line|
 91:             if( line[0...1] != '#' )
 92:                 break
 93:             end
 94:             comments += line
 95:         end
 96:     end
 97:     comments += "\n" 
 98: 
 99:     File.open( formfile, "w" ) do
100:         |f|
101:         f.write( comments )
102:         f.write( spec )
103:     end
104: end

[Validate]