2012-10-19 20:16:41 -04:00
|
|
|
"""
|
|
|
|
An interactive shell.
|
|
|
|
"""
|
2012-12-28 01:47:37 -05:00
|
|
|
import optparse # I prefer argparse, but it's not included with Python < 2.7
|
2012-10-19 20:16:41 -04:00
|
|
|
import code
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from pyspark.context import SparkContext
|
|
|
|
|
|
|
|
|
2012-12-27 13:13:29 -05:00
|
|
|
def main(master='local', ipython=False):
|
2012-10-19 20:16:41 -04:00
|
|
|
sc = SparkContext(master, 'PySparkShell')
|
2012-12-27 13:13:29 -05:00
|
|
|
user_ns = {'sc' : sc}
|
|
|
|
banner = "Spark context avaiable as sc."
|
|
|
|
if ipython:
|
|
|
|
import IPython
|
|
|
|
IPython.embed(user_ns=user_ns, banner2=banner)
|
|
|
|
else:
|
|
|
|
print banner
|
|
|
|
code.interact(local=user_ns)
|
2012-10-19 20:16:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-12-28 01:47:37 -05:00
|
|
|
usage = "usage: %prog [options] master"
|
|
|
|
parser = optparse.OptionParser(usage=usage)
|
|
|
|
parser.add_option("-i", "--ipython", help="Run IPython shell",
|
|
|
|
action="store_true")
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
master = args[0]
|
|
|
|
else:
|
|
|
|
master = 'local'
|
|
|
|
main(master, options.ipython)
|