1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 15:49:41 +02:00
audacity/scripts/piped-work/pipe_test.py
Steve Daulton bedd4f1f3f Fix pipe_test for Python3 on Linux
The script still works with Python 2 on Linux, but it should be tested
(with Python 3) on Windows and Mac.
2019-03-22 10:15:51 +00:00

72 lines
1.9 KiB
Python

# pipe_test.py
# Tests the audacity pipe. Sends 3 commands.
# Keep pipe_test.py short!!
# 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.
import os
import sys
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, 'w' )
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: >>> \n"+command )
tofile.write( command + EOL )
tofile.flush()
def getResponse() :
result = ''
line = ''
while line != '\n' :
result += line
line = fromfile.readline()
#print(" I read line:["+line+"]")
return result
def doCommand( command ) :
sendCommand( command )
response = getResponse()
print( "Rcvd: <<< \n" + response )
return response
def do( command ) :
doCommand( command )
def quickTest() :
do( 'Help: Command=Help' )
do( 'Help: Command="GetInfo"' )
#do( 'SetPreference: Name=GUI/Theme Value=classic Reload=1' )
quickTest()