-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheos.py
200 lines (162 loc) · 6.06 KB
/
eos.py
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
191
192
193
194
195
196
197
198
199
200
# coding:utf-8
import httplib
import logging
import optparse
import urllib
from util import inputUtil, authUtil, svn
__author__ = 'jinkerjiang'
MODULE_BOCAI_HOME = '315'
MODULE_vb2c_lottery = '166'
MODULE_PATH_PREFIX_MAP = {
# /data/eos/dev/dist
MODULE_BOCAI_HOME: '/bocai_home',
MODULE_vb2c_lottery: '/vb2c_lottery'
}
logging.basicConfig(format='%(message)s', level=logging.INFO)
def _GetOptionsParser():
"""Get the options parser."""
parser = optparse.OptionParser(__doc__)
parser.add_option('--type',
dest='type',
action='store',
choices=['pathFromCmd', 'pathFromInput', 'pathFromCmdPhp', 'pathFromInputPhp', 'fullPath'],
default='pathFromInput',
help='mission type')
parser.add_option('--fileRelativePath',
dest='fileRelativePaths',
action='append',
help='file relative path')
parser.add_option('--filePathAbs',
dest='filePathsAbs',
action='append',
help='file abs path')
parser.add_option('--subject',
dest='subject',
action='store',
help='subject')
parser.add_option('--begin',
dest='begin',
action='store',
default=1,
help='env begin')
parser.add_option('--end',
dest='end',
action='store',
default=2,
help='env end')
return parser
def add_eos_mission(module, file_relative_paths, subject, executors, middle_path=None, begin=1, end=2, filePathsAbs=[],
project_path=None):
if filePathsAbs and len(filePathsAbs) > 0:
svn.try_commit(filePathsAbs, cwd=project_path)
if module:
path_prefix = MODULE_PATH_PREFIX_MAP[module]
else:
path_prefix = ''
full_paths = []
if not middle_path:
middle_path = ''
for relPath in file_relative_paths:
path = path_prefix + middle_path + relPath
path = path.replace('\\', '/')
full_paths.append(path)
return do_eos_by_api(executors, full_paths, module, subject, begin, end)
def do_eos(executors, full_paths, module, subject, begin, end):
files = []
for path in full_paths:
files.append(module + ';' + path + ';;')
logging.info("EOS add mission task...")
body = {
'EEnv': '16',
'IsConst': '0',
'Executer': ';'.join(executors),
'ExtExecuter': '',
'Modules': module,
'Desc': '',
'Files': ','.join(files),
'Subject': subject,
'BEnv': '15',
'TapdId': '',
'Attention': '',
'PubType': ''
}
headers = {
'Connection': 'keep-alive',
'pragma': 'no-cache',
'Origin': 'http://t.ecc.com',
'Content-Type': 'application/x-www-form-urlencoded'
}
conn = httplib.HTTPConnection("t.ecc.com")
conn.request("POST", "/eos/api.ajax.php?act=addMissionTask", urllib.urlencode(body), headers)
response = conn.getresponse()
response_text = response.read()
conn.close()
res = 'ok' == response_text
logging.info("\tresult:" + str(res))
return res
def do_eos_by_api(executors, full_paths, module, subject, begin=1, end=2):
logging.info("EOS add mission task...")
body = {
'exeuser': ';'.join(executors),
'files': ','.join(full_paths),
'subject': subject,
'benv': begin,
'eenv': end,
'isexec': 'true'
}
headers = {
'Cookie': 'PHPSESSID=i6le63ru6umm55crtph0tba4i7;'
}
conn = httplib.HTTPConnection("vtools.oa.com", 80)
conn.request("POST", "/dsrm.php/eos/addMission?" + urllib.urlencode(body), "", headers)
response = conn.getresponse()
response_text = response.read()
conn.close()
res = '发布任务创建成功,请登录Eos执行。' == response_text
try:
response_text = response_text.decode('utf-8').encode('gb2312')
except Exception:
pass
logging.info(response_text)
logging.info("\tresult:" + str(res))
return res
if __name__ == "__main__":
logging.basicConfig(format='%(message)s', level=logging.info)
options, args = _GetOptionsParser().parse_args()
options_type = options.type
begin = options.begin
end = options.end
filePaths = []
subject = ''
module = MODULE_BOCAI_HOME
middlePath = ''
filePathsAbs = options.filePathsAbs
if options_type == 'pathFromCmd':
filePaths = options.fileRelativePaths
subject = options.subject
middlePath = '/html'
elif options_type == 'pathFromInput':
logging.info("Please input file relative path(multiple split by semicolon): \n")
filePaths = inputUtil.raw_input_multi_line()
subject = raw_input("Please input subject: \n").replace("\\", "/")
middlePath = '/html'
elif options_type == 'pathFromCmdPhp':
filePaths = options.fileRelativePaths
subject = options.subject
middlePath = '/web_app'
elif options_type == 'pathFromInputPhp':
logging.info("Please input file relative path(multiple split by semicolon): \n")
filePaths = inputUtil.raw_input_multi_line()
subject = raw_input("Please input subject: \n").replace("\\", "/")
middlePath = '/web_app'
else:
logging.info("Please input file relative path(multiple split by semicolon): \n")
filePaths = inputUtil.raw_input_multi_line()
subject = raw_input("Please input subject: \n").replace("\\", "/")
module = raw_input("Please input module: \n")
paths = []
for fileRelPath in filePaths:
paths.append(fileRelPath.replace("\\", "/"))
subject = subject.replace("\\", "/")
add_eos_mission(module=module, file_relative_paths=paths, subject=subject, executors=[authUtil.get_user_name()],
middle_path=middlePath, begin=begin, end=end, filePathsAbs=filePathsAbs)