add collect object, collect table

develop
Спиридонов Денис 12 years ago
parent 6d5768335c
commit 4a138de7a0

@ -203,12 +203,12 @@ def https_server(client, args, unknown_args, url, clVarsCore):
return 1
elif args.method and args.help:
now = datetime.datetime.now()
print '6 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '6 ===> %ds %dms' %(now.second, now.microsecond)
method_parser, view = get_method_argparser(client, args)
method_parser.print_help()
now = datetime.datetime.now()
print '7 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '7 ===> %ds %dms' %(now.second, now.microsecond)
else:
try:
@ -230,15 +230,15 @@ def https_server(client, args, unknown_args, url, clVarsCore):
# signaling.start()
def main():
now = datetime.datetime.now()
print '1 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '1 ===> %ds %dms' %(now.second, now.microsecond)
parser = parse()
args, unknown_args = parser.parse_known_args()
if not args.method and args.help:
parser.print_help()
now = datetime.datetime.now()
print '1/2 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '1/2 ===> %ds %dms' %(now.second, now.microsecond)
return 0
logging.basicConfig(level=logging.FATAL)
@ -283,16 +283,16 @@ def main():
clear()
try:
now = datetime.datetime.now()
print '2 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '2 ===> %ds %dms' %(now.second, now.microsecond)
client = Client_suds(url, \
transport = HTTPSClientCertTransport(None,None, path_to_cert))
now = datetime.datetime.now()
print '2/1 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '2/1 ===> %ds %dms' %(now.second, now.microsecond)
server_host_name = client.service.get_server_host_name()
print server_host_name
now = datetime.datetime.now()
print '2/2 ===> %ds %dms' %(now.second, now.microsecond)
# print server_host_name
# now = datetime.datetime.now()
# print '2/2 ===> %ds %dms' %(now.second, now.microsecond)
del (client)
except urllib2.URLError, e:
print _('Failed to connect')+':', e
@ -310,15 +310,15 @@ def main():
fit_cert_list.append(client_cert_name)
fit_cert_list.sort(key = len)
Connect_Error = 1
now = datetime.datetime.now()
print '3 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '3 ===> %ds %dms' %(now.second, now.microsecond)
for i in range (0, len(fit_cert_list)):
#print 'fit_cert_list = ',fit_cert_list
cert_name = fit_cert_list.pop()
CERT_FILE = path_to_cert + cert_name + '.crt'
CERT_KEY = path_to_cert + cert_name + '.key'
try:
print 111111111
# print 111111111
client = Client_suds(url,\
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
path_to_cert))
@ -333,8 +333,8 @@ def main():
sys.exit(1)
if Connect_Error == 0:
break
now = datetime.datetime.now()
print '4 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '4 ===> %ds %dms' %(now.second, now.microsecond)
#If the certificate file misses
if Connect_Error:
print 'CONNECT ERROR'
@ -347,11 +347,11 @@ def main():
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
client.port = port
now = datetime.datetime.now()
print '5 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print '5 ===> %ds %dms' %(now.second, now.microsecond)
https_server(client, args, unknown_args, url, clVarsCore)
now = datetime.datetime.now()
print 'END ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print 'END ===> %ds %dms' %(now.second, now.microsecond)
#----------------------------------------------------
except WebFault, f:
print _("Exception: %s") %f

@ -34,17 +34,17 @@ import datetime
class Client_suds(Client):
def __init__(self, url, **kwargs):
now = datetime.datetime.now()
print 'suds1 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print 'suds1 ===> %ds %dms' %(now.second, now.microsecond)
Client.__init__(self, url, **kwargs)
now = datetime.datetime.now()
print 'suds1/2 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print 'suds1/2 ===> %ds %dms' %(now.second, now.microsecond)
options = Options()
now = datetime.datetime.now()
print 'suds1/3 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print 'suds1/3 ===> %ds %dms' %(now.second, now.microsecond)
options.cache = ObjectCache(days=5)
now = datetime.datetime.now()
print 'suds2 ===> %ds %dms' %(now.second, now.microsecond)
# now = datetime.datetime.now()
# print 'suds2 ===> %ds %dms' %(now.second, now.microsecond)
def set_parameters (self, path_to_cert, CERT_FILE, PKEY_FILE):
self.path_to_cert = path_to_cert

