Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
OpenEdx
configuration
Commits
0a103f88
Commit
0a103f88
authored
10 years ago
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial code to import courses that can be imported.
parent
be93e668
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
util/import_xml_courses.py
+72
-0
No files found.
util/import_xml_courses.py
0 → 100644
View file @
0a103f88
# Import XML Courses from git repos into the CMS.
# Run with sudo and make sure the user can clone
# the course repos.
import
argparse
import
logging
import
subprocess
from
os.path
import
basename
,
exists
,
join
from
os
import
chdir
from
getpass
import
getuser
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
"Import XML courses from git repos."
)
parser
.
add_argument
(
"-c"
,
"--courses-csv"
,
required
=
True
,
help
=
"A CSV of xml courses to import."
)
parser
.
add_argument
(
"-d"
,
"--data-dir"
,
required
=
True
,
help
=
"The location to checkout the repos for import."
)
args
=
parser
.
parse_args
()
courses
=
open
(
args
.
courses_csv
,
'r'
)
# Go to the platform dir.
# Need this for dealer to work.
chdir
(
"/edx/app/edxapp/edx-platform"
)
for
line
in
courses
:
cols
=
line
.
strip
()
.
split
(
','
)
slug
=
cols
[
0
]
author_format
=
cols
[
1
]
disposition
=
cols
[
2
]
repo_url
=
cols
[
4
]
if
author_format
.
lower
()
!=
'xml'
\
or
disposition
.
lower
()
==
"don't import"
\
or
disposition
.
lower
()
==
'on disk'
:
continue
logging
.
debug
(
"{}: {}"
.
format
(
slug
,
repo_url
))
org
,
course
,
run
=
slug
.
split
(
"/"
)
repo_name
=
"{}"
.
format
(
basename
(
repo_url
)
.
rstrip
(
'.git'
),
run
)
# Clone course into data dir.
repo_location
=
join
(
args
.
data_dir
,
repo_name
)
if
not
exists
(
repo_location
):
cmd
=
"git clone {} {}"
.
format
(
repo_url
,
repo_location
)
subprocess
.
check_call
(
cmd
,
shell
=
True
)
chown_cmd
=
"chown -R www-data:edxapp {}"
.
format
(
repo_location
)
subprocess
.
check_call
(
chown_cmd
,
shell
=
True
)
# Update course.xml
course_xml_path
=
join
(
repo_location
,
"course.xml"
)
xml_content
=
'<course org="{}" course="{}" url_name="{}"/>'
f
=
open
(
course_xml_path
,
'w'
)
f
.
write
(
xml_content
.
format
(
org
,
course
,
run
))
f
.
close
()
# Import the course
if
disposition
.
lower
()
==
"import"
:
# Import into cms
cmd
=
"sudo -E -u edxapp /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py cms --settings=aws import {} {}"
.
format
(
args
.
data_dir
,
repo_name
)
logging
.
debug
(
"Running cmd:: {}"
.
format
(
cmd
))
subprocess
.
check_call
(
cmd
,
shell
=
True
)
elif
disposition
.
lower
()
==
"no static import"
:
# Update courses.xml
# Import with --nostatic
cmd
=
"sudo -E -u edxapp /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py cms --settings=aws import --nostatic {} {}"
.
format
(
args
.
data_dir
,
repo_name
)
logging
.
debug
(
"Running cmd:: {}"
.
format
(
cmd
))
subprocess
.
check_call
(
cmd
,
shell
=
True
)
This diff is collapsed.
Click to expand it.
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