Add connection to server

master3.3
Спиридонов Денис 12 years ago
parent 78bac1e35c
commit aced1c4eab

@ -0,0 +1,24 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
from calculate.lib.cl_datavars import DataVars
from calculate.api.cl_api import DataVarsApi
class ApiClient:
def __init__(self):
# Initialization of system variables
Vars = DataVarsApi()
Vars.importApi()
Vars.flIniFile()
clVars = DataVars()
clVars.flIniFile()
# Initialization other variables
self.homePath = clVars.Get('ur_home_path')
path_to_cert = '~/.calculate/client_cert/'
self.path_to_cert = path_to_cert.replace("~",self.homePath)
self.WindowTitle = 'cl-api-client'
self.default_host = 'localhost'
self.default_port = '8888'
self.client = None

@ -1,14 +1,16 @@
#!/usr/bin/python
# messagebox.py
#-*- coding: utf-8 -*-
import sys
from PySide import QtGui
from Box import Example
from gui.Box import Example
from ClientClass import ApiClient
app = QtGui.QApplication(sys.argv)
ex = Example()
f = QtGui.QStyleFactory().create('Motif')
ClientObj = ApiClient()
ex = Example(ClientObj)
#f = QtGui.QStyleFactory().create('Motif')
#ex.setStyle(f)
#ex.setStyle('Windows')
ex.show()

