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
# -*- coding: utf-8 -*-
import sys
from ZODB.POSException import ConflictError
from zExceptions import ExceptionFormatter
from Products.CMFActivity.ActiveResult import ActiveResult
from Products.ERP5Type.Document import newTempOOoDocument
from zLOG import LOG, INFO
def dumpWorkflowChain(self):
# This method outputs the workflow chain in the format that you can
# easily get diff like the following:
# ---
# Account,account_workflow
# Account,edit_workflow
# ...
# ---
workflow_tool = self.getPortalObject().portal_workflow
cbt = workflow_tool._chains_by_type
ti = workflow_tool._listTypeInfo()
types_info = []
for t in ti:
id_ = t.getId()
title = t.Title()
if title == id_:
title = None
if cbt is not None and cbt.has_key(id_):
chain = sorted(cbt[id_])
else:
chain = ['(Default)']
types_info.append({'id': id_,
'title': title,
'chain': chain})
output = []
for i in sorted(types_info, key=lambda x:x['id']):
for chain in i['chain']:
output.append('%s,%s' % (i['id'], chain))
return '\n'.join(output)
def checkFolderHandler(self, fixit=0, **kw):
error_list = []
try:
is_btree = self.isBTree()
is_hbtree = self.isHBTree()
except AttributeError:
return error_list
message = '%s' % self.absolute_url_path()
problem = False
if not is_btree and not is_hbtree:
problem = True
message = '%s is NOT BTree NOR HBTree' % message
if fixit:
try:
result = self._fixFolderHandler()
except AttributeError:
result = False
if result:
message = '%s fixed' % message
else:
message = '%s CANNOT FIX' % message
if is_btree and is_hbtree:
problem = True
message = '%s is BTree and HBTree' % message
if fixit:
message = '%s CANNOT FIX' % message
if problem:
error_list.append(message)
LOG('checkFolderHandler', INFO, message)
return error_list
def MessageCatalog_getMessageDict(self):
"""
Get Localizer's MessageCatalog instance messages.
"""
d = {}
for k,v in self._messages.iteritems():
d[k] = v
return d
def MessageCatalog_getNotTranslatedMessageDict(self):
"""
Get Localizer's MessageCatalog instance messages that are NOT translated.
"""
not_translated_message_dict = {}
messages = MessageCatalog_getMessageDict(self)
for k,v in messages.iteritems():
if not len(v) or not len(filter(lambda x:x, v.values())):
not_translated_message_dict[k] = v
return not_translated_message_dict
def MessageCatalog_deleteNotTranslatedMessageDict(self):
"""
Delete from Localizer's MessageCatalog instance messages that are NOT translated.
"""
not_translated_message_dict = MessageCatalog_getNotTranslatedMessageDict(self)
for k,_ in not_translated_message_dict.iteritems():
# delete message from dict
del(self._messages[k])
return len(not_translated_message_dict.keys())
def checkConversionToolAvailability(self):
"""
Check conversion tool (oood) is available for erp5.
This script convert an odt document into HTML and try to read
the returned string and find out expected string
"""
portal = self.getPortalObject()
document_id = 'P-ERP5-TEST.Conversion.Tool.Availability-001-en.odt'
document_path = 'portal_skins/erp5_administration/%s' % (document_id,)
document_file = portal.restrictedTraverse(document_path)
message = None
severity = 0
try:
temp_document = newTempOOoDocument(self, document_id, data=document_file.data, source_reference=document_id)
temp_document.convertToBaseFormat()
_, html_result = temp_document.convert(format='html')
except ConflictError:
raise
except: #Which Errors should we catch ?
#Transformation failed
message = 'Conversion tool got unexpected error:\n%s' % ''.join(ExceptionFormatter.format_exception(*sys.exc_info()))
else:
#Everything goes fine, Check that expected string is present in HTML conversion
if 'AZERTYUIOPMQ' not in html_result:
message = 'Conversion to HTML Failed:\n%s' % (html_result,)
active_process = self.newActiveProcess()
result = ActiveResult()
if message:
severity = 1
result.edit(detail=message)
result.edit(severity=severity)
active_process.activateResult(result)
from Products.ERP5Type.Utils import checkPythonSourceCode
def checkPythonSourceCodeAsJSON(self, data):
"""
Check Python source suitable for Ace Editor and return a JSON object
"""
import json
# XXX data is encoded as json, because jQuery serialize lists as []
if isinstance(data, basestring):
data = json.loads(data)
# data contains the code, the bound names and the script params. From this
# we reconstruct a function that can be checked
def indent(text):
return ''.join((" " + line) for line in text.splitlines(True))
is_python_script = 'bound_names' in data
if is_python_script:
signature_parts = data['bound_names']
if data['params']:
signature_parts += [data['params']]
signature = ", ".join(signature_parts)
function_name = "function_name"
body = "def %s(%s):\n%s" % (function_name,
signature,
indent(data['code']) or " pass")
else:
body = data['code']
message_list = checkPythonSourceCode(body)
for message_dict in message_list:
if is_python_script:
message_dict['row'] = message_dict['row'] - 2
else:
message_dict['row'] = message_dict['row'] - 1
if message_dict['type'] in ('E', 'F'):
message_dict['type'] = 'error'
else:
message_dict['type'] = 'warning'
self.REQUEST.RESPONSE.setHeader('content-type', 'application/json')
return json.dumps(dict(annotations=message_list))