Patchwork Get rid of hard-coded absolute paths.

login
register
mail settings
Submitter Guilherme Salgado
Date Feb. 28, 2011, 12:38 p.m.
Message ID <20110228123812.11579.866.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/84828/
State Accepted
Commit e84c31852aae3d1c79fe3cbb1aea2ca9646197ef
Headers show

Comments

Guilherme Salgado - Feb. 28, 2011, 12:38 p.m.
This is so that you don't have to change a dozen variables when you deploy an
instance somewhere other than on /srv/patchwork.

Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org>
---

(resending with a Signed-off-by line)

 apps/settings.py |   15 ++++++++++-----
 apps/urls.py     |   10 +++++++---
 2 files changed, 17 insertions(+), 8 deletions(-)
Jeremy Kerr - March 30, 2011, 6:11 a.m.
Hi Guilherme,

> This is so that you don't have to change a dozen variables when you deploy
> an instance somewhere other than on /srv/patchwork.

[snip]

> +# If you deploy somewhere other than /srv/patchwork you need to change the
> +# settings below, preferably on local_settings.py instead of here.
> +ROOT_DIR = '/srv/patchwork'

This isn't overridable by local_settings; the dependent settings will be 
generated before local_settings provides the new definition of ROOT_DIR.

If you're happy with that behaviour (that the user needs to change the value 
here, rather than in local_settings.py), then I'll remove this comment and 
commit. Otherwise, we'll have to think up some way of allowing a later over-
ride.

Cheers,


Jeremy
Guilherme Salgado - March 30, 2011, 2:01 p.m.
On Wed, 2011-03-30 at 14:11 +0800, Jeremy Kerr wrote:
> Hi Guilherme,
> 
> > This is so that you don't have to change a dozen variables when you deploy
> > an instance somewhere other than on /srv/patchwork.
> 
> [snip]
> 
> > +# If you deploy somewhere other than /srv/patchwork you need to change the
> > +# settings below, preferably on local_settings.py instead of here.
> > +ROOT_DIR = '/srv/patchwork'
> 
> This isn't overridable by local_settings; the dependent settings will be 
> generated before local_settings provides the new definition of ROOT_DIR.
> 
> If you're happy with that behaviour (that the user needs to change the value 
> here, rather than in local_settings.py), then I'll remove this comment and 
> commit. Otherwise, we'll have to think up some way of allowing a later over-
> ride.

Yeah, I'm happy with that behavior, but I think what I meant with the
comment is that one would have to change all 3 settings below, although
it might make more sense to move ROOT_DIR above the comment as
overriding it in local_settings does not make sense unless you use it in
your TEMPLATE_DIRS/MEDIA_ROOT, in which case you'll have to do so.

If you'd like I can submit a second version of this patch.

Cheers,

Patch

diff --git a/apps/settings.py b/apps/settings.py
index 68837b3..84a262c 100644
--- a/apps/settings.py
+++ b/apps/settings.py
@@ -1,4 +1,5 @@ 
 # Django settings for patchwork project.
+import os
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
@@ -34,10 +35,6 @@  SITE_ID = 1
 # to load the internationalization machinery.
 USE_I18N = True
 
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = '/srv/patchwork/lib/python/django/contrib/admin/media'
-
 # URL that handles the media served from MEDIA_ROOT.
 # Example: "http://media.lawrence.com"
 MEDIA_URL = ''
@@ -70,12 +67,20 @@  ROOT_URLCONF = 'apps.urls'
 LOGIN_URL = '/accounts/login'
 LOGIN_REDIRECT_URL = '/user/'
 
+# If you deploy somewhere other than /srv/patchwork you need to change the
+# settings below, preferably on local_settings.py instead of here.
+ROOT_DIR = '/srv/patchwork'
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    '/srv/patchwork/templates'
+    os.path.join(ROOT_DIR, 'templates')
 )
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.join(
+    ROOT_DIR, 'lib', 'python', 'django', 'contrib', 'admin', 'media')
+
 TEMPLATE_CONTEXT_PROCESSORS = (
     "django.core.context_processors.auth",
     "django.core.context_processors.debug",
diff --git a/apps/urls.py b/apps/urls.py
index 5c4ac57..3e82aa5 100644
--- a/apps/urls.py
+++ b/apps/urls.py
@@ -17,6 +17,8 @@ 
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import os
+
 from django.conf.urls.defaults import *
 from django.conf import settings
 from patchwork.admin import admin_site
@@ -25,6 +27,8 @@  from registration.views import register
 from patchwork.forms import RegistrationForm
 from patchwork.utils import userprofile_register_callback
 
+htdocs = os.path.join(settings.ROOT_DIR, 'htdocs')
+
 urlpatterns = patterns('',
     # Example:
     (r'^', include('patchwork.urls')),
@@ -42,10 +46,10 @@  urlpatterns = patterns('',
      (r'^admin/(.*)', admin_site.root),
 
      (r'^css/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/css'}),
+        {'document_root': os.path.join(htdocs, 'css')}),
      (r'^js/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/js'}),
+        {'document_root': os.path.join(htdocs, 'js')}),
      (r'^images/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/images'}),
+        {'document_root': os.path.join(htdocs, 'images')}),
 )