1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Update pipe_test.py for Python 3

This commit is contained in:
Steve Daulton 2019-03-22 14:16:18 +00:00
parent de427da4c8
commit 6f9746b601
2 changed files with 56 additions and 48 deletions

View File

@ -1,71 +1,79 @@
# 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.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Make sure Audacity is running first and that mod-script-pipe is enabled
# before running this script.
"""Tests the audacity pipe.
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.
Requires Python 2.7 or later. Python 3 is strongly recommended.
"""
import os
import sys
if( sys.platform == 'win32' ):
print( "pipe-test.py, running on windows" )
toname = '\\\\.\\pipe\\ToSrvPipe'
fromname = '\\\\.\\pipe\\FromSrvPipe'
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())
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("Write to \"" + TONAME +"\"")
if not os.path.exists(TONAME):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
print( "-- Both pipes exist. Good." )
print("Read from \"" + FROMNAME +"\"")
if not os.path.exists(FROMNAME):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
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" )
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 send_command(command):
"""Send a single command."""
print("Send: >>> \n"+command)
TOFILE.write(command + EOL)
TOFILE.flush()
def getResponse() :
def get_response():
"""Return the command response."""
result = ''
line = ''
while line != '\n' :
while line != '\n':
result += line
line = fromfile.readline()
line = FROMFILE.readline()
#print(" I read line:["+line+"]")
return result
def doCommand( command ) :
sendCommand( command )
response = getResponse()
print( "Rcvd: <<< \n" + response )
def do_command(command):
"""Send one command, and return the response."""
send_command(command)
response = get_response()
print("Rcvd: <<< \n" + response)
return response
def do( command ) :
doCommand( command )
def quick_test():
"""Example list of commands."""
do_command('Help: Command=Help')
do_command('Help: Command="GetInfo"')
#do_command('SetPreference: Name=GUI/Theme Value=classic Reload=1')
def quickTest() :
do( 'Help: Command=Help' )
do( 'Help: Command="GetInfo"' )
#do( 'SetPreference: Name=GUI/Theme Value=classic Reload=1' )
quickTest()
quick_test()

View File

@ -5,7 +5,7 @@
Pipe Client may be used as a command-line script to send commands to
Audacity via the mod-script-pipe interface, or loaded as a module.
Requires Python 2.7 or later. Python 3 recommended.
Requires Python 2.7 or later. Python 3 strongly recommended.
======================
Command Line Interface