Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/generate
diff options
context:
space:
mode:
Diffstat (limited to 'generate')
-rwxr-xr-xgenerate150
1 files changed, 150 insertions, 0 deletions
diff --git a/generate b/generate
new file mode 100755
index 0000000..a240300
--- /dev/null
+++ b/generate
@@ -0,0 +1,150 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#this program generates activities for a course based on milestones.js and activities.js
+#it calls different generators depending on the activity type:
+#currently Karma, basic, Sugar or EPaath (Flash)
+
+import sys, subprocess
+from optparse import OptionParser
+from path import path
+from generate_basic_lesson import generateBasicLesson
+from generate_karma_lesson import process_description
+from generate_karma_lesson import KarmaFramework
+#
+SOURCE = path('/home/tony/Desktop/git/newcontent')
+#SOURCE = path('/home/tony/testcontent')
+TARGET = path('/home/tony/Desktop/master')
+#TARGET = path('/home/tony/testmaster')
+MENUS = path('/home/tony/Desktop/git/generate/menus')
+
+def copyFiles(src, dst, files):
+ for file in files:
+ srcpth = path(src) / file
+ dstpth = path(dst) / file
+ rmcmd = 'rm -rf ' + dstpth
+ cpcmd = 'cp -r ' + srcpth + ' ' + dstpth
+ if srcpth.exists():
+ if dstpth.exists():
+ subprocess.call(rmcmd, shell=True)
+ subprocess.call(cpcmd, shell=True)
+
+def get_entries(srcpth):
+ fin = open(srcpth,'r')
+ txt = fin.read()
+ fin.close()
+ lines = txt.split('\n')
+ entries = []
+ for line in lines:
+ try:
+ entry = eval(line)[0]
+ except:
+ continue
+ if len(entry) < 3:
+ entry = eval(line)
+ entries.append(entry)
+ return entries
+
+parser = OptionParser(usage="Usage: %prog [options] file")
+(options, args) = parser.parse_args()
+if not args:
+ print 'Specify a course (e.g. enp411 as an argument.'
+ parser.print_help()
+ sys.exit(1)
+
+SUBJECT = args[0]
+COURSE = args[1].lower()
+#update version
+cmd = 'git shortlog'
+pipe = 'subprocess.PIPE'
+pid = subprocess.Popen(cmd, cwd=SOURCE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
+pid.wait()
+(result,err) = pid.communicate()
+lines = result.split('\n')
+version = lines[len(lines)-3].strip()
+files = SOURCE.files('version*')
+for file in files:
+ subprocess.call('rm ' + file,shell=True)
+files = TARGET.files('version*')
+for file in files:
+ subprocess.call('rm ' + file,shell=True)
+fout = open(SOURCE / version,'w')
+fout.write('')
+fout.close()
+cmd = 'cp ' + SOURCE / version + ' ' + TARGET
+print cmd
+subprocess.call(cmd, shell=True)
+print 'reset basic files'
+#reset basic files
+cmd = 'cp ' + MENUS / 'subject.html ' + TARGET / 'index.html'
+subprocess.call(cmd, shell=True)
+fileList = ['subjects.js', 'karma']
+copyFiles(SOURCE, TARGET, fileList)
+subprocess.call('cp ' + SOURCE / 'version-* ' + TARGET,shell=True)
+#setup subjects
+subjects = get_entries(SOURCE / 'subjects.js')
+for entry in subjects:
+ subject = entry[1]
+ subprocess.call('mkdir -p ' + TARGET /subject, shell=True)
+ #copy icons
+ cmd = 'cp ' + SOURCE / subject / subject.lower() + '.png ' + TARGET / subject
+ subprocess.call(cmd, shell=True)
+ if subject == 'Library':
+ continue
+ #copy index.html
+ cmd = 'cp ' + MENUS / 'course.html ' + TARGET / subject / 'index.html'
+ subprocess.call(cmd, shell=True)
+ #copy courses.js
+ subprocess.call('cp ' + SOURCE / subject / 'courses.js ' + TARGET / subject, shell=True)
+#create folder in TARGET (master) for SUBJECT COURSE
+spth = SOURCE / SUBJECT / COURSE
+tpth = TARGET / SUBJECT / COURSE
+subprocess.call('rm -rf ' + tpth + '/*',shell=True)
+subprocess.call('mkdir -p ' + tpth, shell=True)
+#copy milestones.js to dst
+subprocess.call('cp ' + spth / 'milestones.js ' + tpth, shell=True)
+#copy index.html to dst
+subprocess.call('cp ' + MENUS / 'milestone.html ' + tpth / 'index.html',shell=True)
+#make list of milestones from milestones.js
+milestones = get_entries(spth / 'milestones.js')
+print 'milestones',len(milestones)
+count = 0
+for entry in milestones:
+ milestone = entry[4]
+ dstms = tpth / milestone
+ srcms = spth / milestone
+ #create target milestone folder
+ try:
+ subprocess.call('rm -rf ' + dstms, shell=True)
+ subprocess.call('mkdir ' + dstms, shell=True)
+ except:
+ print 'make',dstms,'failed',sys.exc_info()[:2]
+ #copy activities.js to activity folder
+ subprocess.call('cp '+ srcms / 'activities.js ' + dstms,shell=True)
+ #copy index.html to activity folder
+ cmd = 'cp ' + MENUS / 'activity.html ' + dstms / 'index.html'
+ subprocess.call(cmd ,shell=True)
+ #get list of activities in milestone
+ activities = get_entries(srcms / 'activities.js')
+ for entry in activities:
+ activity = entry[4]
+ activity_type = entry[3]
+ print 'milestone',milestone,'activity',activity,'activity_type', activity_type
+ #generate activities
+ src = srcms / activity
+ dst = dstms / activity
+ act = path('content') / SUBJECT / COURSE / milestone / activity
+ karmapth = SOURCE / 'karma'
+ subprocess.call('mkdir ' + dst,shell=True)
+ #switch based on activity type
+ if activity_type == 'basic':
+ generateBasicLesson(act, src,dst)
+ elif activity_type == 'Karma':
+ karma = KarmaFramework(karmapth)
+ process_description(karma,src / 'description.py', dst)
+ elif activity_type == 'EPaath':
+ generate-EPaath-lesson(src,dst)
+ else: #copy activity to master
+ subprocess.call('cp -r ' + src + '/* ' + dst, shell=True)
+
+
+