#!/usr/bin/python # -*- coding: utf-8 -*- from PySide import QtGui import os, time, sys from calculate.api.client.cert_func import client_post_auth from calculate.api.cl_api import DataVarsApi from pid_information import client_list_methods, \ client_list_pid from calculate.api.client.function import get_entire_frame, create_obj, \ get_sid, analysis from calculate.api.client.sid_func import client_del_sid from leftmenu import left_menu def _(s): return s def show_msg(text): msgBox = QtGui.QMessageBox() msgBox.setText(text) msgBox.setStandardButtons(QtGui.QMessageBox.Ok) msgBox.exec_() def client_signal(client): Vars = DataVarsApi() Vars.importApi() Vars.flIniFile() try: client_active = Vars.Get('cl_api_client_active_period') except: client_active = 15 while True: if os.path.exists(client.SID_FILE) : fi = open(client.SID_FILE, 'r') temp = fi.read() fi.close() sid = int(temp) else: sid = 0 try: reply = client.service.active_client(sid) except: print _('no connection to server!') sys.exit() time.sleep(float(client_active)) def https_server(client, signaling, ClientObj): global url client_post_auth(client) signaling.start() ClientObj.methods_list = client_list_methods(client) if ClientObj.methods_list == 1: show_msg ('No methods available!') else: RES = 0 # Access to result COM = 0 # Getting command line METH = 1 # Getting method line for num in range (0, len(ClientObj.methods_list)): print " %s - %s" % (ClientObj.methods_list[num][RES][COM],\ ClientObj.methods_list[num][RES][METH]) ClientObj.MainWidget.topleft.menu.refresh(ClientObj.methods_list) get_entire_frame(client) #create_obj(client, "install_system") show_msg("Connection OK!") # while True: # try: # command = raw_input ("\nCommand: ") # except KeyboardInterrupt, e: # print # sys.exit() # if (command == 'halt' or command == 'server_shutdown'): # client_shut(client) # # #elif (command == 'say_hello' or command == 'say'): # #client_say_hello(client) # # #elif (command == 'say_hello2' or command == 'say2'): # #client_say_hello2(client) # # elif (command == 'server_start' or command == 'run'): # if os.path.exists(client.CERT_KEY) and\ # os.path.exists(client.CERT_FILE) : # client = Client_suds(url,\ # transport = HTTPSClientCertTransport(client.CERT_KEY,\ # client.CERT_FILE)) # #If the certificate file misses # else: # CERT_FILE = None # CERT_KEY = None # client = Client_suds(url,\ # transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE)) # # elif (command == 'login' or command == 'cl-login'): # client_login(client) # # elif (command == 'useradd' or command == 'cl-unix-useradd'): # client_useradd(client) # # elif (command == 'sid-del' or command == 'del-sid'): # client_del_sid(client) # # elif (command == 'lsp' or command == 'list-pid'): # client_list_pid(client) # # elif (command == 'ins' or command == 'install'): # client_install(client) # # elif (command == 'lsr' or command == 'list-method'\ # or command == 'list-right'): # client_list_methods(client) # # elif (command == 'lss' or command == 'list-session'\ # or command == 'sls'): # client_list_sessions(client) # # elif (command == 'pi' or command == 'pid-info'): # client_pid_info(client) # # elif (command == 'si' or command == 'session-info'): # client_session_info(client) # # elif (command == 'kill' or command == 'pid-kill'): # client_pid_kill(client) # # elif (command == 'userdel' or command == 'cl-unix-userdel'): # client_userdel(client) # # elif (command == 'vcr' or command == 'view-cert-right'): # client_view_cert_right(client) # # elif command.split(' ',1)[0] in ['t', 'template', 'cl-template']: # #client_template(client, command) # test(client, 'cl_template') # # elif command.lower() in ['test']: # test(client) # # elif (command == 'help' or command == 'h'): # print help_ # # elif command in ['q', 'quit', 'exit']: # print _("Closing\n") # signaling._Thread__stop() # time.sleep(0.3) # num = client_list_pid(client) # if num: # print _('at closing session, ' # 'data %d processes will be deleted!' %num) # c = raw_input (_("Close your session y/[n]: ")) # if c in ['y', 'yes', 'Y', 'YES']: # client_del_sid(client) # #signaling.killed = True ## client_shut(client) # return 0 # else: # print _("Input Error") def test(client, com=None): if not com: method_name = 'test' else: method_name = com view = client.service[0][method_name + '_view']() #print '==>', view cr = create_obj(client, method_name) #print 'ddd',cr #print type (cr) list_param = dir (cr) param_list = [] for param in list_param: if not param.startswith('_'): param_list.append(param) for Group in view.groups.GroupField: print "GroupField name : ", Group.name for field in Group.fields.Field: if field.element == 'input': if field.type == 'str': cr[field.name] = raw_input(field.label) if field.type == 'int': while True: try: var = raw_input(field.label) cr[field.name] = int (var) break except (TypeError, ValueError): print _('Это не целое число') elif field.element == 'bool': while 1: bool_var = raw_input(field.label+' (y/n): ') if bool_var.lower() in ['y','yes']: cr[field.name] = True break if bool_var.lower() in ['n','no']: cr[field.name] = False break print _('Enter "Yes" or "No"!') elif field.element == 'check': choice = field.choice[0] while 1: print _('Select one: ') for i in range(1,len(choice)+1): print choice[i-1], ' - %d' %i try: bool_var = int (raw_input(field.label)) if bool_var > 0: cr[field.name] = choice[bool_var - 1] print 'your choice %s' %cr[field.name] break except: pass #field.choice #print field.help sid = get_sid(client.SID_FILE) s = client.service[0][method_name](sid, cr) analysis(client, sid, s)