mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-26 03:19:48 +00:00
Add facility for confetty to interact with external controller
For certain scenarios (e.g. wcons), having a path to get in and communicate data from the outside. For starters, have a 'GETWINID' directive for wcons to use to fetch the unambiguous window id to use for xwininfo tricks. TODO includes concepts from xtcd.pl that enabled things like warr
This commit is contained in:
parent
57d0997d62
commit
b2102bae30
@ -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:
|
||||
|
63
confluent_client/confluent/termhandler.py
Normal file
63
confluent_client/confluent/termhandler.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user