在Rally中替换模板故事的字符串

2024-04-18 00:27:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以用Python代码成功地获取用户故事信息;但是,我希望替换位于details和user story name中的特定字符串。例如,字符串可以是$projectName,我想用用户输入的值替换它。你知道吗

有没有什么东西可以帮助我们编写代码,或者有一个有效的例子?我被卡住了,因为这不一定是一个要编辑的文件,层次结构输出也为我创建了一个块来开发一些有用的东西。你知道吗

以下是我提取数据的代码:

#!/usr/bin/env python
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, username, password, apikey, workspace, project = rallyWorkset(options)
if apikey:
        rally = Rally(server, apikey=apikey, workspace=workspace, project=project)
else:
        rally = Rally(server, username=username, password=password, workspace=workspace, project=project)
response = rally.get ('UserStory', fetch=True, query='Name contains "$projecttest"')
for story1 in response:
    print story1.details()

这是我得到的输出,当然是擦洗过的:

HierarchicalRequirement
    oid                       : 81284473268
    ref                       : hierarchicalrequirement/81284473268
    ObjectID                  : 81284473268
    ObjectUUID                : 67c952b4-e414-4759-a8c5-d7d7543ba98d
    _ref                      : https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/81284473268
    _CreatedAt                : Dec 14, 2016
    _hydrated                 : True
    Name                      : Robert - test - pyRal - $projecttest
    Subscription              : <<SCRUBBED>>
    Workspace                 : Workspace.ref          (OID  SCRUBBED)
    FormattedID               : US47008

    AcceptedDate              : None
    Attachments               : []
    Blocked                   : False
    BlockedReason             : None
    Blocker                   : None
    Changesets                : []
    Children                  : []
    CreationDate              : 2016-12-14T18:21:03.663Z
    DefectStatus              : NONE
    Defects                   : []
    Description               : <b>Description</b><div><br /><div>Some format here</div><div><br /></div><div><b>Outcome</b></div><div><b><br /></b></div><div>Some outcome here</div></div>
    DirectChildrenCount       : 0
    Discussion                : []
    DisplayColor              : #21a2e0
    DragAndDropRank           : O~zbf~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Expedite                  : False
    Feature                   : None
    HasParent                 : False
    InProgressDate            : None
    Iteration                 : None
    LastBuild                 : None
    LastRun                   : None
    LastUpdateDate            : 2016-12-19T22:42:48.173Z
    LatestDiscussionAgeInMinutes  : None
    Milestones                : []
    Notes                     : 
    Owner                     : User.ref  (OID  SCRUBBED)
    Package                   : None
    Parent                    : None
    PassingTestCaseCount      : 0
    PlanEstimate              : None
    PortfolioItem             : None
    Predecessors              : []
    Project                   : Project.ref                 (OID  SCRUBBED)
    Ready                     : False
    Recycled                  : False
    Release                   : None
    ScheduleState             : Ungroomed
    ScheduleStatePrefix       : U
    Successors                : []
    Tags                      : []
    TaskActualTotal           : 0.0
    TaskEstimateTotal         : 0.0
    TaskRemainingTotal        : 0.0
    TaskStatus                : NONE
    Tasks                     : []
    TestCaseCount             : 0
    TestCaseStatus            : NONE
    TestCases                 : []
    VersionId                 : 4
    __collection_ref_for_RevisionHistory  : SCRUBBED
    _refObjectUUID            : SCRUBBED
    AcceptanceCriteria        : None
    IGNOREAcceptanceCriteria  : None
    IdeaURL                   : <pyral.entity.CustomField object at 0x7f1afb79a190>
    IdeaVotes                 : None
    JIRAPriority              : None
    JiraKey                   : None
    JiraLink                  : None
    KanbanState               : None
    Priority                  : None
    ReleaseNote               : None
    RequestedDate             : None
    SNRequest                 : None
    Submitter                 : None
    TestRailPlanID            : None
    TrackingState             : None

===============================================================

因此,使用PyRal,我必须向这个代码获取的每个用户故事发送一个更新,只在包含字符串的行上发送;然而,我必须以某种方式存储每个FormattedID:和关联的Name:字段以进行更新,这就是我被困在的地方,关于如何实际存储它以便可以迭代和更新它。你知道吗


Tags: 字符串代码用户indivprojectnoneref
1条回答
网友
1楼 · 发布于 2024-04-18 00:27:01

您可以使用模板字符串来做您想做的事情,使用env变量来限定模板标记:

from string import Template
s = Template('this is $projectName')
s.substitute(projectName='THE_PROJECT')

结果:

'this is THE_PROJECT'

https://docs.python.org/3/library/string.html

另一种方法是,如果将projectName用大括号括起来,则使用format

s = 'this is {projectName}'
print(s.format(projectName='THE_PROJECT'))

相关问题 更多 >

    热门问题