Annotate git export settings and toggles in CMS

We take the opportunity to resolve a few linting issues, without affecting the
feature behaviour.
This commit is contained in:
Régis Behmo
2021-01-29 12:26:50 +01:00
parent d1d7867ee6
commit 5a618bfdbb
6 changed files with 46 additions and 13 deletions

View File

@@ -22,9 +22,7 @@ from xmodule.modulestore.xml_exporter import export_course_to_xml
log = logging.getLogger(__name__)
GIT_REPO_EXPORT_DIR = getattr(settings, 'GIT_REPO_EXPORT_DIR', None)
GIT_EXPORT_DEFAULT_IDENT = getattr(settings, 'GIT_EXPORT_DEFAULT_IDENT',
{'name': 'STUDIO_EXPORT_TO_GIT',
'email': 'STUDIO_EXPORT_TO_GIT@example.com'})
GIT_EXPORT_DEFAULT_IDENT = settings.GIT_EXPORT_DEFAULT_IDENT
class GitExportError(Exception):
@@ -34,7 +32,7 @@ class GitExportError(Exception):
def __init__(self, message):
# Force the lazy i18n values to turn into actual unicode objects
super(GitExportError, self).__init__(six.text_type(message)) # lint-amnesty, pylint: disable=super-with-arguments
super().__init__(six.text_type(message))
NO_EXPORT_DIR = _(u"GIT_REPO_EXPORT_DIR not set or path {0} doesn't exist, "
"please create it, or configure a different path with "
@@ -110,7 +108,7 @@ def export_to_git(course_id, repo, user='', rdir=None):
branch = cmd_log(cmd, cwd).decode('utf-8').strip('\n')
except subprocess.CalledProcessError as ex:
log.exception(u'Failed to get branch: %r', ex.output)
raise GitExportError(GitExportError.DETACHED_HEAD) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.DETACHED_HEAD) from ex
cmds = [
['git', 'remote', 'set-url', 'origin', repo],
@@ -129,7 +127,7 @@ def export_to_git(course_id, repo, user='', rdir=None):
cmd_log(cmd, cwd)
except subprocess.CalledProcessError as ex:
log.exception(u'Failed to pull git repository: %r', ex.output)
raise GitExportError(GitExportError.CANNOT_PULL) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.CANNOT_PULL) from ex
# export course as xml before commiting and pushing
root_dir = os.path.dirname(rdirp)
@@ -149,7 +147,7 @@ def export_to_git(course_id, repo, user='', rdir=None):
except subprocess.CalledProcessError as ex:
log.exception(u'Failed to get branch from freshly cloned repo: %r',
ex.output)
raise GitExportError(GitExportError.MISSING_BRANCH) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.MISSING_BRANCH) from ex
# Now that we have fresh xml exported, set identity, add
# everything to git, commit, and push to the right branch.
@@ -171,15 +169,15 @@ def export_to_git(course_id, repo, user='', rdir=None):
cmd_log(['git', 'config', 'user.name', ident['name']], cwd)
except subprocess.CalledProcessError as ex:
log.exception(u'Error running git configure commands: %r', ex.output)
raise GitExportError(GitExportError.CONFIG_ERROR) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.CONFIG_ERROR) from ex
try:
cmd_log(['git', 'add', '.'], cwd)
cmd_log(['git', 'commit', '-a', '-m', commit_msg], cwd)
except subprocess.CalledProcessError as ex:
log.exception(u'Unable to commit changes: %r', ex.output)
raise GitExportError(GitExportError.CANNOT_COMMIT) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.CANNOT_COMMIT) from ex
try:
cmd_log(['git', 'push', '-q', 'origin', branch], cwd)
except subprocess.CalledProcessError as ex:
log.exception(u'Error running git push command: %r', ex.output)
raise GitExportError(GitExportError.CANNOT_PUSH) # lint-amnesty, pylint: disable=raise-missing-from
raise GitExportError(GitExportError.CANNOT_PUSH) from ex

View File

