From 6bd9cd6c2892cf53be2614fed61a03f7621acdb4 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 26 Jul 2012 15:31:51 -0400 Subject: [PATCH] Add management command for syncing with github --- .../contentstore/management/commands/import.py | 2 +- cms/djangoapps/github_sync/__init__.py | 18 ++++++++++++++++++ .../github_sync/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/sync_with_github.py | 14 ++++++++++++++ cms/djangoapps/github_sync/views.py | 9 ++++----- cms/envs/common.py | 1 + 7 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 cms/djangoapps/github_sync/management/__init__.py create mode 100644 cms/djangoapps/github_sync/management/commands/__init__.py create mode 100644 cms/djangoapps/github_sync/management/commands/sync_with_github.py diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 0e4dc5cc89..6be03b7850 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -1,5 +1,5 @@ ### -### One-off script for importing courseware form XML format +### Script for importing courseware form XML format ### from django.core.management.base import BaseCommand, CommandError diff --git a/cms/djangoapps/github_sync/__init__.py b/cms/djangoapps/github_sync/__init__.py index bf6e2114b3..e3215cbec1 100644 --- a/cms/djangoapps/github_sync/__init__.py +++ b/cms/djangoapps/github_sync/__init__.py @@ -16,6 +16,24 @@ log = logging.getLogger(__name__) RepoSettings = namedtuple('RepoSettings', 'path branch origin') +def sync_all_with_github(): + """ + Sync all defined repositories from github + """ + for repo_name in settings.REPOS: + sync_with_github(load_repo_settings(repo_name)) + + +def sync_with_github(repo_settings): + """ + Sync specified repository from github + + repo_settings: A RepoSettings defining which repo to sync + """ + revision, course = import_from_github(repo_settings) + export_to_github(course, "Changes from cms import of revision %s" % revision, "CMS ") + + def setup_repo(repo_settings): """ Reset the local github repo specified by repo_settings diff --git a/cms/djangoapps/github_sync/management/__init__.py b/cms/djangoapps/github_sync/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cms/djangoapps/github_sync/management/commands/__init__.py b/cms/djangoapps/github_sync/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cms/djangoapps/github_sync/management/commands/sync_with_github.py b/cms/djangoapps/github_sync/management/commands/sync_with_github.py new file mode 100644 index 0000000000..4383871df3 --- /dev/null +++ b/cms/djangoapps/github_sync/management/commands/sync_with_github.py @@ -0,0 +1,14 @@ +### +### Script for syncing CMS with defined github repos +### + +from django.core.management.base import NoArgsCommand +from github_sync import sync_all_with_github + + +class Command(NoArgsCommand): + help = \ +'''Sync the CMS with the defined github repos''' + + def handle_noargs(self, **options): + sync_all_with_github() diff --git a/cms/djangoapps/github_sync/views.py b/cms/djangoapps/github_sync/views.py index e4cae6cad8..941d50f986 100644 --- a/cms/djangoapps/github_sync/views.py +++ b/cms/djangoapps/github_sync/views.py @@ -5,7 +5,7 @@ from django.http import HttpResponse from django.conf import settings from django_future.csrf import csrf_exempt -from . import import_from_github, export_to_github +from . import sync_with_github, load_repo_settings log = logging.getLogger() @@ -40,13 +40,12 @@ def github_post_receive(request): log.info('No repository matching %s found' % repo_name) return HttpResponse('No Repo Found') - repo = settings.REPOS[repo_name] + repo = load_repo_settings(repo_name) - if repo['branch'] != branch_name: + if repo.branch != branch_name: log.info('Ignoring changes to non-tracked branch %s in repo %s' % (branch_name, repo_name)) return HttpResponse('Ignoring non-tracked branch') - revision, course = import_from_github(repo) - export_to_github(course, repo['path'], "Changes from cms import of revision %s" % revision) + sync_with_github(repo) return HttpResponse('Push received') diff --git a/cms/envs/common.py b/cms/envs/common.py index 582cb75abf..e7609c517f 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -309,6 +309,7 @@ INSTALLED_APPS = ( # For CMS 'contentstore', + 'github_sync', 'student', # misleading name due to sharing with lms # For asset pipelining