1

为了唯一标识 Rally 中的用户,我们要更新用户的显示名称字段,以便可以识别 2 个同名的人。

e.g. John D(johnd@test.com)
     John G(johng@test.com)

尝试下面的代码片段以获取 Rally 中的所有用户,然后将使用update()ORpost()方法更改显示名称为上述格式。

import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args    = [arg for arg in sys.argv[1:] if arg not in options]
server = "rally1.rallydev.com"
apikey = "<rally_api_key>"
workspace = "<myworkspace>"
#project = "<myproject>"
rally = Rally(server,apikey=apikey, workspace=workspace)
rally.enableLogging('mypyral.log')

all_users = rally.getAllUsers()
for user in all_users:
    tz   = user.UserProfile.TimeZone or 'default'
    role = user.Role or '-No Role-'
    values = (int(user.oid), user.Name, user.UserName, role, tz)
    print("%12.12d %-24.24s %-30.30s %-12.12s" % values)    

不提供任何输出 - 逻辑变成无限循环

是否有任何替代方法来更新所有用户的显示名称字段。

4

2 回答 2

0

不确定这是否有帮助,但它适用于 Ruby:

$ cat -n Print-All-Users-short.rb 
 1  #!/usr/bin/env ruby
 2  $my_base_url    = 'http://rally1.rallydev.com'
 3  $my_username    = 'Secret'
 4  $my_password    = 'MoreSecret'
 5  $my_workspace   = 'Integrations'
 6  
 7  require './MyVars.rb' if FileTest.exist?( './MyVars.rb' )
 8  require 'rally_api'
 9  
10  @rallycon = RallyAPI::RallyRestJson.new({
11          :base_url       => $my_base_url,
12          :username       => $my_username,
13          :password       => $my_password,
14          :workspace      => $my_workspace,
15          :version        => 'v2.0',
16          :headers        => RallyAPI::CustomHttpHeader.new(:name=>'Print-All-Users-short.rb', :vendor=>'MySelf', :version=>'3.14159')
17          })
18  
19  all_users = @rallycon.find(RallyAPI::RallyQuery.new(
20                  :type           => :user,
21                  :query_string   => "(ObjectID > 0)",
22                  :fetch          => true))
23  
24  if all_users.count < 1 then     # Did we find too few?
25      print "ERROR: Query returned nothing.\n"
26      exit (-1)
27  end
28  print "Query returned #{all_users.count} users.\n"

$ ./Print-All-Users-short.rb
Query returned 109 users.
于 2017-02-27T20:45:30.613 回答
0

我能够使用以下代码更新显示名称字段。

require 'rally_api'
#require 'rally_user_management'
require 'csv'
require './lib/go_update_user_attributes.rb'

$input_filename_arg = ARGV[0]

if $input_filename_arg == nil
# This is the default of the file to be used for uploading user permissions
  $input_filename             = 'update_user_attributes_template.txt'
else
  $input_filename = File.dirname(__FILE__) + "/" + $input_filename_arg
end

begin
  go_update_user_attributes($input_filename)
end

您唯一需要确保的是作为参数提供的输入文件应该是文本文件,而不是 CSV、Excel 等。您的输入文件 - update_user_attributes_template.txt

UserID  LastName    FirstName   DisplayName Role    OfficeLocation  Department  CostCenter  Phone   NetworkID   DefaultWorkspaceName    DefaultProjectName  TimeZone
testuser@cisco.com          dummy name (testuser)

$update_user_attributes.rb update_user_attributes_template.txt

于 2017-03-01T11:21:04.200 回答