@@ -0,0 +1,20 @@
"""
CMS feature toggles.
"""
from edx_toggles.toggles import SettingDictToggle
# .. toggle_name: FEATURES['ENABLE_EXPORT_GIT']
# .. toggle_implementation: SettingDictToggle
# .. toggle_default: False
# .. toggle_description: When enabled, a "Export to Git" menu item is added to the course studio for courses that have a
# valid "giturl" attribute. Exporting a course to git causes the course to be exported in the directory indicated by
# the GIT_REPO_EXPORT_DIR setting. Note that when this feature is disabled, courses can still be exported to git with
# the git_export management command.
# .. toggle_warnings: To enable this feature, the GIT_REPO_EXPORT_DIR setting must be properly defined and point to an
# existing directory.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2014-02-13
EXPORT_GIT = SettingDictToggle(
"FEATURES", "ENABLE_EXPORT_GIT", default=False, module_name=__name__
)

View File

@@ -14,6 +14,7 @@ from django.utils.translation import ugettext as _
from six import text_type
from xblock.fields import Scope
from cms.djangoapps.contentstore import toggles
from openedx.core.lib.teams_config import TeamsetType
from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG
from common.djangoapps.student.roles import GlobalStaff
@@ -84,7 +85,7 @@ class CourseMetadata(object):
exclude_list = list(cls.FIELDS_EXCLUDE_LIST)
# Do not show giturl if feature is not enabled.
if not settings.FEATURES.get('ENABLE_EXPORT_GIT'):
if not toggles.EXPORT_GIT.is_enabled():
exclude_list.append('giturl')
# Do not show edxnotes if the feature is disabled.

View File

@@ -974,7 +974,19 @@ STATIC_URL_BASE = '/static/'
X_FRAME_OPTIONS = 'DENY'
# .. setting_name: GIT_REPO_EXPORT_DIR
# .. setting_default: '/edx/var/edxapp/export_course_repos'
# .. setting_description: When courses are exported to git, either with the export_git management command or the git
# export view from the studio (when FEATURES['ENABLE_EXPORT_GIT'] is True), they are stored in this directory, which
# must exist at the time of the export.
GIT_REPO_EXPORT_DIR = '/edx/var/edxapp/export_course_repos'
# .. setting_name: GIT_EXPORT_DEFAULT_IDENT
# .. setting_default: {'name': 'STUDIO_EXPORT_TO_GIT', 'email': 'STUDIO_EXPORT_TO_GIT@example.com'}
# .. setting_description: When courses are exported to git, commits are signed with this name/email git identity.
GIT_EXPORT_DEFAULT_IDENT = {
'name': 'STUDIO_EXPORT_TO_GIT',
'email': 'STUDIO_EXPORT_TO_GIT@example.com'
}
# Email
TECH_SUPPORT_EMAIL = 'technical@example.com'

View File

@@ -6,6 +6,7 @@
from django.conf import settings
from django.urls import reverse
from django.utils.translation import ugettext as _
from cms.djangoapps.contentstore import toggles
from openedx.core.djangoapps.lang_pref.api import header_language_selector_is_enabled, released_languages
%>
<div class="wrapper-header wrapper" id="view-top">
@@ -137,7 +138,7 @@
<li class="nav-item nav-course-tools-export">
<a href="${export_url}">${_("Export")}</a>
</li>
% if settings.FEATURES.get('ENABLE_EXPORT_GIT') and context_course.giturl:
% if toggles.EXPORT_GIT.is_enabled() and context_course.giturl:
<li class="nav-item nav-course-tools-export-git">
<a href="${reverse('export_git', kwargs=dict(course_key_string=six.text_type(course_key)))}">${_("Export to Git")}</a>
</li>

View File

@@ -13,6 +13,7 @@ from ratelimitbackend import admin
import openedx.core.djangoapps.common_views.xblock
import openedx.core.djangoapps.debug.views
import openedx.core.djangoapps.lang_pref.views
from cms.djangoapps.contentstore import toggles
from cms.djangoapps.contentstore import views as contentstore_views
from cms.djangoapps.contentstore.views.organization import OrganizationListView
from openedx.core.apidocs import api_info
@@ -210,7 +211,7 @@ if settings.FEATURES.get('ENABLE_CONTENT_LIBRARIES'):
contentstore_views.manage_library_users, name='manage_library_users'),
]
if settings.FEATURES.get('ENABLE_EXPORT_GIT'):
if toggles.EXPORT_GIT.is_enabled():
urlpatterns += [
url(r'^export_git/{}$'.format(settings.COURSE_KEY_PATTERN),
contentstore_views.export_git,