#!/usr/bin/python #create courseware from master folder #proceed by level: subject, course, milestone, activity from path import path import subprocess, os, sys from optparse import OptionParser parser = OptionParser(usage="Usage: %prog [options] file") (options, args) = parser.parse_args() if not args: SUBJECT = 'All' else: SUBJECT = args[0] COURSE = args[1] MAINPATH = path('/home/tony/Desktop/master') TARGET = path('/home/tony/courseware') BACKUP = path('/home/tony/courseware.bak') if SUBJECT == 'All': subprocess.call('rm -rf ' + BACKUP,shell=True) subprocess.call('mv ' + TARGET + ' ' + BACKUP, shell=True) subprocess.call('mkdir ' + TARGET, shell=True) #copy version to TARGET subprocess.call('cp ' + MAINPATH / 'version* ' + TARGET, shell=True) #courseware folder needs subjects.js, subject.html, and karma.zip subjectsfile = MAINPATH / 'subjects.js' subprocess.call('cp '+subjectsfile+' '+TARGET,shell=True) subprocess.call('cp '+ MAINPATH / 'index.html' + ' ' + TARGET,shell=True) cwd = MAINPATH cmd = 'zip -qr ' + TARGET / 'karma.zip' + ' karma' print cmd subprocess.call(cmd,cwd=cwd,shell=True) #create subject folders based on subjects.js fin = open(subjectsfile,'r') txt = fin.read() fin.close() lines = txt.split('\n') for line in lines: try: entry = eval(line)[0] except: continue if len(entry) < 3: entry = eval(line) subject = entry[1] sbj = entry[0] src = MAINPATH / subject if sbj == 'li': subprocess.call('cp -r ' + src + ' ' + TARGET,shell=True) continue tpth = TARGET / subject subprocess.call('mkdir ' + tpth, shell=True) subprocess.call('cp ' + src / 'index.html' + ' ' + tpth,shell=True) subprocess.call('cp ' + src / subject.lower()+'.png' + ' ' + tpth,shell=True) subprocess.call('cp ' + src / 'courses.js' + ' ' + tpth,shell=True) #create course folders for each course in courses.js fin = open(MAINPATH / subject / 'courses.js') txt = fin.read() fin.close() lines = txt.split('\n') for line in lines: try: entry = eval(line)[0] except: continue if len(entry)<4: entry = eval(line) coursename = entry[1] course = entry[0].lower() srcpth = MAINPATH / subject / course.lower() tgtpth = TARGET / subject / course print tgtpth subprocess.call('mkdir ' + tgtpth, shell=True) subprocess.call('cp ' + srcpth / 'index.html ' + tgtpth,shell=True) subprocess.call('cp ' + srcpth / 'milestones.js ' + tgtpth,shell=True) #now get milestones based on milestones.js fin = open(srcpth / 'milestones.js','r') txt = fin.read() fin.close() milestones = [] lines = txt.split('\n') for line in lines: try: entry = eval(line)[0] except: continue if len(entry)<3: entry = eval(line) milestones.append(entry) milestones.sort() for milestone in milestones: print 'milestone', milestone[4] cwd = srcpth cmd = 'zip -qr ' + tgtpth / milestone[4] + '.msxo ' + milestone[4] subprocess.call(cmd, cwd=cwd, shell=True) else: #we are doing one course #now get milestones based on milestones.js srcpth = MAINPATH / SUBJECT / COURSE tgtpth = TARGET / SUBJECT / COURSE #also copy to target folder subprocess.call('cp ' + srcpth / 'milestones.js ' + tgtpth,shell=True) fin = open(srcpth / 'milestones.js','r') txt = fin.read() fin.close() milestones = [] lines = txt.split('\n') for line in lines: try: entry = eval(line)[0] except: continue if len(entry)<3: entry = eval(line) milestones.append(entry) for milestone in milestones: print 'milestone', milestone[4] cwd = srcpth cmd = 'zip -qr ' + tgtpth / milestone[4] + '.msxo ' + milestone[4] subprocess.call(cmd, cwd=cwd, shell=True)