-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_task.py
More file actions
56 lines (41 loc) · 1.48 KB
/
Copy pathmod_task.py
File metadata and controls
56 lines (41 loc) · 1.48 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
import sys
import tacticenv
from pyasm.biz import Project
from pyasm.security import Batch
from pyasm.command import Command
from pyasm.search import Search
class ModTaskCmd(Command):
def get_title(my):
''' this is just for show for now'''
return "Mod Task"
def execute(my):
my.add_description("Set task's context to match process if empty")
search = Search('sthpw/task')
search.add_filter('context', None)
tasks = search.get_sobjects()
if tasks and len(tasks) > 700:
print "More than 700 tasks are found. Exiting as a precaution."
sys.exit(0)
if not tasks:
print "All tasks have context attribute filled in. Exiting."
sys.exit(0)
ctr = 0
for task in tasks:
context = task.get_value('context')
process = task.get_value('process')
search_type = task.get_value('search_type')
# delete dangling task
if not search_type:
task.delete()
continue
if not context and process:
task.set_value('context', process)
task.commit(triggers=False)
ctr += 1
print "%s tasks have been processed. Their context are matched with their process." %ctr
if __name__ == '__main__':
my_login = 'admin'
batch = Batch(login_code=my_login)
Project.set_project('admin')
command = ModTaskCmd()
Command.execute_cmd(command)