-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathundo_cmd.py
More file actions
194 lines (129 loc) · 5.39 KB
/
Copy pathundo_cmd.py
File metadata and controls
194 lines (129 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ["UndoCmd", "RedoCmd"]
from pyasm.common import *
from pyasm.biz import Project
from pyasm.search import *
from command import *
class UndoCmd(Command):
def __init__(my, ignore_files=False, is_sync=True, transaction_log=None):
super(UndoCmd,my).__init__()
my.transaction_log = transaction_log
my.ignore_files = ignore_files
my.is_sync = is_sync
def get_title(my):
return "Undo"
def is_undoable(cls):
return False
is_undoable = classmethod(is_undoable)
def check(my):
return True
def set_transaction_log(my, transaction_log):
'''manually set the translation log'''
my.transaction_log = transaction_log
def set_transaction_id(my, transaction_id):
'''manually set the translation id'''
my.transaction_log = Search.get_by_id("sthpw/transaction_log", transaction_id)
if not my.transaction_log:
raise CommandException("Transaction with id [%s] does not exist" % transaction_id)
def set_transaction_code(my, transaction_code):
'''manually set the translation code'''
my.transaction_log = Search.get_by_code("sthpw/transaction_log", transaction_code)
if not my.transaction_log:
raise CommandException("Transaction with code [%s] does not exist" % transaction_code)
def execute(my):
if not my.transaction_log:
search = Search("sthpw/transaction_log")
search.add_filter("type", "undo")
# get the current project. If the project is admin, then undo
# works differently
project = Project.get_global_project_code()
assert project
search.add_filter("namespace", project)
user = Environment.get_user_name()
assert user
search.add_filter("login", user)
search.add_order_by("timestamp desc")
search.add_limit(1)
my.transaction_log = search.get_sobject()
if not my.transaction_log:
print("WARNING: No transaction log found for undo")
return CommandExitException()
my.transaction_log.undo(ignore_files=my.ignore_files)
my.transaction_log.set_value("type", "redo")
my.transaction_log.commit()
# undo triggers a special sync
# if this is a sync undo, then do not propgate remote undos
if not my.is_sync:
my.transaction_log.trigger_remote_undo()
class RedoCmd(Command):
def __init__(my,**kwargs):
super(RedoCmd,my).__init__()
my.kwargs = kwargs
my.transaction_log = my.kwargs.get("transaction_log")
my.ignore = my.kwargs.get("ignore")
if not my.ignore:
my.ignore = []
def get_title(my):
return "Redo"
def is_undoable(cls):
return False
is_undoable = classmethod(is_undoable)
def check(my):
#from pyasm.web import WebContainer
#web = WebContainer.get_web()
#if web.get_form_value("Redo") != "":
return True
def set_transaction_log(my, transaction_log):
'''manually set the translation log to undo'''
my.transaction_log = transaction_log
def get_transaction_log(my):
'''get the transaction log'''
return my.transaction_log
def set_transaction_id(my, transaction_id):
'''manually set the translation id'''
my.transaction_log = Search.get_by_id("sthpw/transaction_log", transaction_id)
if not my.transaction_log:
raise CommandException("Transaction with id [%s] does not exist" % transaction_id)
def set_transaction_code(my, transaction_code):
'''manually set the translation code'''
my.transaction_log = Search.get_by_code("sthpw/transaction_log", transaction_code)
if not my.transaction_log:
raise CommandException("Transaction with code [%s] does not exist" % transaction_code)
def execute(my):
import time
start = time.time()
security = Environment.get_security()
ticket = security.get_ticket_key()
if not my.transaction_log:
search = Search("sthpw/transaction_log")
search.add_filter("type", "redo")
# get the current project
project = Project.get_global_project_code()
search.add_filter("namespace", project)
user = Environment.get_user_name()
search.add_filter("login", user)
search.add_order_by("timestamp")
search.add_limit(1)
my.transaction_log = search.get_sobject()
if not my.transaction_log:
return CommandExitException()
base_dir = my.kwargs.get("base_dir")
my.transaction_log.redo(ignore=my.ignore, base_dir=base_dir)
my.transaction_log.set_value("type", "undo")
my.transaction_log.commit()
# get the transaction
transaction = Transaction.get()
# update the change timestamps
transaction.update_change_timestamps(my.transaction_log)
print "RedoCmd: ", time.time() - start
print