diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 7409bfb3..e45fef9d 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -62,6 +62,7 @@ path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) if path.startswith('/opt'): sys.path.append(path) +import confluent.termhandler as termhandler import confluent.tlvdata as tlvdata import confluent.client as client @@ -509,12 +510,16 @@ def check_escape_seq(currinput, filehandle): currinput += filehandle.read() return currinput - parser = optparse.OptionParser() parser.add_option("-s", "--server", dest="netserver", help="Confluent instance to connect to", metavar="SERVER:PORT") +parser.add_option("-c", "--control", dest="controlpath", + help="Path to offer terminal control", + metavar="PATH") opts, shellargs = parser.parse_args() +if opts.controlpath: + termhandler.TermHandler(opts.controlpath) if opts.netserver: # going over a TLS network session = client.Command(opts.netserver) elif 'CONFLUENT_HOST' in os.environ: diff --git a/confluent_client/confluent/termhandler.py b/confluent_client/confluent/termhandler.py new file mode 100644 index 00000000..986b2229 --- /dev/null +++ b/confluent_client/confluent/termhandler.py @@ -0,0 +1,63 @@ +__author__ = 'jbjohnso' + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2014 Lenovo Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#This file is responsible for a client-side communication method to enable +#capabilities like measuring and rearranging the terminal window for +#wcons + +import atexit +import os +import socket +import stat +import threading + +class TermHandler(object): + def __init__(self, path): + self.path = path + self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + try: + os.remove(path) + except OSError: # if file does not exist, no big deal + pass + atexit.register(self.shutdown) + self.socket.bind(path) + os.chmod(path, stat.S_IWUSR | stat.S_IRUSR) + threading.Thread(target=self.sockinteract).start() + + def shutdown(self): + try: + os.remove(self.path) + except OSError: + pass + + def sockinteract(self): + self.socket.listen(5) + while True: + connection = None + try: + connection, address = self.socket.accept() + connection.sendall("confetty control v1--\n") + cmd = connection.recv(8) + if 'GETWINID' == cmd: + connection.sendall(os.environ['WINDOWID']) + connection.close() + except BaseException: + pass + finally: + if connection is not None: + connection.close() \ No newline at end of file