From ce697d052ac3651be311ea6a76a10f03e3c33050 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 13 Jan 2018 13:54:44 +0000 Subject: [PATCH] mod-script-pipe python scripts working on linux too. - Pipe names are different on Linux. - End of line is different on linux. - The pipe must be opened with 'w+' not just 'w'. --- scripts/piped-work/get-gui-structure.py | 48 +++++++++++++++++++---- scripts/piped-work/pipe-test.py | 52 ++++++++++++++++++++----- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/scripts/piped-work/get-gui-structure.py b/scripts/piped-work/get-gui-structure.py index 12abf5fb3..516bfac7f 100644 --- a/scripts/piped-work/get-gui-structure.py +++ b/scripts/piped-work/get-gui-structure.py @@ -1,16 +1,46 @@ # get-gui-structure.py # Obtains all menus and all box locations from the currently running Audacity. +# This is useful for wit.audacityteam.org, where we need these lists when we +# draw the menus and create the image maps. + +# Make sure Audacity is running first and that mod-script-pipe is enabled +# before running this script. + +import os +import sys -toname = '\\\\.\\pipe\\ToSrvPipe' -fromname = '\\\\.\\pipe\\FromSrvPipe' +if( sys.platform == 'win32' ): + print( "get-gui-structure.py, running on windows" ) + toname = '\\\\.\\pipe\\ToSrvPipe' + fromname = '\\\\.\\pipe\\FromSrvPipe' + EOL = '\r\n\0' +else: + print( "get-gui-structure.py, running on linux or mac" ) + toname = '/tmp/audacity_script_pipe.to.' + str(os.getuid()) + fromname = '/tmp/audacity_script_pipe.from.' + str(os.getuid()) + EOL = '\n' -tofile = open( toname, 'wt' ) +print( "Write to \"" + toname +"\"" ) +if not os.path.exists( toname ) : + print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." ) + sys.exit(); + +print( "Read from \"" + fromname +"\"") +if not os.path.exists( fromname ) : + print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." ) + sys.exit(); + +print( "-- Both pipes exist. Good." ) + +tofile = open( toname, 'wt+' ) +print( "-- File to write to has been opened" ) fromfile = open( fromname, 'rt') +print( "-- File to read from has now been opened too\r\n" ) def sendCommand( command ) : - print( "Send: "+command ) - tofile.write( command + '\r\n\0' ) + print( "Send: >>> "+command ) + tofile.write( command + EOL ) tofile.flush() def getResponse() : @@ -24,15 +54,19 @@ def getResponse() : def doCommand( command ) : sendCommand( command ) response = getResponse() - print( "Rcvd: " + response ) + print( "Rcvd: <<< " + response ) return response def do( command ) : doCommand( command ) + def getStructure() : + #do( 'Help: CommandName=Help' ) + #do( 'Help: CommandName=SetPreference' ) + #do( 'SetPreference: PrefName=GUI/Theme PrefValue=light' ) + #do( 'Screenshot: CaptureMode=menus' ) do( 'GetBoxes' ) - #doCommand( 'Screenshot: CaptureMode=menus' ) do( 'GetMenusPlus' ) getStructure() diff --git a/scripts/piped-work/pipe-test.py b/scripts/piped-work/pipe-test.py index 4108b1e8e..50a390404 100644 --- a/scripts/piped-work/pipe-test.py +++ b/scripts/piped-work/pipe-test.py @@ -4,16 +4,45 @@ # You can make more complicated longer tests to test other functionality # or to generate screenshots etc in other scripts. +# Make sure Audacity is running first and that mod-script-pipe is enabled +# before running this script. -toname = '\\\\.\\pipe\\ToSrvPipe' -fromname = '\\\\.\\pipe\\FromSrvPipe' +import os +import sys -tofile = open( toname, 'wt' ) + +if( sys.platform == 'win32' ): + print( "pipe-test.py, running on windows" ) + toname = '\\\\.\\pipe\\ToSrvPipe' + fromname = '\\\\.\\pipe\\FromSrvPipe' + EOL = '\r\n\0' +else: + print( "pipe-test.py, running on linux or mac" ) + toname = '/tmp/audacity_script_pipe.to.' + str(os.getuid()) + fromname = '/tmp/audacity_script_pipe.from.' + str(os.getuid()) + EOL = '\n' + +print( "Write to \"" + toname +"\"" ) +if not os.path.exists( toname ) : + print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." ) + sys.exit(); + +print( "Read from \"" + fromname +"\"") +if not os.path.exists( fromname ) : + print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." ) + sys.exit(); + +print( "-- Both pipes exist. Good." ) + +tofile = open( toname, 'wt+' ) +print( "-- File to write to has been opened" ) fromfile = open( fromname, 'rt') +print( "-- File to read from has now been opened too\r\n" ) + def sendCommand( command ) : - print( "Send: "+command ) - tofile.write( command + '\r\n\0' ) + print( "Send: >>> "+command ) + tofile.write( command + EOL ) tofile.flush() def getResponse() : @@ -22,18 +51,21 @@ def getResponse() : while line != '\n' : result += line line = fromfile.readline() + #print(" I read line:["+line+"]") return result def doCommand( command ) : sendCommand( command ) response = getResponse() - print( "Rcvd: " + response ) + print( "Rcvd: <<< " + response ) return response -def quickTest() : - doCommand( 'Help: CommandName=Help' ) - doCommand( 'Help: CommandName=SetPreference' ) - doCommand( 'SetPreference: PrefName=GUI/Theme PrefValue=light' ) +def do( command ) : + doCommand( command ) +def quickTest() : + do( 'Help: CommandName=Help' ) + do( 'Help: CommandName=SetPreference' ) + do( 'SetPreference: PrefName=GUI/Theme PrefValue=light' ) quickTest()