From f2a3f9a622613ec1575e70ac9fe9655b485d9a6d Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Wed, 8 Sep 2010 10:45:39 +0200 Subject: [PATCH] Make the scripts in bin/ detect if they're being run from a bzr checkout or an extracted release tarball or whatever and adjust PYTHONPATH accordingly. --- bin/nova-api | 10 ++++++++++ bin/nova-api-new | 11 +++++++++++ bin/nova-compute | 11 +++++++++++ bin/nova-dhcpbridge | 11 +++++++---- bin/nova-import-canonical-imagestore | 8 ++++++++ bin/nova-instancemonitor | 10 ++++++++++ bin/nova-manage | 9 +++++++++ bin/nova-network | 11 +++++++++++ bin/nova-objectstore | 11 +++++++++++ bin/nova-volume | 11 +++++++++++ 10 files changed, 99 insertions(+), 4 deletions(-) diff --git a/bin/nova-api b/bin/nova-api index a3ad5a0e1dff..ede09d38c97d 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -22,9 +22,19 @@ Tornado daemon for the main API endpoint. """ import logging +import os +import sys from tornado import httpserver from tornado import ioloop +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import flags from nova import server from nova import utils diff --git a/bin/nova-api-new b/bin/nova-api-new index fda42339c47e..8625c487fb4e 100755 --- a/bin/nova-api-new +++ b/bin/nova-api-new @@ -21,6 +21,17 @@ Nova API daemon. """ +import os +import sys + +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import api from nova import flags from nova import utils diff --git a/bin/nova-compute b/bin/nova-compute index ed9a55565b3d..631d2c85ce7d 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -21,6 +21,17 @@ Twistd daemon for the nova compute nodes. """ +import os +import sys + +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import twistd from nova.compute import service diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index 1f2ed4f890bb..0c3d987a7b44 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -25,10 +25,13 @@ import logging import os import sys -#TODO(joshua): there is concern that the user dnsmasq runs under will not -# have nova in the path. This should be verified and if it is -# not true the ugly line below can be removed -sys.path.append(os.path.abspath(os.path.join(__file__, "../../"))) +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) from nova import flags from nova import rpc diff --git a/bin/nova-import-canonical-imagestore b/bin/nova-import-canonical-imagestore index 2bc61cf0c1d6..4ed9e8365e02 100755 --- a/bin/nova-import-canonical-imagestore +++ b/bin/nova-import-canonical-imagestore @@ -29,6 +29,14 @@ import subprocess import sys import urllib2 +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import flags from nova import utils from nova.objectstore import image diff --git a/bin/nova-instancemonitor b/bin/nova-instancemonitor index fbac58889869..094da403344f 100755 --- a/bin/nova-instancemonitor +++ b/bin/nova-instancemonitor @@ -21,9 +21,19 @@ Daemon for Nova RRD based instance resource monitoring. """ +import os import logging +import sys from twisted.application import service +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import twistd from nova.compute import monitor diff --git a/bin/nova-manage b/bin/nova-manage index 145294d3d68c..d2fd49d8ddc4 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -22,9 +22,18 @@ Connects to the running ADMIN api in the api daemon. """ +import os import sys import time +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import flags from nova import utils from nova.auth import manager diff --git a/bin/nova-network b/bin/nova-network index 5753aafbebb2..307795d7bf11 100755 --- a/bin/nova-network +++ b/bin/nova-network @@ -21,6 +21,17 @@ Twistd daemon for the nova network nodes. """ +import os +import sys + +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import flags from nova import twistd diff --git a/bin/nova-objectstore b/bin/nova-objectstore index afcf13e24feb..447ef9055806 100755 --- a/bin/nova-objectstore +++ b/bin/nova-objectstore @@ -21,6 +21,17 @@ Twisted daemon for nova objectstore. Supports S3 API. """ +import os +import sys + +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import flags from nova import utils from nova import twistd diff --git a/bin/nova-volume b/bin/nova-volume index 8ef006ebcd18..f8e2e1744f3b 100755 --- a/bin/nova-volume +++ b/bin/nova-volume @@ -21,6 +21,17 @@ Twistd daemon for the nova volume nodes. """ +import os +import sys + +# If ../nova/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + from nova import twistd from nova.volume import service