Source
xxxxxxxxxx
'%s=%s' % (server,ctsys.registry( )['uri']) ] + data_path + rcdir + nogui,
import os as __os
import sys as __sys
import pwd as __pwd
import time as __time
import traceback
from .config import app_path
debug = 'GRPC_DEBUG' in __os.environ
###
### TODO: (1) perhaps add __main__ which execs casaviewer app
### https://stackoverflow.com/a/55346918
###
###
### Load the necessary gRPC libraries and bindings.
###
### The generated wrappers assume that all of the wrappers can be
### loaded using the standard sys.path so here we add the path to
### the wrappers, load all of the needed wrappers, and then remove
### the private path from sys.path
###
__sys.path.insert(0, __os.path.dirname(__os.path.abspath(__file__)))
import grpc as __grpc
from . import shutdown_pb2_grpc as __sd
from . import ping_pb2_grpc as __ping
from google.protobuf import empty_pb2 as __empty_p
from . import img_pb2 as __img_p
from . import img_pb2_grpc as __img_rpc
__sys.path.pop(0)
###
### Tried to subclass to add __hash__( ) function to Id message (needed
### to be able to build a dict of Ids), but got error "TypeError: A
### Message class can only inherit from Message". At first I assumed
### this must be Google (gRPC) trying to add some structure to Python,
### but after brief searching, it seems like just Python brokenness...
###
def __h(id):
return id.id
def make_id(v):
i = __img_p.Id( )
i.id = v
return i
def is_id(o):
### "type(o) == __img_p.Id" fails...
return o.__class__.__name__ == __img_p.Id.__name__ and o.__class__.__module__ == __img_p.Id.__module__
__proc = { '--server': None, '--nogui': None }
__stub = { '--server': None, '--nogui': None }
__channel = { '--server': None, '--nogui': None }
__uri = { '--server': None, '--nogui': None }
__stub_id = { '--server': None, '--nogui': None }
__health_check = { '--server': 0, '--nogui': 0 }
__id_gui_state = { }
__registered = False
###
### When casaviewer is started (via __launch) without casatools, this function
### is called to shutdown the casaviewer app when the user exits python.
###
def __shutdown_sans_casatools( ):
global __uri
for k in __uri:
if __uri[k] is not None:
channel = __grpc.insecure_channel(__uri[k])
shutdown = __sd.ShutdownStub(channel)
shutdown.now(__empty_p.Empty( ))
###
### A named-pipe is used for communication when casaviewer is started
### without casatools. The --server=... flag to the casaviewer app
### accepts wither a named pipe (path) or a gRPC URI. The URI for
### the casaviewer app is passed back through the named pipe.
###
def __fifo_name(index):
count = 0
path = "/tmp/._casaviewer_%s_%s_%s_" % (__pwd.getpwuid(__os.getuid()).pw_name, __os.getpid( ), count)
while __os.path.exists(path):
count = count + 1
path = "/tmp/._casaviewer_%s_%s_%s_" % (__pwd.getpwuid(__os.getuid()).pw_name, __os.getpid( ), count)
return path
###
### Create a named pipe...
###
def __mkfifo( ):
path = __fifo_name(0)
__os.mkfifo(path)