@ -151,9 +151,11 @@ def print_brief_group(Fields, group_name):
elif field.element in ['check', 'check_tristate']:
if field.value == 'on':
value = 'yes'
value = _('yes')
elif field.value == 'off':
value = 'no'
value = _('no')
elif field.value == 'auto':
value = _('auto')
else:
value = field.value
print green+'%s: %s' %(field.label, value)
@ -169,16 +171,38 @@ def print_brief_group(Fields, group_name):
if hasattr(row, 'string'):
body.append(row.string)
else: body = [[]]
print printTable(body, head)
ChoiceValue = field.tablevalue.values.ChoiceValue
for row in xrange(len(ChoiceValue)):
if ChoiceValue[row].typefield in ['check', 'check_tristate']:
for i in xrange(len(body)):
if body[i][row] == 'on':
body[i][row] = _('yes')
if body[i][row] == 'off':
body[i][row] = _('no')
if body[i][row] == 'auto':
body[i][row] = _('auto')
if ChoiceValue[row].typefield == 'password':
for i in xrange(len(body)):
if body[i][row]:
body[i][row] = '***'
data = []
for body_row in body:
data.append(map(lambda x: x if x else '', body_row))
print green+'%s: ' %(field.label)
res = printTable(data, head)
sys.stdout.flush()
sys.stdout.write(res)
else:
uncompatible_count += 1
if uncompatible_count == len (Fields) and group_name:
print green+'NONE'
print green + _('Not used')
def print_brief(view, brief_label):
print brief_label
for Group in view.groups.GroupField:
if Group.name:
if not Group.fields:
@ -268,7 +292,7 @@ def show_view(view):
def printTable(data, header=None ):
res = []
for row in data:
encode_row = map(lambda x: x.encode('utf-8') if x else None, row)
encode_row = map(lambda x: x.encode('utf-8') if x else '', row)
res.append(encode_row)
data = res

@ -89,15 +89,9 @@ def get_method_argparser(client, args):
return parser, view
def call_method(client, args):
print 'call_method'
method = args.method
# view_params = get_view_params(client, method + '_view', step = None, \
# expert = True)
#
# view = get_view(client, method, client.sid, view_params)
method_parser, view = get_method_argparser(client, args)
param_object = _create_obj(client, method)
args = method_parser.parse_known_args()[0]
@ -105,14 +99,25 @@ def call_method(client, args):
if steps.label and hasattr (param_object, 'CheckOnly'):
param_object['CheckOnly'] = True
# print param_object
method_result = client.service[0][method](client.sid, param_object)
if method_result.ReturnedMessage[0].type and \
method_result.ReturnedMessage[0].type != "pid":
print method_result
for error in method_result.ReturnedMessage:
red = '\033[31m * \033[0m'
print red + error.message
sys.exit(1)
view_params = get_view_params(client, method + '_view', step = None, \
expert = True, brief = True)
view = get_view(client, method, client.sid, view_params)
print_brief(view, steps.label)
while True:
ask = raw_input('\n'+_('Run process? (yes/no): '))
try:
ask = raw_input('\n'+_('Run process? (yes/no): '))
except KeyboardInterrupt:
ask = 'no'
if ask.lower() in ['n', 'no']:
red = '\033[31m * \033[0m'
print red + _('Interrupted by user')
@ -169,13 +174,27 @@ def collect_table(field, val_list, client):
if not val_list:
return None
val_table = map(lambda x: x.split(':'), val_list)
obj_body = []
key_list = []
if hasattr (field.tablevalue.body, 'stringArray'):
for obj_row in field.tablevalue.body.stringArray:
if hasattr(obj_row, 'string'):
key_list.append(obj_row.string[0])
obj_body.append(obj_row.string)
obj_body = collect_obj_body(obj_body, field)
column = len(field.tablevalue.head.string)
ChoiceValue = field.tablevalue.values.ChoiceValue
result_table = []
# result_table = []
for i in range(len(val_table)):
temp_row = []
print 'val_table[i] = ',val_table[i]
empty_row_flag = True if len (val_table[i]) == 1 else False
print 'empty_row_flag = ',empty_row_flag
for j in range(column):
# not adding if readonly
if j > (len(ChoiceValue) + 1):
@ -207,6 +226,71 @@ def collect_table(field, val_list, client):
temp_row.append('')
else:
temp_row.append(val_table[i][j])
result_table.append(temp_row)
return listToArrayArray(client, result_table)
if temp_row[0] in key_list:
ind = key_list.index(temp_row[0])
count_val = filter (None, temp_row)
if (len(count_val) == 1 and not empty_row_flag) or \
(len(count_val) == 2 and temp_row[1].lower() == 'none'):
obj_body.pop(ind)
key_list.pop(ind)
else:
obj_body.pop(ind)
obj_body.insert(ind, temp_row)
else:
count_val = filter (None, temp_row)
if (len(count_val) == 1 and not empty_row_flag) or \
(len(count_val) == 2 and temp_row[1].lower() == 'none'):
continue
obj_body.append(temp_row)
key_list.append(temp_row[0])
return listToArrayArray(client, obj_body)
def collect_obj_body(body, field):
column = len(field.tablevalue.head.string)
ChoiceValue = field.tablevalue.values.ChoiceValue
result_table = []
for i in range(len(body)):
temp_row = []
for j in range(column):
# not adding if readonly
if j > (len(ChoiceValue) + 1):
continue
choice_value = ChoiceValue[j]
typefield = choice_value.typefield
if typefield == 'readonly':
continue
elif typefield in ['check', 'check_tristate']:
if len (body[i]) < j + 1:
temp_row.append('')
continue
if not body[i][j]:
temp_row.append('')
elif body[i][j].lower() in ['on', 'yes']:
temp_row.append('on')
elif body[i][j].lower() in ['off', 'no']:
temp_row.append('off')
else:
temp_row.append(body[i][j])
elif typefield in ['input', 'combo', 'comboEdit', 'openfile', \
'file', 'password', 'radio']:
if len (body[i]) < j + 1:
temp_row.append('')
elif not body[i][j]:
temp_row.append('')
else:
temp_row.append(body[i][j])
elif typefield in ['multichoice', 'multichoice_add']:
if len (body[i]) < j + 1:
temp_row.append('')
elif not body[i][j]:
temp_row.append('')
else:
temp_row.append(body[i][j])
result_table.append(temp_row)
return result_table

