Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/generate
blob: a24030091d7796a00cbd167ee3e2be2f13245996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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)