spark-instrumented-optimizer/python/pyspark/shell.py

34 lines
888 B
Python
Raw Normal View History

2012-10-19 20:16:41 -04:00
"""
An interactive shell.
"""
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
def main(master='local', ipython=False):
2012-10-19 20:16:41 -04:00
sc = SparkContext(master, 'PySparkShell')
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__':
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)