diff --git a/.gitignore b/.gitignore index 7023e877..c3490378 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tags *~ ChangeLog melange/vcsversion.py +requirements.txt diff --git a/bin/melange-delete-deallocated-ips b/bin/melange-delete-deallocated-ips index e8a08563..27400a36 100755 --- a/bin/melange-delete-deallocated-ips +++ b/bin/melange-delete-deallocated-ips @@ -26,11 +26,17 @@ This script can be run as a cron job on the melange server. """ -import logging +#TODO(jkoelker) Convert this to an entry_point + +import gettext import optparse import os import sys + +gettext.install('melange', unicode=1) + + # If ../melange/__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]), diff --git a/bin/melange-manage b/bin/melange-manage index f454ba63..60597e4c 100755 --- a/bin/melange-manage +++ b/bin/melange-manage @@ -16,11 +16,16 @@ # License for the specific language governing permissions and limitations # under the License. +#TODO(jkoelker) Convert this to an entry_point + +import gettext import optparse import os -import re import sys -import time + + +gettext.install('melange', unicode=1) + # If ../melange/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... @@ -32,7 +37,6 @@ if os.path.exists(os.path.join(possible_topdir, 'melange', '__init__.py')): from melange import version from melange.common import config -from melange.common import wsgi from melange.common import utils from melange.db import db_api diff --git a/bin/melange-server b/bin/melange-server index cb31095a..69e6eb05 100755 --- a/bin/melange-server +++ b/bin/melange-server @@ -16,11 +16,16 @@ # License for the specific language governing permissions and limitations # under the License. +#TODO(jkoelker) Convert this to an entry_point + +import gettext import optparse import os -import re import sys -import time + + +gettext.install('melange', unicode=1) + # If ../melange/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... diff --git a/melange/__init__.py b/melange/__init__.py index 75a5f221..2e34742b 100644 --- a/melange/__init__.py +++ b/melange/__init__.py @@ -14,25 +14,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - -import gettext -import pkgutil -import os - - -__path__ = pkgutil.extend_path(__path__, __name__) - - -gettext.install('melange', unicode=1) - - -def melange_root_path(): - return os.path.dirname(__file__) - - -def melange_bin_path(filename="."): - return os.path.join(melange_root_path(), "..", "bin", filename) - - -def melange_etc_path(filename="."): - return os.path.join(melange_root_path(), "..", "etc", "melange", filename) +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + from pkgutil import extend_path + __path__ = extend_path(__path__, __name__) diff --git a/melange/common/__init__.py b/melange/common/__init__.py index b6069570..2ceeca6b 100644 --- a/melange/common/__init__.py +++ b/melange/common/__init__.py @@ -14,3 +14,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import gettext + +gettext.install('melange', unicode=1) diff --git a/melange/tests/__init__.py b/melange/tests/__init__.py index 9f9a7d67..f08193ce 100644 --- a/melange/tests/__init__.py +++ b/melange/tests/__init__.py @@ -15,14 +15,37 @@ # License for the specific language governing permissions and limitations # under the License. -import mox +# See http://code.google.com/p/python-nose/issues/detail?id=373 +# The code below enables nosetests to work with i18n _() blocks +import __builtin__ +setattr(__builtin__, '_', lambda x: x) + +import os import unittest import urlparse +import mox + from melange.db import db_api from melange.common import utils +def melange_root_path(): + return os.path.join(os.path.dirname(__file__), "..", "..") + + +def melange_bin_path(filename="."): + return os.path.join(melange_root_path(), "bin", filename) + + +def melange_etc_path(filename="."): + return os.path.join(melange_root_path(), "etc", "melange", filename) + + +def test_config_file(): + return melange_etc_path("melange.conf.sample") + + class BaseTest(unittest.TestCase): def setUp(self): diff --git a/melange/tests/functional/__init__.py b/melange/tests/functional/__init__.py index 4f8a7cd1..af16d905 100644 --- a/melange/tests/functional/__init__.py +++ b/melange/tests/functional/__init__.py @@ -18,17 +18,13 @@ import os import subprocess -import melange +from melange import tests from melange.common import config from melange.db import db_api -def test_config_file(): - return melange.melange_etc_path("melange.conf.sample") - - def setup(): - options = dict(config_file=test_config_file()) + options = dict(config_file=tests.test_config_file()) _db_sync(options) _configure_db(options) @@ -60,7 +56,7 @@ def execute(cmd, raise_error=True): # Make sure that we use the programs in the # current source directory's bin/ directory. - env['PATH'] = melange.melange_bin_path() + ':' + env['PATH'] + env['PATH'] = tests.melange_bin_path() + ':' + env['PATH'] process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, diff --git a/melange/tests/functional/test_cli.py b/melange/tests/functional/test_cli.py index d5b9fd31..60e59eee 100644 --- a/melange/tests/functional/test_cli.py +++ b/melange/tests/functional/test_cli.py @@ -26,8 +26,8 @@ from melange.tests import functional def run_melange_manage(command): - melange_manage = melange.melange_bin_path('melange-manage') - config_file = functional.test_config_file() + melange_manage = tests.melange_bin_path('melange-manage') + config_file = tests.test_config_file() return functional.execute("%(melange_manage)s %(command)s " "--config-file=%(config_file)s" % locals()) @@ -56,8 +56,8 @@ class TestDeleteDeallocatedIps(tests.BaseTest): days = config.Config.get('keep_deallocated_ips_for_days') self._push_back_deallocated_date(ip, days) - script = melange.melange_bin_path('melange-delete-deallocated-ips') - config_file = functional.test_config_file() + script = tests.melange_bin_path('melange-delete-deallocated-ips') + config_file = tests.test_config_file() functional.execute("{0} --config-file={1}".format(script, config_file)) self.assertIsNone(models.IpAddress.get(ip.id)) diff --git a/melange/tests/unit/__init__.py b/melange/tests/unit/__init__.py index a81541c9..e4676d2c 100644 --- a/melange/tests/unit/__init__.py +++ b/melange/tests/unit/__init__.py @@ -15,25 +15,16 @@ # License for the specific language governing permissions and limitations # under the License. -# See http://code.google.com/p/python-nose/issues/detail?id=373 -# The code below enables nosetests to work with i18n _() blocks -import __builtin__ -setattr(__builtin__, '_', lambda x: x) - import json import webtest -import melange +from melange import tests from melange.common import config from melange.common import utils from melange.common import wsgi from melange.db import db_api -def test_config_path(): - return melange.melange_etc_path("melange.conf.sample") - - def sanitize(data): serializer = wsgi.JSONDictSerializer() return json.loads(serializer.serialize(data)) @@ -79,7 +70,7 @@ class TestApp(webtest.TestApp): def setup(): - options = {"config_file": test_config_path()} + options = {"config_file": tests.test_config_file()} conf = config.Config.load_paste_config("melangeapp", options, None) db_api.drop_db(conf) diff --git a/melange/tests/unit/test_extensions.py b/melange/tests/unit/test_extensions.py index 421e8bd9..500d6c42 100644 --- a/melange/tests/unit/test_extensions.py +++ b/melange/tests/unit/test_extensions.py @@ -19,15 +19,15 @@ import routes import unittest import webtest +from melange import tests from melange.common import config from melange.common import wsgi -from melange.tests import unit class TestExtensions(unittest.TestCase): def test_extension_loads_with_melange_xmlns(self): - options = {'config_file': unit.test_config_path()} + options = {'config_file': tests.test_config_file()} conf, app = config.Config.load_paste_app('melangeapi', options, None) test_app = webtest.TestApp(app) diff --git a/melange/tests/unit/test_ipam_service.py b/melange/tests/unit/test_ipam_service.py index 5076fd54..dbd7fb14 100644 --- a/melange/tests/unit/test_ipam_service.py +++ b/melange/tests/unit/test_ipam_service.py @@ -17,7 +17,6 @@ import string import unittest -import mox import netaddr import routes import webob.exc @@ -41,7 +40,7 @@ class ControllerTestBase(tests.BaseTest): def setUp(self): super(ControllerTestBase, self).setUp() conf, melange_app = config.Config.load_paste_app('melangeapp', - {"config_file": unit.test_config_path()}, None) + {"config_file": tests.test_config_file()}, None) self.app = unit.TestApp(melange_app) diff --git a/melange/tests/unit/test_versions.py b/melange/tests/unit/test_versions.py index 3406b634..ed068ac5 100644 --- a/melange/tests/unit/test_versions.py +++ b/melange/tests/unit/test_versions.py @@ -19,14 +19,13 @@ import webtest from melange.common import config from melange import tests -from melange.tests import unit class TestVersionsController(tests.BaseTest): def setUp(self): conf, melange_app = config.Config.load_paste_app('melange', - {"config_file": unit.test_config_path()}, None) + {"config_file": tests.test_config_file()}, None) self.test_app = webtest.TestApp(melange_app) super(TestVersionsController, self).setUp() diff --git a/setup.py b/setup.py index 76b57225..d2308312 100644 --- a/setup.py +++ b/setup.py @@ -96,4 +96,6 @@ setup(name='melange', 'bin/melange-manage', 'bin/melange-delete-deallocated-ips', ], - py_modules=[]) + py_modules=[], + namespace_packages=['melange'], + )