Support gstdbuf on MacOSX

Change-Id: I6cdff2b4cebcd6168b8779ad8330d5c86f6a9d6e
This commit is contained in:
ahothan 2016-08-12 09:44:31 -07:00
parent f220bdd59f
commit 1f0c94a2e5
3 changed files with 23 additions and 70 deletions

View File

@ -69,38 +69,6 @@ If you need to run the KloudBuster Web UI you need to install coreutils
$ # Refer here for the steps to install Homebrew on Mac:
$ # http://brew.sh/
$ brew install coreutils
$ # Follow instructions to add the new directory in the path
$ export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
$ # Verify that you have stdbuf working
$ stdbuf --help
Usage: stdbuf OPTION... COMMAND
Run COMMAND, with modified buffering operations for its standard streams.
Mandatory arguments to long options are mandatory for short options too.
-i, --input=MODE adjust standard input stream buffering
-o, --output=MODE adjust standard output stream buffering
-e, --error=MODE adjust standard error stream buffering
--help display this help and exit
--version output version information and exit
If MODE is 'L' the corresponding stream will be line buffered.
This option is invalid with standard input.
If MODE is '0' the corresponding stream will be unbuffered.
Otherwise MODE is a number which may be followed by one of the following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
In this case the corresponding stream will be fully buffered with the buffer
size set to MODE bytes.
NOTE: If COMMAND adjusts the buffering of its standard streams ('tee' does
for example) then that will override corresponding changes by 'stdbuf'.
Also some filters (like 'dd' and 'cat' etc.) don't use streams for I/O,
and are thus unaffected by 'stdbuf' settings.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/stdbuf>
or available locally via: info '(coreutils) stdbuf invocation'
Verify installation
^^^^^^^^^^^^^^^^^^^

View File

@ -37,38 +37,7 @@ MacOSX::
$ # Refer here for the steps to install Homebrew on Mac:
$ # http://brew.sh/
$ brew install coreutils
$ # Follow instructions to add the new directory in the path
$ export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
$ # Verify that you have stdbuf working
$ stdbuf --help
Usage: stdbuf OPTION... COMMAND
Run COMMAND, with modified buffering operations for its standard streams.
Mandatory arguments to long options are mandatory for short options too.
-i, --input=MODE adjust standard input stream buffering
-o, --output=MODE adjust standard output stream buffering
-e, --error=MODE adjust standard error stream buffering
--help display this help and exit
--version output version information and exit
If MODE is 'L' the corresponding stream will be line buffered.
This option is invalid with standard input.
If MODE is '0' the corresponding stream will be unbuffered.
Otherwise MODE is a number which may be followed by one of the following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
In this case the corresponding stream will be fully buffered with the buffer
size set to MODE bytes.
NOTE: If COMMAND adjusts the buffering of its standard streams ('tee' does
for example) then that will override corresponding changes by 'stdbuf'.
Also some filters (like 'dd' and 'cat' etc.) don't use streams for I/O,
and are thus unaffected by 'stdbuf' settings.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/stdbuf>
or available locally via: info '(coreutils) stdbuf invocation'
2. Install KloudBuster in a virtual environment
-----------------------------------------------

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from pkg_resources import resource_filename
import subprocess
import sys
@ -26,18 +27,33 @@ def exec_command(cmd, cwd=None, show_console=False):
p.communicate()
return p.returncode
# will raise OSError exception if the command is not found
def launch_kb(cwd):
for stdbuf in ['stdbuf', 'gstdbuf']:
cmd = [stdbuf, '-oL', 'python', 'setup.py', 'develop']
try:
rc = exec_command(cmd, cwd=cwd)
if not rc:
cmd = [stdbuf, '-oL', 'pecan', 'serve', 'config.py']
rc = exec_command(cmd, cwd=cwd, show_console=True)
return rc
except OSError:
continue
if os.uname()[0] == "Darwin":
print
print "To run the KloudBuster web server you need to install the coreutils package:"
print " brew install coreutils"
print
raise OSError('Cannot find stdbuf or gstdbuf command')
def main():
cwd = resource_filename(__name__, 'config.py')
cwd = cwd[:cwd.rfind('/')] + '/../kb_server'
try:
cmd = ['stdbuf', '-oL', 'python', 'setup.py', 'develop']
rc = exec_command(cmd, cwd=cwd)
if not rc:
cmd = ['stdbuf', '-oL', 'pecan', 'serve', 'config.py']
rc = exec_command(cmd, cwd=cwd, show_console=True)
sys.exit(rc)
return launch_kb(cwd)
except KeyboardInterrupt:
print 'Terminating server...'
return 1
if __name__ == '__main__':
main()
sys.exit(main())