Review Board

beta

Decouple 'uploaded/images' location from MEDIA_ROOT setting

Updated 1 month, 3 weeks ago

Chris Lamb Reviewers
reviewboard
None Review Board SVN
Adds 'UPLOADS_ROOT' configuration variable which decouples the 'uploaded/images' location from a being a suffix of MEDIA_ROOT.

This allows the upload directory to be overridden in local_settings.py, allowing multiple instances of Review Board on a system to share a system-wide installation containing the htdocs and media directories (ie. in the context of distributor packages).

For example, HTDOCS_ROOT and MEDIA_ROOT may point somewhere within /var/lib/ or /usr/share/, whilst a particular instance's UPLOAD_ROOT would point to (say) /srv/mysite.tld/uploads/

This change does not affect existing installations.

This diff additionally modifies the "chown" call to use ":" (colon) as the USER:GROUP seperator over the deprecated "." (period).
Tested locally with my (draft) Debian packages.

Diff revision 2 (Latest)

1 2
1 2

  1. /trunk/reviewboard/settings.py: 1 change [ 1 ]
  2. /trunk/reviewboard/test.py: 1 change [ 1 ]
  3. /trunk/reviewboard/admin/checks.py: 2 changes [ 1 2 ]
  4. /trunk/reviewboard/templates/admin/manual-updates/media-upload-dir.html: 4 changes [ 1 2 3 4 ]
