79 lines
1.9 KiB
Python
Executable File
79 lines
1.9 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# python script to export course from CMS to github
|
|
#
|
|
# Usage: python cms_export_to_github <course_location> <username> <github_ssl_url> [<repo_dir>]
|
|
#
|
|
|
|
import os, sys, string, re
|
|
import datetime
|
|
|
|
DIR = "/mnt/data_export"
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# usage
|
|
|
|
def usage():
|
|
print "Usage: python cms_export_to_github <course_location> <username> <github_ssl_url> [<repo_dir>]"
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
try:
|
|
course_loc = sys.argv.pop(1)
|
|
username = sys.argv.pop(1)
|
|
repo = sys.argv.pop(1)
|
|
except:
|
|
usage()
|
|
sys.exit(0)
|
|
|
|
if course_loc.startswith('i4x://'):
|
|
course_loc = course_loc[6:]
|
|
|
|
m = re.match('git@[^ ]+\.git', repo)
|
|
if not m:
|
|
print "Oops, not a git ssh url?"
|
|
print repo
|
|
print "Expecting something like git@github.com:mitocw/edx4edx_lite.git"
|
|
sys.exit(-1)
|
|
|
|
if len(sys.argv)>1:
|
|
rdir = sys.argv.pop(1)
|
|
rdir = os.path.basename(rdir)
|
|
else:
|
|
rdir = repo.rsplit('/',1)[-1].rsplit('.git',1)[0]
|
|
print "rdir = %s" % rdir
|
|
|
|
rdirp = '%s/%s' % (DIR, rdir)
|
|
if os.path.exists(rdirp):
|
|
print "directory already exists, doing a git pull instead of git clone"
|
|
cmd = 'cd %s/%s; git pull' % (DIR, rdir)
|
|
else:
|
|
cmd = 'cd %s; git clone "%s"' % (DIR, repo)
|
|
|
|
print cmd
|
|
ret_git = os.popen(cmd).read()
|
|
print ret_git
|
|
|
|
if not os.path.exists('%s/%s' % (DIR, rdir)):
|
|
print "git clone failed!"
|
|
sys.exit(-1)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# export course
|
|
|
|
cmd = "./DJANGO-ADMIN-CMS export %s %s" % (course_loc, rdirp)
|
|
print cmd
|
|
ret_export = os.popen(cmd).read()
|
|
print ret_export
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# push to github
|
|
|
|
dt = datetime.datetime.now()
|
|
cmd = 'cd %s; git add .; git commit -a -m "(%s) Export %s"; git push' % (rdirp, username, dt)
|
|
print cmd
|
|
ret_push = os.popen(cmd).read()
|
|
print ret_push
|
|
|
|
|