Commit e311dfa8 by Carson Gee

Adding additonal path to search for git information on sysadmin dashboard

When viewing the sysadmin dashboard courses tag, we also search the git
repository directory in addition to the DATA_DIR to try and find
the course git repo to get hash, last commit, and last editor information
for each loaded course if available.
parent f3952f2a
......@@ -21,7 +21,7 @@ from xmodule.modulestore import Location
log = logging.getLogger(__name__)
GIT_REPO_DIR = getattr(settings, 'GIT_REPO_DIR', '/opt/edx/course_repos')
GIT_REPO_DIR = getattr(settings, 'GIT_REPO_DIR', '/edx/var/app/edxapp/course_repos')
GIT_IMPORT_STATIC = getattr(settings, 'GIT_IMPORT_STATIC', True)
......
......@@ -27,6 +27,7 @@ from django.views.decorators.http import condition
from django_future.csrf import ensure_csrf_cookie
from edxmako.shortcuts import render_to_response
import mongoengine
from path import path
from courseware.courses import get_course_by_id
import dashboard.git_import as git_import
......@@ -333,8 +334,12 @@ class Courses(SysadminDashboardView):
cmd = ''
gdir = settings.DATA_DIR / cdir
info = ['', '', '']
if not os.path.exists(gdir):
return info
# Try the data dir, then try to find it in the git import dir
if not gdir.exists():
gdir = path(git_import.GIT_REPO_DIR) / cdir
if not gdir.exists():
return info
cmd = ['git', 'log', '-1',
'--format=format:{ "commit": "%H", "author": "%an %ae", "date": "%ad"}', ]
......@@ -348,7 +353,7 @@ class Courses(SysadminDashboardView):
return info
def get_course_from_git(self, gitloc, branch, datatable):
def get_course_from_git(self, gitloc, branch):
"""This downloads and runs the checks for importing a course in git"""
if not (gitloc.endswith('.git') or gitloc.startswith('http:') or
......@@ -359,7 +364,7 @@ class Courses(SysadminDashboardView):
if self.is_using_mongo:
return self.import_mongo_course(gitloc, branch)
return self.import_xml_course(gitloc, branch, datatable)
return self.import_xml_course(gitloc, branch)
def import_mongo_course(self, gitloc, branch):
"""
......@@ -411,7 +416,7 @@ class Courses(SysadminDashboardView):
msg += "<pre>{0}</pre>".format(escape(ret))
return msg
def import_xml_course(self, gitloc, branch, datatable):
def import_xml_course(self, gitloc, branch):
"""Imports a git course into the XMLModuleStore"""
msg = u''
......@@ -478,8 +483,7 @@ class Courses(SysadminDashboardView):
msg += u'<li><pre>{0}: {1}</pre></li>'.format(escape(summary),
escape(err))
msg += u'</ul>'
datatable['data'].append([course.display_name, cdir]
+ self.git_info_for_course(cdir))
return msg
def make_datatable(self):
......@@ -491,7 +495,7 @@ class Courses(SysadminDashboardView):
for (cdir, course) in courses.items():
gdir = cdir
if '/' in cdir:
gdir = cdir.rsplit('/', 1)[1]
gdir = cdir.split('/')[1]
data.append([course.display_name, cdir]
+ self.git_info_for_course(gdir))
......@@ -530,8 +534,7 @@ class Courses(SysadminDashboardView):
if action == 'add_course':
gitloc = request.POST.get('repo_location', '').strip().replace(' ', '').replace(';', '')
branch = request.POST.get('repo_branch', '').strip().replace(' ', '').replace(';', '')
datatable = self.make_datatable()
self.msg += self.get_course_from_git(gitloc, branch, datatable)
self.msg += self.get_course_from_git(gitloc, branch)
elif action == 'del_course':
course_id = request.POST.get('course_id', '').strip()
......@@ -575,10 +578,9 @@ class Courses(SysadminDashboardView):
self.msg += \
u"<font color='red'>{0} {1} = {2} ({3})</font>".format(
_('Deleted'), loc, course.id, course.display_name)
datatable = self.make_datatable()
context = {
'datatable': datatable,
'datatable': self.make_datatable(),
'msg': self.msg,
'djangopid': os.getpid(),
'modeflag': {'courses': 'active-section'},
......
......@@ -4,6 +4,7 @@ Provide tests for sysadmin dashboard feature in sysadmin.py
import glob
import os
import re
import shutil
import unittest
......@@ -454,6 +455,31 @@ class TestSysAdminMongoCourseImport(SysadminBaseTestCase):
course = def_ms.get_course('MITx/edx4edx/edx4edx')
self.assertIsNone(course)
def test_course_info(self):
"""
Check to make sure we are getting git info for courses
"""
# Regex of first 3 columns of course information table row for
# test course loaded from git. Would not have sha1 if
# git_info_for_course failed.
table_re = re.compile(r"""
<tr>\s+
<td>edX\sAuthor\sCourse</td>\s+ # expected test git course name
<td>MITx/edx4edx/edx4edx</td>\s+ # expected test git course_id
<td>[a-fA-F\d]{40}</td> # git sha1 hash
""", re.VERBOSE)
self._setstaff_login()
self._mkdir(getattr(settings, 'GIT_REPO_DIR'))
# Make sure we don't have any git hashes on the page
response = self.client.get(reverse('sysadmin_courses'))
self.assertNotRegexpMatches(response.content, table_re)
# Now add the course and make sure it does match
response = self._add_edx4edx()
self.assertRegexpMatches(response.content, table_re)
def test_gitlogs(self):
"""
Create a log entry and make sure it exists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment