]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: make life easier on developers by handling in-tree runs
authorDan Mick <dan.mick@inktank.com>
Wed, 12 Jun 2013 02:46:53 +0000 (19:46 -0700)
committerDan Mick <dan.mick@inktank.com>
Wed, 12 Jun 2013 21:05:34 +0000 (14:05 -0700)
If <path-to-ceph> contains pybind and .libs:
- prepend <path-to-ceph>/pybind to PYTHONPATH
- append <path-to-ceph>/.libs to LD_LIBRARY_PATH if not already there
  and exec self so it takes effect

Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/ceph.in

index 01dd908ad98acce582a695ce7e3666b76cd62d38..18e518669dc395e55c036fe883b4fe8309918204 100755 (executable)
@@ -1,12 +1,41 @@
 #
 # Processed in Makefile to add python #! line and version variable
 #
+#
+# vim: ts=4 sw=4 smarttab expandtab
+
+
+import os
+import sys
+
+# Make life easier on developers:
+# If in src/, and .libs and pybind exist here, assume we're running
+# from a Ceph source dir and tweak PYTHONPATH and LD_LIBRARY_PATH
+# to use local files
+
+MYPATH = os.path.abspath(__file__)
+MYDIR = os.path.dirname(MYPATH)
+DEVMODEMSG = '*** DEVELOPER MODE: setting PYTHONPATH and LD_LIBRARY_PATH'
+
+if MYDIR.endswith('src') and \
+   os.path.exists(os.path.join(MYDIR, '.libs')) and \
+   os.path.exists(os.path.join(MYDIR, 'pybind')):
+    MYLIBPATH = os.path.join(MYDIR, '.libs')
+    if 'LD_LIBRARY_PATH' in os.environ:
+        if MYLIBPATH not in os.environ['LD_LIBRARY_PATH']:
+            os.environ['LD_LIBRARY_PATH'] += ':' + MYLIBPATH
+            print >> sys.stderr, DEVMODEMSG
+            os.execvp('python', ['python'] + sys.argv)
+    else:
+        os.environ['LD_LIBRARY_PATH'] = MYLIBPATH
+        print >> sys.stderr, DEVMODEMSG
+        os.execvp('python', ['python'] + sys.argv)
+    sys.path.insert(0, os.path.join(MYDIR, 'pybind'))
 
 import argparse
 import copy
 import errno
 import json
-import os
 import rados
 # for raw_input to do readline cmd editing
 import readline
@@ -15,7 +44,6 @@ import stat
 import string
 import struct
 import subprocess
-import sys
 import types
 import uuid