Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/zipper.py
blob: a9f82c1044d2e0ef0a85bf136144d64f177b22c5 (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
#!/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)