From 37b57779dc58a0c2b8623092eccbb91076955f4d Mon Sep 17 00:00:00 2001 From: trbs Date: Wed, 29 Feb 2012 20:23:47 +0100 Subject: [PATCH] ticket #180 import error _make_writeable does not exist in django 1.4-beta the _make_writeable function has been inlined into TemplateCommand class in the django 1.4 and up. we should probably rewrite the commands to use the TemplateCommand class instead of duplicating code. But for now I moved the _make_writeable function to django_extensions.management.utils so that the existing commands keep working with Django 1.4 and up. --- .../management/commands/create_app.py | 3 ++- .../management/commands/create_command.py | 3 ++- .../management/commands/create_jobs.py | 3 ++- django_extensions/management/utils.py | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/django_extensions/management/commands/create_app.py b/django_extensions/management/commands/create_app.py index 67b20f8d1..8668201e8 100644 --- a/django_extensions/management/commands/create_app.py +++ b/django_extensions/management/commands/create_app.py @@ -3,10 +3,11 @@ import django_extensions from django.conf import settings from django.db import connection -from django.core.management.base import CommandError, LabelCommand, _make_writeable +from django.core.management.base import CommandError, LabelCommand from django.template import Template, Context from django_extensions.settings import REPLACEMENTS from django_extensions.utils.dia2django import dia2django +from django_extensions.management.utils import _make_writeable from optparse import make_option diff --git a/django_extensions/management/commands/create_command.py b/django_extensions/management/commands/create_command.py index d77c2646e..b0a6d16bb 100644 --- a/django_extensions/management/commands/create_command.py +++ b/django_extensions/management/commands/create_command.py @@ -1,5 +1,6 @@ import os -from django.core.management.base import CommandError, AppCommand, _make_writeable +from django.core.management.base import CommandError, AppCommand +from django_extensions.management.utils import _make_writeable from optparse import make_option diff --git a/django_extensions/management/commands/create_jobs.py b/django_extensions/management/commands/create_jobs.py index c3c363aee..cc87247d6 100644 --- a/django_extensions/management/commands/create_jobs.py +++ b/django_extensions/management/commands/create_jobs.py @@ -1,6 +1,7 @@ import os import sys -from django.core.management.base import CommandError, AppCommand, _make_writeable +from django.core.management.base import CommandError, AppCommand +from django_extensions.management.utils import _make_writeable class Command(AppCommand): diff --git a/django_extensions/management/utils.py b/django_extensions/management/utils.py index d8286b219..b829e3287 100644 --- a/django_extensions/management/utils.py +++ b/django_extensions/management/utils.py @@ -1,8 +1,25 @@ from django.conf import settings import os +import sys def get_project_root(): """ get the project root directory """ settings_mod = __import__(settings.SETTINGS_MODULE, {}, {}, ['']) return os.path.dirname(os.path.abspath(settings_mod.__file__)) + +def _make_writeable(filename): + """ + Make sure that the file is writeable. Useful if our source is + read-only. + + """ + import stat + if sys.platform.startswith('java'): + # On Jython there is no os.access() + return + if not os.access(filename, os.W_OK): + st = os.stat(filename) + new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR + os.chmod(filename, new_permissions) +