Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
39e5a776
Commit
39e5a776
authored
Jul 26, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make github_sync use a namedtuple for repo settings
parent
c9e637d7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
41 deletions
+27
-41
cms/djangoapps/github_sync/__init__.py
+14
-15
cms/djangoapps/github_sync/exceptions.py
+4
-0
cms/djangoapps/github_sync/tests/__init__.py
+3
-5
cms/envs/dev.py
+6
-21
No files found.
cms/djangoapps/github_sync/__init__.py
View file @
39e5a776
...
...
@@ -7,34 +7,33 @@ from git import Repo, PushInfo
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
from
collections
import
namedtuple
from
.exceptions
import
GithubSyncError
from
.exceptions
import
GithubSyncError
,
InvalidRepo
log
=
logging
.
getLogger
(
__name__
)
RepoSettings
=
namedtuple
(
'RepoSettings'
,
'path branch origin'
)
def
setup_repo
(
repo_settings
):
"""
Reset the local github repo specified by repo_settings
repo_settings is a dictionary with the following keys:
path: file system path to the local git repo
branch: name of the branch to track on github
origin: git url for the repository to track
repo_settings (RepoSettings): The settings for the repo to reset
"""
course_dir
=
repo_settings
[
'path'
]
course_dir
=
repo_settings
.
path
repo_path
=
settings
.
GITHUB_REPO_ROOT
/
course_dir
if
not
os
.
path
.
isdir
(
repo_path
):
Repo
.
clone_from
(
repo_settings
[
'origin'
]
,
repo_path
)
Repo
.
clone_from
(
repo_settings
.
origin
,
repo_path
)
git_repo
=
Repo
(
repo_path
)
origin
=
git_repo
.
remotes
.
origin
origin
.
fetch
()
# Do a hard reset to the remote branch so that we have a clean import
git_repo
.
git
.
checkout
(
repo_settings
[
'branch'
]
)
git_repo
.
git
.
checkout
(
repo_settings
.
branch
)
return
git_repo
...
...
@@ -43,19 +42,19 @@ def load_repo_settings(course_dir):
"""
Returns the repo_settings for the course stored in course_dir
"""
for
repo_settings
in
settings
.
REPOS
.
values
()
:
if
repo_settings
[
'path'
]
==
course_dir
:
return
repo_settings
r
aise
InvalidRepo
(
course_dir
)
if
course_dir
not
in
settings
.
REPOS
:
raise
InvalidRepo
(
course_dir
)
r
eturn
RepoSettings
(
course_dir
,
**
settings
.
REPOS
[
course_dir
]
)
def
import_from_github
(
repo_settings
):
"""
Imports data into the modulestore based on the XML stored on github
"""
course_dir
=
repo_settings
[
'path'
]
course_dir
=
repo_settings
.
path
git_repo
=
setup_repo
(
repo_settings
)
git_repo
.
head
.
reset
(
'origin/
%
s'
%
repo_settings
[
'branch'
]
,
index
=
True
,
working_tree
=
True
)
git_repo
.
head
.
reset
(
'origin/
%
s'
%
repo_settings
.
branch
,
index
=
True
,
working_tree
=
True
)
module_store
=
import_from_xml
(
modulestore
(),
settings
.
GITHUB_REPO_ROOT
,
course_dirs
=
[
course_dir
])
...
...
cms/djangoapps/github_sync/exceptions.py
View file @
39e5a776
class
GithubSyncError
(
Exception
):
pass
class
InvalidRepo
(
Exception
):
pass
cms/djangoapps/github_sync/tests/__init__.py
View file @
39e5a776
from
django.test
import
TestCase
from
path
import
path
import
shutil
import
os
from
github_sync
import
import_from_github
,
export_to_github
from
github_sync
import
import_from_github
,
export_to_github
,
load_repo_settings
from
git
import
Repo
from
django.conf
import
settings
from
xmodule.modulestore.django
import
modulestore
...
...
@@ -16,8 +15,7 @@ REMOTE_DIR = WORKING_DIR / 'remote_repo'
@override_settings
(
REPOS
=
{
'local'
:
{
'path'
:
'local_repo'
,
'local_repo'
:
{
'origin'
:
REMOTE_DIR
,
'branch'
:
'master'
,
}
...
...
@@ -40,7 +38,7 @@ class GithubSyncTestCase(TestCase):
remote
.
git
.
commit
(
m
=
'Initial commit'
)
remote
.
git
.
config
(
"receive.denyCurrentBranch"
,
"ignore"
)
self
.
import_revision
,
self
.
import_course
=
import_from_github
(
settings
.
REPOS
[
'local'
]
)
self
.
import_revision
,
self
.
import_course
=
import_from_github
(
load_repo_settings
(
'local_repo'
)
)
def
tearDown
(
self
):
self
.
cleanup
()
...
...
cms/envs/dev.py
View file @
39e5a776
...
...
@@ -32,38 +32,23 @@ DATABASES = {
REPOS
=
{
'edx4edx'
:
{
'path'
:
"edx4edx"
,
'org'
:
'edx'
,
'course'
:
'edx4edx'
,
'branch'
:
'for_cms'
,
'branch'
:
'master'
,
'origin'
:
'git@github.com:MITx/edx4edx.git'
,
},
'6002x-fall-2012'
:
{
'path'
:
'6002x-fall-2012'
,
'org'
:
'mit.edu'
,
'course'
:
'6.002x'
,
'branch'
:
'for_cms'
,
'content-mit-6002x'
:
{
'branch'
:
'master'
,
'origin'
:
'git@github.com:MITx/6002x-fall-2012.git'
,
},
'6.00x'
:
{
'path'
:
'6.00x'
,
'org'
:
'mit.edu'
,
'course'
:
'6.00x'
,
'branch'
:
'for_cms'
,
'branch'
:
'master'
,
'origin'
:
'git@github.com:MITx/6.00x.git'
,
},
'7.00x'
:
{
'path'
:
'7.00x'
,
'org'
:
'mit.edu'
,
'course'
:
'7.00x'
,
'branch'
:
'for_cms'
,
'branch'
:
'master'
,
'origin'
:
'git@github.com:MITx/7.00x.git'
,
},
'3.091x'
:
{
'path'
:
'3.091x'
,
'org'
:
'mit.edu'
,
'course'
:
'3.091x'
,
'branch'
:
'for_cms'
,
'branch'
:
'master'
,
'origin'
:
'git@github.com:MITx/3.091x.git'
,
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment