-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
59 lines (43 loc) · 1.73 KB
/
utils.py
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
import CosNaming, Server, Client
import os
import sys
from omniORB import CORBA, PortableServer
def read_in_chunks(file_object, chunk_size=65536):
while True:
data = file_object.read(chunk_size)
if not data:
break
yield data
def connect_to_server(server_name):
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
try:
obj = orb.resolve_initial_references("NameService")
rootContext = obj._narrow(CosNaming.NamingContext)
name = [CosNaming.NameComponent(server_name, "context"),
CosNaming.NameComponent(server_name, "Object")]
obj = rootContext.resolve(name)
obj = obj._narrow(Server.CentralServer)
if obj is None:
print("Voce tem certeza deste servidor?")
sys.exit(1)
print("Conectado a {} com sucesso".format(server_name))
return obj
except CosNaming.NamingContext.NotFound, ex:
print("Servidor nao encontrado")
sys.exit(1)
def connect_to_client(server_name):
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
try:
obj = orb.resolve_initial_references("NameService")
rootContext = obj._narrow(CosNaming.NamingContext)
name = [CosNaming.NameComponent(server_name, "context"),
CosNaming.NameComponent(server_name, "Object")]
obj = rootContext.resolve(name)
obj = obj._narrow(Client.ClientServer)
if obj is None:
print("Voce tem certeza deste cliente?")
sys.exit(1)
print("Conectado a {} com sucesso".format(server_name))
return obj
except CosNaming.NamingContext.NotFound, ex:
print("Cliente nao encontrado")