fix encode error, modified get pasword

develop
Спиридонов Денис 12 years ago
parent f208273145
commit 152cd94942

@ -32,7 +32,12 @@ from calculate.core.client.function import create_obj
green = '\033[32m * \033[0m'
red = '\033[31m * \033[0m'
colorPrint = color_print()
class _color_print(color_print):
def _printSUCCESS(self, string, offsetL=0, printBR=True):
self.printSUCCESS(string.encode('utf-8'), offsetL, printBR)
colorPrint = _color_print()
def _print (*args):
print " ".join(map(lambda x:unicode(x).encode('utf-8'),args))
@ -100,7 +105,7 @@ def print_brief_group(Fields, group_name):
continue
if field.element in ['input', 'openfile']:
value = field.value if field.value else ''
colorPrint.printSUCCESS('%s: %s' %(field.label, value))
colorPrint._printSUCCESS('%s: %s' %(field.label, value))
elif field.element in ['combo', 'comboEdit', 'radio', 'file']:
if hasattr (field.comments, 'string') and field.value in \
@ -113,7 +118,7 @@ def print_brief_group(Fields, group_name):
value = ', '.join(value)
else:
value = field.value if field.value else ''
colorPrint.printSUCCESS('%s: %s' %(field.label, value))
colorPrint._printSUCCESS('%s: %s' %(field.label, value))
elif field.element in ['multichoice', 'multichoice_add',\
'selecttable', 'selecttable_add']:
@ -129,7 +134,7 @@ def print_brief_group(Fields, group_name):
value = ', '.join(field.listvalue.string)
else:
value = field.value if field.value else ''
colorPrint.printSUCCESS('%s: %s' %(field.label, value))
colorPrint._printSUCCESS('%s: %s' %(field.label, value))
# elif field.element == 'label':
# print field.label
@ -146,7 +151,7 @@ def print_brief_group(Fields, group_name):
value = _('auto')
else:
value = field.value
colorPrint.printSUCCESS('%s: %s' %(field.label, value))
colorPrint._printSUCCESS('%s: %s' %(field.label, value))
elif field.element == 'table' and field.type != 'steps':
if hasattr (field.tablevalue.head, 'string'):
@ -187,7 +192,7 @@ def print_brief_group(Fields, group_name):
for body_row in body:
data.append(map(lambda x: x if x else '', body_row))
colorPrint.printSUCCESS('%s: ' %(field.label))
colorPrint._printSUCCESS('%s: ' %(field.label))
res = printTable(data, head)
sys.stdout.flush()
sys.stdout.write(res)
@ -196,7 +201,7 @@ def print_brief_group(Fields, group_name):
uncompatible_count += 1
if uncompatible_count == len (Fields) and group_name:
colorPrint.printSUCCESS(_('Not used'))
colorPrint._printSUCCESS(_('Not used'))
def print_brief(view, brief_label):
for Group in view.groups.GroupField:
@ -268,7 +273,7 @@ def printTable(data, header=None ):
def show_table(table, item):
if item.message:
colorPrint.printSUCCESS(item.message)
colorPrint._printSUCCESS(item.message)
head = table.head.string if hasattr (table.head, 'string') else None
data = []
for line in table.body[0]:
@ -292,7 +297,7 @@ def show_warning(item):
def show_group(item):
if item.message:
for line in item.message.splitlines():
colorPrint.printSUCCESS(line)
colorPrint._printSUCCESS(line)
def show_result(result):
pass
@ -300,12 +305,12 @@ def show_result(result):
def startTask(item):
if item.message:
for line in item.message.splitlines():
colorPrint.printSUCCESS(line)
colorPrint._printSUCCESS(line)
def endTask(item):
if item.message:
for line in item.message.splitlines():
colorPrint.printSUCCESS(line)
colorPrint._printSUCCESS(line)
def beginFrame(item):
pass
@ -508,12 +513,12 @@ def cout(string):
def print_progressbar(returnProgr, pbar, last_msg = None, error = False):
if returnProgr.long_message:
if last_msg != returnProgr.long_message:
colorPrint.printSUCCESS('%s\n' %returnProgr.long_message)
colorPrint._printSUCCESS('%s\n' %returnProgr.long_message)
pbar.update(returnProgr.percent)
return returnProgr.long_message
elif returnProgr.short_message:
if last_msg != returnProgr.short_message:
colorPrint.printSUCCESS('%s\n' %returnProgr.short_message)
colorPrint._printSUCCESS('%s\n' %returnProgr.short_message)
pbar.update(returnProgr.percent)
return returnProgr.short_message
else:

@ -21,7 +21,8 @@ setLocalTranslate('calculate_console',sys.modules[__name__])
import urllib2
from calculate.core.server.methods_func import get_method_argparser, \
collect_object, RawAndDefaultsHelpFormatter
collect_object, RawAndDefaultsHelpFormatter, \
get_password, set_table_pwd
def parse():
parser = argparse.ArgumentParser(add_help=False,
@ -99,6 +100,44 @@ def get_view(client, method, sid, view_params):
raise Exception(1)
return view
def check_result_msg(method_result, view):
password_errors = {}
for error in method_result.ReturnedMessage:
if error.type == 'pwderror':
password_errors[error.field] = error.message
continue
params_text = ''
for Group in view.groups.GroupField:
for field in Group.fields.Field:
if field.name == error.field:
if field.opt.shortopt or field.opt.longopt:
params_text += _('Wrong option ')
params_text += ', '.join(filter(None,
[field.opt.shortopt, field.opt.longopt])) \
+ '. '
red = '\033[31m * \033[0m'
_print ('\r' + red + params_text + error.message)
if len(password_errors) < len(method_result.ReturnedMessage):
return None
else:
return password_errors
def get_param_pwd(check_res, view, param_object, client):
for pwd_field in check_res:
_print (check_res[pwd_field])
for Group in view.groups.GroupField:
for field in Group.fields.Field:
if field.name == pwd_field:
if field.element == 'table':
value = get_password()
set_table_pwd(client, param_object, field, value)
else:
value = get_password()
setattr(param_object, pwd_field, value)
return param_object
def call_method(client, args, wait_thread):
method = args.method
no_questions = args.no_questions
@ -125,28 +164,24 @@ def call_method(client, args, wait_thread):
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)
while True:
method_result = client.service[0][method](client.sid,param_object)
if not method_result:
print _('Method not available')
return None
if method_result.ReturnedMessage[0].type and \
method_result.ReturnedMessage[0].type != "pid":
wait_thread.stop()
if not method_result:
print _('Method not available')
return None
if method_result.ReturnedMessage[0].type and \
method_result.ReturnedMessage[0].type != "pid":
wait_thread.stop()
for error in method_result.ReturnedMessage:
params_text = ''
for Group in view.groups.GroupField:
for field in Group.fields.Field:
if field.name == error.field:
if field.opt.shortopt or field.opt.longopt:
params_text += _('Wrong option ')
params_text += ', '.join(filter(None,
[field.opt.shortopt, field.opt.longopt])) \
+ '. '
check_res = check_result_msg(method_result, view)
if not check_res:
return None
else:
param_object = get_param_pwd(check_res, view,
param_object, client)
else:
break
red = '\033[31m * \033[0m'
_print ('\r' + red + params_text + error.message)
return None
view_params = get_view_params(client, method + '_view', step = None, \
expert = True, brief = True)
view = get_view(client, method, client.sid, view_params)

Loading…
Cancel
Save