@ -2,8 +2,8 @@ msgid ""
msgstr ""
"Project-Id-Version: console_gui_translate\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-05-23 17:35+0300\n"
"PO-Revision-Date: 2012-05-23 17:35+0300\n"
"POT-Creation-Date: 2012-05-23 17:59+0300\n"
"PO-Revision-Date: 2012-05-23 17:59+0300\n"
"Last-Translator: Denis <ds@mail.ru>\n"
"Language-Team: \n"
"Language: \n"
@ -171,23 +171,35 @@ msgstr "Страна (2 символа): [%s]"
msgid "Clear Cache error! "
msgstr "Ошибка очистки кэша!"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:323
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:154
msgid "yes"
msgstr "да"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:156
msgid "no"
msgstr "нет"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:158
msgid "auto"
msgstr "авто"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:324
msgid "Error"
msgstr "Ошибка"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:329
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:330
msgid "Warning"
msgstr "Предепреждение"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:367
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:368
msgid "Method not found: "
msgstr "Метод не найден: "
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:488
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:490
msgid "Process not exist or not belong to your session"
msgstr "Процесс не существует или принадлежит не вашей сессии"
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:540
#: /var/calculate/mydir/git/calculate-console/console/application/function.py:542
#, python-format
msgid "Error task by %s"
msgstr "Ошибка задачи на %s"
@ -269,11 +281,11 @@ msgstr "Не удалось подключиться"
msgid "Exception: %s"
msgstr "Исключение: %s"
#: /var/calculate/mydir/git/calculate-console/console/application/methods_func.py:114
msgid "Run process? yes/[no]: "
msgstr "Запустить процесс? yes/[no]: "
#: /var/calculate/mydir/git/calculate-console/console/application/methods_func.py:115
msgid "Run process? (yes/no): "
msgstr "Запустить процесс? (yes/no): "
#: /var/calculate/mydir/git/calculate-console/console/application/methods_func.py:116
#: /var/calculate/mydir/git/calculate-console/console/application/methods_func.py:118
msgid "Interrupted by user"
msgstr "Прервано пользователем"

@ -15,12 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, datetime
import sys
from calculate.console.application.cl_client import main
reload(sys)
sys.setdefaultencoding("utf-8")
if __name__=='__main__':
now = datetime.datetime.now()
print 'BEGIN ===> %dm %ds %dms' %(now.minute, now.second, now.microsecond)
sys.exit(main())
Loading…
Cancel
Save