Skip to content
Snippets Groups Projects
Commit 13176e3c authored by Connor McCoy's avatar Connor McCoy
Browse files

[scripts] Improve errors in bin/ycsb

* Handles missing "java" with an error message.
* Adds a check_output method for users running on Python 2.6.
* Prints an error when importing argparse fails (third party module on Python 2.6).
parent 454f88f8
No related branches found
No related tags found
No related merge requests found
...@@ -16,13 +16,18 @@ ...@@ -16,13 +16,18 @@
# LICENSE file. # LICENSE file.
# #
import argparse import errno
import fnmatch import fnmatch
import io import io
import os import os
import shlex import shlex
import sys import sys
import subprocess import subprocess
try:
import argparse
except ImportError:
print >> sys.stderr, '[ERROR] argparse not found. Try installing it via "pip".'
raise
BASE_URL = "https://github.com/brianfrankcooper/YCSB/tree/master/" BASE_URL = "https://github.com/brianfrankcooper/YCSB/tree/master/"
COMMANDS = { COMMANDS = {
...@@ -111,6 +116,13 @@ def usage(): ...@@ -111,6 +116,13 @@ def usage():
return output.getvalue() return output.getvalue()
def check_output(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
stdout, _ = p.communicate()
if p.returncode:
raise subprocess.CalledProcessError(p.returncode, cmd)
return stdout
def debug(message): def debug(message):
print >> sys.stderr, "[DEBUG] ", message print >> sys.stderr, "[DEBUG] ", message
...@@ -127,7 +139,6 @@ def find_jars(dir, glob='*.jar'): ...@@ -127,7 +139,6 @@ def find_jars(dir, glob='*.jar'):
jars.append(os.path.join(dirpath, filename)) jars.append(os.path.join(dirpath, filename))
return jars return jars
def get_ycsb_home(): def get_ycsb_home():
dir = os.path.abspath(os.path.dirname(sys.argv[0])) dir = os.path.abspath(os.path.dirname(sys.argv[0]))
while "LICENSE.txt" not in os.listdir(dir): while "LICENSE.txt" not in os.listdir(dir):
...@@ -147,11 +158,11 @@ def get_classpath_from_maven(module): ...@@ -147,11 +158,11 @@ def get_classpath_from_maven(module):
try: try:
debug("Running 'mvn -pl com.yahoo.ycsb:" + module + " -am package -DskipTests " debug("Running 'mvn -pl com.yahoo.ycsb:" + module + " -am package -DskipTests "
"dependency:build-classpath -DincludeScope=compile -Dmdep.outputFilterFile=true'") "dependency:build-classpath -DincludeScope=compile -Dmdep.outputFilterFile=true'")
mvn_output = subprocess.check_output(["mvn", "-pl", "com.yahoo.ycsb:" + module, mvn_output = check_output(["mvn", "-pl", "com.yahoo.ycsb:" + module,
"-am", "package", "-DskipTests", "-am", "package", "-DskipTests",
"dependency:build-classpath", "dependency:build-classpath",
"-DincludeScope=compile", "-DincludeScope=compile",
"-Dmdep.outputFilterFile=true"]) "-Dmdep.outputFilterFile=true"])
# the above outputs a "classpath=/path/tojar:/path/to/other/jar" for each module # the above outputs a "classpath=/path/tojar:/path/to/other/jar" for each module
# the last module will be the datastore binding # the last module will be the datastore binding
line = [x for x in mvn_output.splitlines() if x.startswith("classpath=")][-1:] line = [x for x in mvn_output.splitlines() if x.startswith("classpath=")][-1:]
...@@ -226,8 +237,14 @@ def main(): ...@@ -226,8 +237,14 @@ def main():
if command: if command:
ycsb_command.append(command) ycsb_command.append(command)
print >> sys.stderr, " ".join(ycsb_command) print >> sys.stderr, " ".join(ycsb_command)
return subprocess.call(ycsb_command) try:
return subprocess.call(ycsb_command)
except OSError as e:
if e.errno == errno.ENOENT:
error('Command failed. Is java installed and on your PATH?')
return 1
else:
raise
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment