Skip to content

Commit

Permalink
ticket django-extensions#180 import error _make_writeable does not ex…
Browse files Browse the repository at this point in the history
…ist 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.
  • Loading branch information
trbs committed Feb 29, 2012
1 parent 58e4cd2 commit 37b5777
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion django_extensions/management/commands/create_app.py
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion 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


Expand Down
3 changes: 2 additions & 1 deletion 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):
Expand Down
17 changes: 17 additions & 0 deletions 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)

0 comments on commit 37b5777

Please sign in to comment.