aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/shell.py
diff options
context:
space:
mode:
authorJosh Rosen <joshrosen@eecs.berkeley.edu>2013-01-01 21:25:49 -0800
committerJosh Rosen <joshrosen@eecs.berkeley.edu>2013-01-01 21:25:49 -0800
commitce9f1bbe20eff794cd1d588dc88f109d32588cfe (patch)
treeff840eea62e8314dc4cefcaa08534c4b21e544ba /python/pyspark/shell.py
parentb58340dbd9a741331fc4c3829b08c093560056c2 (diff)
downloadspark-ce9f1bbe20eff794cd1d588dc88f109d32588cfe.tar.gz
spark-ce9f1bbe20eff794cd1d588dc88f109d32588cfe.tar.bz2
spark-ce9f1bbe20eff794cd1d588dc88f109d32588cfe.zip
Add `pyspark` script to replace the other scripts.
Expand the PySpark programming guide.
Diffstat (limited to 'python/pyspark/shell.py')
-rw-r--r--python/pyspark/shell.py36
1 files changed, 10 insertions, 26 deletions
diff --git a/python/pyspark/shell.py b/python/pyspark/shell.py
index bd39b0283f..7e6ad3aa76 100644
--- a/python/pyspark/shell.py
+++ b/python/pyspark/shell.py
@@ -1,33 +1,17 @@
"""
An interactive shell.
-"""
-import optparse # I prefer argparse, but it's not included with Python < 2.7
-import code
-import sys
+This fle is designed to be launched as a PYTHONSTARTUP script.
+"""
+import os
from pyspark.context import SparkContext
-def main(master='local', ipython=False):
- 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)
-
+sc = SparkContext(os.environ.get("MASTER", "local"), "PySparkShell")
+print "Spark context avaiable as sc."
-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)
+# The ./pyspark script stores the old PYTHONSTARTUP value in OLD_PYTHONSTARTUP,
+# which allows us to execute the user's PYTHONSTARTUP file:
+_pythonstartup = os.environ.get('OLD_PYTHONSTARTUP')
+if _pythonstartup and os.path.isfile(_pythonstartup):
+ execfile(_pythonstartup)