complete VCSU support
This commit is contained in:
parent
4a70a0442e
commit
8423dbe4ab
@ -23,6 +23,7 @@ from struct import unpack_from, unpack, pack
|
|||||||
from fenrirscreenreader.core import debug
|
from fenrirscreenreader.core import debug
|
||||||
from fenrirscreenreader.core.eventData import fenrirEventType
|
from fenrirscreenreader.core.eventData import fenrirEventType
|
||||||
from fenrirscreenreader.core.screenDriver import screenDriver
|
from fenrirscreenreader.core.screenDriver import screenDriver
|
||||||
|
from fenrirscreenreader.utils import screen_utils
|
||||||
|
|
||||||
class driver(screenDriver):
|
class driver(screenDriver):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -47,7 +48,7 @@ class driver(screenDriver):
|
|||||||
'default', # fontsize
|
'default', # fontsize
|
||||||
'default' # fontfamily
|
'default' # fontfamily
|
||||||
]) #end attribute )
|
]) #end attribute )
|
||||||
self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog, multiprocess=True)
|
self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog, multiprocess=True)
|
||||||
def getCurrScreen(self):
|
def getCurrScreen(self):
|
||||||
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
|
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
|
||||||
try:
|
try:
|
||||||
@ -55,7 +56,7 @@ class driver(screenDriver):
|
|||||||
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
||||||
currScreenFile.close()
|
currScreenFile.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
def injectTextToScreen(self, text, screen = None):
|
def injectTextToScreen(self, text, screen = None):
|
||||||
useScreen = "/dev/tty" + self.env['screen']['newTTY']
|
useScreen = "/dev/tty" + self.env['screen']['newTTY']
|
||||||
if screen != None:
|
if screen != None:
|
||||||
@ -63,12 +64,12 @@ class driver(screenDriver):
|
|||||||
with open(useScreen, 'w') as fd:
|
with open(useScreen, 'w') as fd:
|
||||||
for c in text:
|
for c in text:
|
||||||
fcntl.ioctl(fd, termios.TIOCSTI, c)
|
fcntl.ioctl(fd, termios.TIOCSTI, c)
|
||||||
|
|
||||||
def getSessionInformation(self):
|
def getSessionInformation(self):
|
||||||
self.env['screen']['autoIgnoreScreens'] = []
|
self.env['screen']['autoIgnoreScreens'] = []
|
||||||
try:
|
try:
|
||||||
if not self.sysBus:
|
if not self.sysBus:
|
||||||
self.sysBus = dbus.SystemBus()
|
self.sysBus = dbus.SystemBus()
|
||||||
obj = self.sysBus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
|
obj = self.sysBus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
|
||||||
inf = dbus.Interface(obj, 'org.freedesktop.login1.Manager')
|
inf = dbus.Interface(obj, 'org.freedesktop.login1.Manager')
|
||||||
self.ListSessions = inf.get_dbus_method('ListSessions')
|
self.ListSessions = inf.get_dbus_method('ListSessions')
|
||||||
@ -83,16 +84,16 @@ class driver(screenDriver):
|
|||||||
screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY'))
|
screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY'))
|
||||||
screen = screen[screen.upper().find('TTY') + 3:]
|
screen = screen[screen.upper().find('TTY') + 3:]
|
||||||
if screen == '':
|
if screen == '':
|
||||||
self.env['runtime']['debug'].writeDebugOut('No TTY found for session:' + session[4],debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('No TTY found for session:' + session[4],debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
if sessionType.upper() != 'TTY':
|
if sessionType.upper() != 'TTY':
|
||||||
self.env['screen']['autoIgnoreScreens'] += [screen]
|
self.env['screen']['autoIgnoreScreens'] += [screen]
|
||||||
if screen == self.env['screen']['newTTY'] :
|
if screen == self.env['screen']['newTTY'] :
|
||||||
if self.env['general']['currUser'] != session[2]:
|
if self.env['general']['currUser'] != session[2]:
|
||||||
self.env['general']['prevUser'] = self.env['general']['currUser']
|
self.env['general']['prevUser'] = self.env['general']['currUser']
|
||||||
self.env['general']['currUser'] = session[2]
|
self.env['general']['currUser'] = session[2]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR)
|
||||||
#self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO)
|
#self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO)
|
||||||
|
|
||||||
def updateWatchdog(self,active , eventQueue):
|
def updateWatchdog(self,active , eventQueue):
|
||||||
@ -106,7 +107,7 @@ class driver(screenDriver):
|
|||||||
index = vcsaDev[9:]
|
index = vcsaDev[9:]
|
||||||
vcsa[str(index)] = open(vcsaDev,'rb')
|
vcsa[str(index)] = open(vcsaDev,'rb')
|
||||||
if useVCSU:
|
if useVCSU:
|
||||||
vcsuDevices = glob.glob('/dev/vcsu*')
|
vcsuDevices = glob.glob('/dev/vcsu*')
|
||||||
for vcsuDev in vcsuDevices:
|
for vcsuDev in vcsuDevices:
|
||||||
index = vcsuDev[9:]
|
index = vcsuDev[9:]
|
||||||
vcsu[str(index)] = open(vcsuDev,'rb')
|
vcsu[str(index)] = open(vcsuDev,'rb')
|
||||||
@ -123,43 +124,48 @@ class driver(screenDriver):
|
|||||||
fileno = change[0]
|
fileno = change[0]
|
||||||
event = change[1]
|
event = change[1]
|
||||||
if fileno == tty.fileno():
|
if fileno == tty.fileno():
|
||||||
self.env['runtime']['debug'].writeDebugOut('ScreenChange',debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut('ScreenChange',debug.debugLevel.INFO)
|
||||||
tty.seek(0)
|
tty.seek(0)
|
||||||
currScreen = str(tty.read()[3:-1])
|
currScreen = str(tty.read()[3:-1])
|
||||||
if currScreen != oldScreen:
|
if currScreen != oldScreen:
|
||||||
try:
|
try:
|
||||||
watchdog.unregister(vcsa[ oldScreen ])
|
watchdog.unregister(vcsa[oldScreen])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
watchdog.register(vcsa[ currScreen ], select.POLLPRI | select.POLLERR)
|
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.updateCharMap(currScreen)
|
self.updateCharMap(currScreen)
|
||||||
oldScreen = currScreen
|
oldScreen = currScreen
|
||||||
try:
|
try:
|
||||||
vcsa[currScreen].seek(0)
|
vcsa[currScreen].seek(0)
|
||||||
lastScreenContent = vcsa[currScreen].read()
|
lastScreenContent = vcsa[currScreen].read()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
vcsuContent = None
|
||||||
|
if useVCSU:
|
||||||
|
vcsu[currScreen].seek(0)
|
||||||
|
vcsuContent = vcsu[currScreen].read()
|
||||||
eventQueue.put({"Type":fenrirEventType.ScreenChanged,
|
eventQueue.put({"Type":fenrirEventType.ScreenChanged,
|
||||||
"Data":self.createScreenEventData(currScreen,lastScreenContent)
|
"Data":self.createScreenEventData(currScreen, lastScreenContent, vcsuContent)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO)
|
||||||
vcsa[currScreen].seek(0)
|
vcsa[currScreen].seek(0)
|
||||||
dirtyContent = vcsa[currScreen].read()
|
dirtyContent = vcsa[currScreen].read()
|
||||||
screenContent = b''
|
screenContent = b''
|
||||||
vcsuContent = None
|
vcsuContent = None
|
||||||
timeout = time.time()
|
timeout = time.time()
|
||||||
while screenContent != dirtyContent:
|
while screenContent != dirtyContent:
|
||||||
screenContent = dirtyContent
|
screenContent = dirtyContent
|
||||||
if time.time() - timeout >= 0.4:
|
if time.time() - timeout >= 0.4:
|
||||||
break
|
break
|
||||||
time.sleep(0.02)
|
time.sleep(0.02)
|
||||||
vcsa[currScreen].seek(0)
|
vcsa[currScreen].seek(0)
|
||||||
dirtyContent = vcsa[currScreen].read()
|
dirtyContent = vcsa[currScreen].read()
|
||||||
if useVCSU:
|
if useVCSU:
|
||||||
|
vcsu[currScreen].seek(0)
|
||||||
vcsuContent = vcsu[currScreen].read()
|
vcsuContent = vcsu[currScreen].read()
|
||||||
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
||||||
"Data":self.createScreenEventData(currScreen, screenContent, vcsuContent)
|
"Data":self.createScreenEventData(currScreen, screenContent, vcsuContent)
|
||||||
@ -167,7 +173,6 @@ class driver(screenDriver):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
|
||||||
def createScreenEventData(self, screen, vcsaContent, vcsuContent = None):
|
def createScreenEventData(self, screen, vcsaContent, vcsuContent = None):
|
||||||
eventData = {
|
eventData = {
|
||||||
@ -179,14 +184,14 @@ class driver(screenDriver):
|
|||||||
'x': int( vcsaContent[2]),
|
'x': int( vcsaContent[2]),
|
||||||
'y': int( vcsaContent[3])
|
'y': int( vcsaContent[3])
|
||||||
},
|
},
|
||||||
'screen': screen,
|
'screen': screen,
|
||||||
'screenUpdateTime': time.time(),
|
'screenUpdateTime': time.time(),
|
||||||
}
|
}
|
||||||
eventData['text'], eventData['attributes'] =\
|
eventData['text'], eventData['attributes'] =\
|
||||||
self.autoDecodeVCSA(vcsaContent[4:], eventData['lines'], eventData['columns'])
|
self.autoDecodeVCSA(vcsaContent[4:], eventData['lines'], eventData['columns'])
|
||||||
#if vcsuContent != None:
|
if vcsuContent != None:
|
||||||
# eventData['text'] = vcsuContent.decode('UTF-32')
|
eventData['text'] = screen_utils.insertNewlines(vcsuContent.decode('UTF-32', 'replace'), eventData['columns'])
|
||||||
return eventData.copy()
|
return eventData.copy()
|
||||||
def updateCharMap(self, screen):
|
def updateCharMap(self, screen):
|
||||||
self.charmap = {}
|
self.charmap = {}
|
||||||
try:
|
try:
|
||||||
@ -226,7 +231,7 @@ class driver(screenDriver):
|
|||||||
lineAttrib = []
|
lineAttrib = []
|
||||||
for x in range(cols):
|
for x in range(cols):
|
||||||
data = allData[i: i + 2]
|
data = allData[i: i + 2]
|
||||||
i += 2
|
i += 2
|
||||||
if data == b' \x07':
|
if data == b' \x07':
|
||||||
#attr = 7
|
#attr = 7
|
||||||
#ink = 7
|
#ink = 7
|
||||||
@ -266,7 +271,7 @@ class driver(screenDriver):
|
|||||||
if sh & self.hichar:
|
if sh & self.hichar:
|
||||||
ch |= 0x100
|
ch |= 0x100
|
||||||
try:
|
try:
|
||||||
lineText += self.charmap[ch]
|
lineText += self.charmap[ch]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
lineText += '?'
|
lineText += '?'
|
||||||
charAttrib = [
|
charAttrib = [
|
||||||
@ -293,7 +298,7 @@ class driver(screenDriver):
|
|||||||
currScreen = self.env['screen']['newTTY']
|
currScreen = self.env['screen']['newTTY']
|
||||||
apps = subprocess.Popen('ps -t tty' + currScreen + ' -o comm,tty,stat', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n')
|
apps = subprocess.Popen('ps -t tty' + currScreen + ' -o comm,tty,stat', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
for i in apps:
|
for i in apps:
|
||||||
@ -308,8 +313,7 @@ class driver(screenDriver):
|
|||||||
not "PS" == i[0]:
|
not "PS" == i[0]:
|
||||||
if "TTY"+currScreen in i[1]:
|
if "TTY"+currScreen in i[1]:
|
||||||
if self.env['screen']['newApplication'] != i[0]:
|
if self.env['screen']['newApplication'] != i[0]:
|
||||||
self.env['screen']['newApplication'] = i[0]
|
self.env['screen']['newApplication'] = i[0]
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
|
@ -11,23 +11,23 @@ def getPrevLine(currX,currY, currText):
|
|||||||
endOfScreen = False
|
endOfScreen = False
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, '', endOfScreen
|
return -1, -1, '', endOfScreen
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
x = currX
|
x = currX
|
||||||
y = currY
|
y = currY
|
||||||
if y - 1 >= 0:
|
if y - 1 >= 0:
|
||||||
y -= 1
|
y -= 1
|
||||||
else:
|
else:
|
||||||
endOfScreen = True
|
endOfScreen = True
|
||||||
x = 0
|
x = 0
|
||||||
currLine = ''
|
currLine = ''
|
||||||
if not endOfScreen:
|
if not endOfScreen:
|
||||||
currLine = wrappedLines[y]
|
currLine = wrappedLines[y]
|
||||||
return x, y, currLine, endOfScreen
|
return x, y, currLine, endOfScreen
|
||||||
|
|
||||||
def getCurrentLine(currX,currY, currText):
|
def getCurrentLine(currX,currY, currText):
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, ''
|
return -1, -1, ''
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
x = currX
|
x = currX
|
||||||
y = currY
|
y = currY
|
||||||
x = 0
|
x = 0
|
||||||
@ -38,7 +38,7 @@ def getNextLine(currX,currY, currText):
|
|||||||
endOfScreen = False
|
endOfScreen = False
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, '', endOfScreen
|
return -1, -1, '', endOfScreen
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
x = currX
|
x = currX
|
||||||
y = currY
|
y = currY
|
||||||
if y + 1 < len(wrappedLines):
|
if y + 1 < len(wrappedLines):
|
||||||
|
@ -32,7 +32,7 @@ def createScreenEventData(content):
|
|||||||
'screen': content['screen'],
|
'screen': content['screen'],
|
||||||
'text': content['text'],
|
'text': content['text'],
|
||||||
'attributes': content['attributes'],
|
'attributes': content['attributes'],
|
||||||
'screenUpdateTime': time.time(),
|
'screenUpdateTime': time.time(),
|
||||||
}
|
}
|
||||||
return eventData.copy()
|
return eventData.copy()
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ def isValidShell(shell = ''):
|
|||||||
def getShell():
|
def getShell():
|
||||||
try:
|
try:
|
||||||
shell = os.environ["FENRIRSHELL"]
|
shell = os.environ["FENRIRSHELL"]
|
||||||
if isValidShell(shell):
|
if isValidShell(shell):
|
||||||
return shell
|
return shell
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -83,7 +83,7 @@ def getShell():
|
|||||||
(username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':')
|
(username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':')
|
||||||
shell = shell.replace('\n','')
|
shell = shell.replace('\n','')
|
||||||
if username == getpass.getuser():
|
if username == getpass.getuser():
|
||||||
if isValidShell(shell):
|
if isValidShell(shell):
|
||||||
return shell
|
return shell
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user