diff --git a/cms/djangoapps/contentstore/git_export_utils.py b/cms/djangoapps/contentstore/git_export_utils.py index 470d3ac27c..bf39bbb901 100644 --- a/cms/djangoapps/contentstore/git_export_utils.py +++ b/cms/djangoapps/contentstore/git_export_utils.py @@ -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 diff --git a/cms/djangoapps/contentstore/toggles.py b/cms/djangoapps/contentstore/toggles.py new file mode 100644 index 0000000000..248843cc76 --- /dev/null +++ b/cms/djangoapps/contentstore/toggles.py @@ -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__ +) diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index 534f182799..61e37e5998 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -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. diff --git a/cms/envs/common.py b/cms/envs/common.py index 9255b03eae..8ab6f935ce 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -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' diff --git a/cms/templates/widgets/header.html b/cms/templates/widgets/header.html index 53e00d9e74..36665df0ff 100644 --- a/cms/templates/widgets/header.html +++ b/cms/templates/widgets/header.html @@ -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 %>