/trunk/reviewboard/settings.py
Revision 1440 New Change
59
59
60
REVIEWBOARD_ROOT = os.path.abspath(os.path.split(__file__)[0])
60
REVIEWBOARD_ROOT = os.path.abspath(os.path.split(__file__)[0])
61
61
62
HTDOCS_ROOT = os.path.join(REVIEWBOARD_ROOT, 'htdocs')
62
HTDOCS_ROOT = os.path.join(REVIEWBOARD_ROOT, 'htdocs')
63
MEDIA_ROOT = os.path.join(HTDOCS_ROOT, 'media')
63
MEDIA_ROOT = os.path.join(HTDOCS_ROOT, 'media')
64
UPLOADS_ROOT = os.path.join(MEDIA_ROOT, 'uploaded')
64
65
65
# where is the site on your server ? - add the trailing slash.
66
# where is the site on your server ? - add the trailing slash.
66
SITE_ROOT = '/'
67
SITE_ROOT = '/'
67
68
68
TEMPLATE_DIRS = (
69
TEMPLATE_DIRS = (
/trunk/reviewboard/test.py
Revision 1440 New Change
56
56
57
    # Default to testing in a non-subdir install.
57
    # Default to testing in a non-subdir install.
58
    settings.SITE_ROOT = "/"
58
    settings.SITE_ROOT = "/"
59
    settings.MEDIA_ROOT = "/tmp/reviewboard-tests"
59
    settings.MEDIA_ROOT = "/tmp/reviewboard-tests"
60
60
61
    images_dir = os.path.join(settings.MEDIA_ROOT, "uploaded", "images")
61
    images_dir = os.path.join(settings.UPLOADS_ROOT, "images")
62
62
63
    if not os.path.exists(images_dir):
63
    if not os.path.exists(images_dir):
64
        os.makedirs(images_dir)
64
        os.makedirs(images_dir)
65
65
66
    settings.MEDIA_URL = settings.SITE_ROOT + 'media/'
66
    settings.MEDIA_URL = settings.SITE_ROOT + 'media/'
/trunk/reviewboard/admin/checks.py
Revision 1440 New Change
17
17
18
    if not _updates_required and not _install_fine:
18
    if not _updates_required and not _install_fine:
19
        # Check if there's a media/uploaded/images directory. If not, this is
19
        # Check if there's a media/uploaded/images directory. If not, this is
20
        # either a new install or is using the old-style media setup and needs
20
        # either a new install or is using the old-style media setup and needs
21
        # to be manually upgraded.
21
        # to be manually upgraded.
22
        uploaded_dir = os.path.join(settings.MEDIA_ROOT, "uploaded")
22
        uploaded_dir = os.path.join(settings.UPLOADS_ROOT)
23
23
24
        if not os.path.isdir(uploaded_dir) or \
24
        if not os.path.isdir(uploaded_dir) or \
25
           not os.path.isdir(os.path.join(uploaded_dir, "images")):
25
           not os.path.isdir(os.path.join(uploaded_dir, "images")):
26
            _updates_required.append((
26
            _updates_required.append((
27
                "admin/manual-updates/media-upload-dir.html", {
27
                "admin/manual-updates/media-upload-dir.html", {
28
                    'MEDIA_ROOT': settings.MEDIA_ROOT
28
                    'UPLOADS_ROOT': settings.UPLOADS_ROOT
29
                }
29
                }
30
            ))
30
            ))
31
31
32
32
33
        #
33
        #
/trunk/reviewboard/templates/admin/manual-updates/media-upload-dir.html
Revision 1440 New Change
1
{% load i18n %}
1
{% load i18n %}
2
<h1 class="title">{% trans "Media directory changes" %}</h1>
2
<h1 class="title">{% trans "Media directory changes" %}</h1>
3
<div class="main">
3
<div class="main">
4
 <p>
4
 <p>
5
{% blocktrans %}
5
{% blocktrans %}
6
  Your Review Board installation does not have a {{MEDIA_ROOT}}/uploaded/images directory.
6
  Your Review Board installation does not have a {{UPLOAD_ROOT}}/images directory.
7
{% endblocktrans %}
7
{% endblocktrans %}
8
 </p>
8
 </p>
9
 <h3>{% trans "If this is a new installation..." %}</h3>
9
 <h3>{% trans "If this is a new installation..." %}</h3>
10
 <p>
10
 <p>
11
{% blocktrans %}
11
{% blocktrans %}
12
  Create both <tt>{{MEDIA_ROOT}}/uploaded</tt> and
12
  Create both <tt>{{UPLOAD_ROOT}}</tt> and
13
  <tt>{{MEDIA_ROOT}}/uploaded/images</tt> on the server and make both directories writable by the web
13
  <tt>{{UPLOAD_ROOT}}/images</tt> on the server and make both directories writable by the web
14
  server. You can do so with the following commands:
14
  server. You can do so with the following commands:
15
{% endblocktrans %}
15
{% endblocktrans %}
16
 </p>
16
 </p>
17
 <pre>
17
 <pre>
18
  $ cd {{MEDIA_ROOT}}
18
  $ mkdir -p {{UPLOAD_ROOT}}/images
19
  $ mkdir -p uploaded/images
19
  $ sudo chown -R www-data:www-data {{UPLOAD_ROOT}}
20
  $ sudo chown -R www-data.www-data uploaded
21
 </pre>
20
 </pre>
22
 <h3>{% trans "If this is an existing installation..." %}</h3>
21
 <h3>{% trans "If this is an existing installation..." %}</h3>
23
 <p>
22
 <p>
24
{% blocktrans %}
23
{% blocktrans %}
25
  A recent update has changed the media setup on the server. This may require manual updates to
24
  A recent update has changed the media setup on the server. This may require manual updates to
26
  the web server configuration. Please see the "Media Changes" section on the
25
  the web server configuration. Please see the "Media Changes" section on the
27
  <a href="http://code.google.com/p/reviewboard/wiki/RequiredServerUpdates">Required Server
26
  <a href="http://code.google.com/p/reviewboard/wiki/RequiredServerUpdates">Required Server
28
  Updates</a> page for instructions on fixing your setup.
27
  Updates</a> page for instructions on fixing your setup.
29
{% endblocktrans %}
28
{% endblocktrans %}
30
 </p>
29
 </p>
31
</div>
30
</div>
  1. /trunk/reviewboard/settings.py: 1 change [ 1 ]
  2. /trunk/reviewboard/test.py: 1 change [ 1 ]
  3. /trunk/reviewboard/admin/checks.py: 2 changes [ 1 2 ]
  4. /trunk/reviewboard/templates/admin/manual-updates/media-upload-dir.html: 4 changes [ 1 2 3 4 ]