通过python rally API更新"Display Name"



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

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

在以下代码片段中尝试了以拉力赛中所有用户,然后将使用 update()post()方法更改displyName的格式。

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)    

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

是否有其他方法可以更新所有用户的显示名称字段。

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

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

不确定这是否有帮助,但在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.

最新更新