Reverting Auto-Task (Python)

Reverting Auto-Task (Python)
 1# Project Revert Auto-task example
 2# This script should be assigned to either the "Revert (After)" or "Revert (Before)" auto-tasks.
 3# It will not work in the Script Toolbox as the impact.gui.active_database_revert property is only valid
 4# during a database revert operation.
 5
 6# For the "Revert (Before)" auto-task the IRevertAction object will only have Project,
 7# User and OldRevision properties. The OldRevision is the revision being Reverted To or
 8# being Made Current.
 9
10# The "Revert (Before)" may be cancelled by setting IDatabase.accept_auto_task = False
11
12# For the "Revert (After)" auto-task the IRevertAction object will also have
13# a NewRevision property to the IDatabaseRevision of the new revision.
14# For a Revert To the OldRevision and NewRevision will be the same revision.
15# If the customer was changed as part of the revert then the OldCustomer
16# and NewCustomer properties will also be set.
17
18# All properties are read-only and cannot be modified.
19
20db = impact.active_database
21
22def DescribeRevertAction(ra):
23    impact.gui.output_toolbox.add("Project: " + ra.project.reference)
24    impact.gui.output_toolbox.add("User: " + ra.user.login_id)
25
26    if ra.action == ipRevertAction.raRevert:
27        impact.gui.output_toolbox.add("Action: Reverting")
28    else:
29        impact.gui.output_toolbox.add("Action: Making Current")
30
31    impact.gui.output_toolbox.add("OldRevision: " + ra.old_revision.number)
32
33    if not ra.new_revision.isNone():
34        impact.gui.output_toolbox.add("NewRevision: " + ra.new_revision.number)
35        impact.gui.output_toolbox.add("  Comments: " + ra.new_revision.comments)
36
37    if (not ra.old_customer.isNone()) and (not ra.new_customer.isNone()):
38        impact.gui.output_toolbox.add("OldCustomer: " + ra.old_customer.full_name)
39        impact.gui.output_toolbox.add("NewCustomer: " + ra.new_customer.full_name)
40
41    # When assigned to "Revert (Before)" - revert may be cancelled using AcceptAutoTask
42    # Make sure you inform the user why they cannot revert
43    # MsgBox "You cannot revert this revision"
44    # db.accept_auto_task = False
45
46ra = impact.gui.active_database_revert
47
48if not ra.isNone():
49
50    DescribeRevertAction(ra)
51
52else:
53
54    impact.gui.output_toolbox.add("Error: ActiveDatabaseRevert is not valid")