@ -1,19 +1,22 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
from PySide import QtGui, QtCore
from PySide.QtGui import QScrollArea, QLabel, QMessageBox
from leftmenu import LeftMenu
from statusfield import StatusField
from mainframe import MainFrame
from mainmenu import MainMenu
from helpwidget import HelpWgt
from tools import ToolsWidget
from conf_connection import FrameConnection
#class Example(QtGui.QWidget):
class Example(QtGui.QMainWindow):
def __init__(self):
def __init__(self, ClientObj):
super(Example, self).__init__()
self.ClientObj = ClientObj
self.initUI()
def initUI(self):
@ -29,15 +32,18 @@ class Example(QtGui.QMainWindow):
# левое верхнее меню
topleft = LeftMenu(self)
# верхнее правое
self.main_frame = MainFrame(self)
self.main_frame = FrameConnection(self, self.ClientObj)
self.main_frame.resize(700,900)
# создание нижнего фрейма
bottom = StatusField(self)
bottom.resize(800,100)
# объединение в один виджет
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(self.main_frame)
splitter1.setGeometry(0, 0, 0, 140)
splitter1.resize(800,700)
# splitter1.setGeometry(0, 0, 0, 140)
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
@ -46,18 +52,30 @@ class Example(QtGui.QMainWindow):
hbox.addWidget(splitter2)
# self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
# QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
# QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('CDE'))
CentralWidget = QtGui.QWidget()
CentralWidget.setLayout(hbox)
self.setCentralWidget(CentralWidget)
self.setGeometry(200, 200, 800, 800)
self.setWindowTitle('QtGui.QSplitter')
self.move(200, 200)
self.resize(800,800)
self.setWindowTitle(self.ClientObj.WindowTitle)
def onChanged(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
def help(self):
self.HelpWidget = HelpWgt(self)
self.HelpWidget.show()
def tools(self):
self.ToolsWgt = ToolsWidget(self)
self.ToolsWgt.show()
# def closeEvent(self, event):
## reply = QtGui.QMessageBox.question(self, 'Message',
## "Close your session?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No,\

@ -0,0 +1,159 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide import QtGui, QtCore
from calculate.api.client.client_class import Client_suds
from calculate.api.client.client_class import HTTPSClientCertTransport
from suds import WebFault
from suds.transport import TransportError, Request
from calculate.api.cl_api import DataVarsApi
from calculate.api.client.function import *
from calculate.api.client.pid_information import *
from calculate.api.client.cert_func import *
from calculate.api.client.cert_verify import get_CRL, VerifyError
from calculate.api.client.sid_func import *
import soap
from soap.more import https_server, client_signal, show_msg, test
class Conn(QtGui.QWidget):
def __init__(self, ClientObj):
super(Conn, self).__init__()
self.ClientObj = ClientObj
self.initUI()
def initUI(self):
grid = QtGui.QGridLayout()
grid.setSpacing(10)
self.lbl_host = QtGui.QLabel("Host: ")
self.lbl_port = QtGui.QLabel("Port: ")
self.text_host = QtGui.QLineEdit(self.ClientObj.default_host)
self.text_port = QtGui.QLineEdit(self.ClientObj.default_port)
grid.setRowMinimumHeight(0,20)
grid.setColumnMinimumWidth(0,30)
# grid.addWidget(QtGui.QSpacerItem(10,10),0,0)
grid.addWidget(self.lbl_host, 1, 1)
grid.addWidget(self.lbl_port, 2, 1)
grid.addWidget(self.text_host, 1, 2)
grid.addWidget(self.text_port, 2, 2)
self.cmd_connect = QtGui.QPushButton('Connect')
grid.addWidget(self.cmd_connect, 3, 2)
self.cmd_connect.connect \
(self.cmd_connect, QtCore.SIGNAL('clicked()'), self.onClick)
self.setLayout(grid)
self.setGeometry(0, 0, 150, 180)
self.show()
# establish a connection
def onClick(self):
# write parameters
self.str_host = self.text_host.text()
self.str_port = self.text_port.text()
self.lbl_host.setText(self.str_host)
self.lbl_port.setText(self.str_port)
try:
int_port = int(self.str_port)
except:
show_msg("Enter correctly port!")
return 1
# get server hostname
url = "https://%s:%d/?wsdl" %(self.str_host, int_port)
path_to_cert = self.ClientObj.path_to_cert
try:
client = Client_suds(url, transport = \
HTTPSClientCertTransport(None,None, path_to_cert))
except:
show_msg("Not connected!")
return 1
server_host_name = client.service.get_server_host_name()
del (client)
self.lbl_port.setText(server_host_name)
try:
import glob
all_cert_list = glob.glob(path_to_cert + '*.crt')
fit_cert_list = []
for client_cert_path in all_cert_list:
client_cert = client_cert_path.replace(path_to_cert, '')
client_cert_name = client_cert.replace('.crt', '')
if server_host_name.endswith(client_cert_name):
fit_cert_list.append(client_cert_name)
fit_cert_list.sort(key = len)
Connect_Error = 1
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'
# print "cert_name = ",cert_name
try:
self.ClientObj.client = Client_suds(url,\
transport = HTTPSClientCertTransport(CERT_KEY, \
CERT_FILE, path_to_cert))
self.ClientObj.client.set_parameters \
(path_to_cert, CERT_FILE, CERT_KEY)
client_post_cert(self.ClientObj.client)
Connect_Error = 0
except VerifyError, e:
show_msg (e.value)
Connect_Error = 1
except Exception, e:
print 1111111
print dir(e)
show_msg (e.message)
Connect_Error = 1
#sys.exit()
if Connect_Error == 0:
break
#If the certificate file misses
if Connect_Error:
CERT_FILE = None
CERT_KEY = None
self.ClientObj.client = Client_suds(url,\
transport = HTTPSClientCertTransport(CERT_KEY, CERT_FILE,\
path_to_cert))
self.ClientObj.client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
Vars = DataVarsApi()
Vars.importApi()
Vars.flIniFile()
try:
self.ClientObj.client.frame_period = Vars.Get('cl_api_get_frame_period')
except:
self.ClientObj.client.frame_period = 2
signaling = threading.Thread(target=client_signal, args = (self.ClientObj.client, ))
signaling.setDaemon(True)
https_server(self.ClientObj.client, signaling)
#----------------------------------------------------
except WebFault, f:
show_msg ("Exception: %s" %f)
print f.fault
except TransportError, te:
show_msg ("Exception: %s" %te)
except Exception, e:
show_msg ("Exception: %s" %e)
# tb.print_exc()
class FrameConnection (QtGui.QScrollArea):
def __init__(self, parent, ClientObj):
self.ClientObj = ClientObj
QtGui.QScrollArea.__init__(self)
# верхнее правое
connection = Conn(self.ClientObj)
self.setWidget(connection)
# self.resize(700,900)

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from PySide import QtGui, QtCore
class HelpWgt(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self)
helpLabel = QtGui.QLabel('about calculate Inc.')
helpQuit = QtGui.QPushButton("Quit")
layout = QtGui.QVBoxLayout()
layout.addWidget(helpLabel)
layout.addWidget(helpQuit)
self.setLayout(layout)
self.connect(helpQuit, QtCore.SIGNAL("clicked()"),
self, QtCore.SLOT("close()"))
self.move(100+parent.frameGeometry().x(), \
100+parent.frameGeometry().y())
self.resize(200,200)
# self.show()

@ -25,7 +25,6 @@ class Checkbox(QtGui.QWidget):
combo.activated[str].connect(self.onActivated)
self.setGeometry(0, 0, 150, 180)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
@ -40,21 +39,22 @@ class Checkbox(QtGui.QWidget):
self.lbl.show()
self.lbl.setText(text)
self.lbl.adjustSize()
class LeftMenu(QtGui.QFrame):
def __init__(self, parent):
QtGui.QFrame.__init__(self)
# верхнее левое меню
# верхнее левое меню
# topleft = QtGui.QFrame(self)
# self.setFrameShape(QtGui.QFrame.NoFrame)
self.setGeometry(0, 0, 100, 20)
check1 = Checkbox()
self.scrollArea1 = QtGui.QScrollArea()
self.scrollArea1.setWidget(check1)
tempbox = QtGui.QHBoxLayout(self)
tempbox.addWidget(self.scrollArea1)
self.setLayout(tempbox)
tempbox = QtGui.QHBoxLayout(self)
tempbox.addWidget(self.scrollArea1)
self.setLayout(tempbox)
# self.resize(100,900)

@ -24,7 +24,6 @@ class Check(QtGui.QWidget):
combo.activated[str].connect(self.onActivated)
self.setGeometry(0, 0, 150, 180)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
@ -45,4 +44,5 @@ class MainFrame (QtGui.QScrollArea):
QtGui.QScrollArea.__init__(self)
# верхнее правое
check2 = Check()
self.setWidget(check2)
self.setWidget(check2)
# self.resize(700,900)

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class MainMenu():
def __init__(self, parent):
exitAction = QtGui.QAction(QtGui.QIcon('image/Exit.png'), \
'&Exit', parent)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(parent.close)
toolAction = QtGui.QAction(QtGui.QIcon('image/tool.png'), \
'&Tool', parent)
toolAction.setShortcut('Ctrl+T')
toolAction.setStatusTip('Tool application')
toolAction.triggered.connect(parent.tools)
helpAction = QtGui.QAction(QtGui.QIcon('image/help.png'), \
'&Help', parent)
helpAction.setShortcut('Ctrl+H')
helpAction.setStatusTip('Help')
helpAction.triggered.connect(parent.help)
parent.toolbar = parent.addToolBar('Main')
parent.toolbar.addAction(toolAction)
parent.toolbar.addAction(helpAction)
parent.toolbar.addAction(exitAction)
# menubar = parent.menuBar()
# fileMenu = menubar.addMenu('&File')
# fileMenu.addAction(exitAction)

@ -22,7 +22,6 @@ class Checkbox(QtGui.QWidget):
self.combo.activated[str].connect(self.onActivated)
self.setGeometry(50, 50, 200, 100)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
@ -48,6 +47,7 @@ class StatusField (QtGui.QFrame):
self.scrollArea3 = QtGui.QScrollArea()
self.scrollArea3.horizontalScrollBar().hide()
self.scrollArea3.setWidget(check3)
# self.resize(800,10)
tempbox3.addWidget(self.scrollArea3)
self.setLayout(tempbox3)

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class ToolsWidget (QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self)
helpLabel = QtGui.QLabel('about calculate Inc.')
helpQuit = QtGui.QPushButton("Quit")
layout = QtGui.QVBoxLayout()
layout.addWidget(helpLabel)
layout.addWidget(helpQuit)
self.setLayout(layout)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

@ -1,16 +0,0 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class MainMenu():
def __init__(self, parent):
exitAction = QtGui.QAction(QtGui.QIcon('image/Exit.png'), '&Exit', parent)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(parent.close)
parent.toolbar = parent.addToolBar('Exit')
parent.toolbar.addAction(exitAction)
# menubar = parent.menuBar()
# fileMenu = menubar.addMenu('&File')
# fileMenu.addAction(exitAction)

@ -0,0 +1,216 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide import QtGui, QtCore
import os, time, sys
from calculate.api.client.cert_func import client_post_auth
from calculate.api.cl_api import DataVarsApi
from calculate.api.client.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
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()
print 1111111111
time.sleep(float(client_active))
def https_server(client, signaling):
global url
client_post_auth(client)
signaling.start()
client_list_methods(client)
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)
Loading…
Cancel
Save