mirror of
https://github.com/cookiengineer/audacity
synced 2026-02-04 10:43:08 +01:00
Update pipe_test.py for Python 3
This commit is contained in:
@@ -1,71 +1,79 @@
|
|||||||
# pipe_test.py
|
#!/usr/bin/env python
|
||||||
# Tests the audacity pipe. Sends 3 commands.
|
# -*- coding: utf-8 -*-
|
||||||
# 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
|
"""Tests the audacity pipe.
|
||||||
# before running this script.
|
|
||||||
|
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 os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
if( sys.platform == 'win32' ):
|
if sys.platform == 'win32':
|
||||||
print( "pipe-test.py, running on windows" )
|
print("pipe-test.py, running on windows")
|
||||||
toname = '\\\\.\\pipe\\ToSrvPipe'
|
TONAME = '\\\\.\\pipe\\ToSrvPipe'
|
||||||
fromname = '\\\\.\\pipe\\FromSrvPipe'
|
FROMNAME = '\\\\.\\pipe\\FromSrvPipe'
|
||||||
EOL = '\r\n\0'
|
EOL = '\r\n\0'
|
||||||
else:
|
else:
|
||||||
print( "pipe-test.py, running on linux or mac" )
|
print("pipe-test.py, running on linux or mac")
|
||||||
toname = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
|
TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
|
||||||
fromname = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
|
FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
|
||||||
EOL = '\n'
|
EOL = '\n'
|
||||||
|
|
||||||
print( "Write to \"" + toname +"\"" )
|
print("Write to \"" + TONAME +"\"")
|
||||||
if not os.path.exists( toname ) :
|
if not os.path.exists(TONAME):
|
||||||
print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." )
|
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
|
||||||
sys.exit();
|
sys.exit()
|
||||||
|
|
||||||
print( "Read from \"" + fromname +"\"")
|
print("Read from \"" + FROMNAME +"\"")
|
||||||
if not os.path.exists( fromname ) :
|
if not os.path.exists(FROMNAME):
|
||||||
print( " ..does not exist. Ensure Audacity is running with mod-script-pipe." )
|
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
|
||||||
sys.exit();
|
sys.exit()
|
||||||
|
|
||||||
print( "-- Both pipes exist. Good." )
|
print("-- Both pipes exist. Good.")
|
||||||
|
|
||||||
tofile = open( toname, 'w' )
|
TOFILE = open(TONAME, 'w')
|
||||||
print( "-- File to write to has been opened" )
|
print("-- File to write to has been opened")
|
||||||
fromfile = open( fromname, 'rt')
|
FROMFILE = open(FROMNAME, 'rt')
|
||||||
print( "-- File to read from has now been opened too\r\n" )
|
print("-- File to read from has now been opened too\r\n")
|
||||||
|
|
||||||
|
|
||||||
def sendCommand( command ) :
|
def send_command(command):
|
||||||
print( "Send: >>> \n"+command )
|
"""Send a single command."""
|
||||||
tofile.write( command + EOL )
|
print("Send: >>> \n"+command)
|
||||||
tofile.flush()
|
TOFILE.write(command + EOL)
|
||||||
|
TOFILE.flush()
|
||||||
|
|
||||||
def getResponse() :
|
def get_response():
|
||||||
|
"""Return the command response."""
|
||||||
result = ''
|
result = ''
|
||||||
line = ''
|
line = ''
|
||||||
while line != '\n' :
|
while line != '\n':
|
||||||
result += line
|
result += line
|
||||||
line = fromfile.readline()
|
line = FROMFILE.readline()
|
||||||
#print(" I read line:["+line+"]")
|
#print(" I read line:["+line+"]")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def doCommand( command ) :
|
def do_command(command):
|
||||||
sendCommand( command )
|
"""Send one command, and return the response."""
|
||||||
response = getResponse()
|
send_command(command)
|
||||||
print( "Rcvd: <<< \n" + response )
|
response = get_response()
|
||||||
|
print("Rcvd: <<< \n" + response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def do( command ) :
|
def quick_test():
|
||||||
doCommand( command )
|
"""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() :
|
quick_test()
|
||||||
do( 'Help: Command=Help' )
|
|
||||||
do( 'Help: Command="GetInfo"' )
|
|
||||||
#do( 'SetPreference: Name=GUI/Theme Value=classic Reload=1' )
|
|
||||||
|
|
||||||
quickTest()
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
Pipe Client may be used as a command-line script to send commands to
|
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.
|
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
|
Command Line Interface
|
||||||
|
|||||||
Reference in New Issue
Block a user