Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Anderson <tony@traveler.(none)>2011-01-13 06:56:09 (GMT)
committer Tony Anderson <tony@traveler.(none)>2011-01-13 06:56:09 (GMT)
commitd07ce9b4a937c64e6d96e17f67a8738c2a5d21f8 (patch)
treec3f06ec036e30aa2809b366c1cf8bfad7c67e174
parent47e975f01d100d7d0af852774343d6a5f359255a (diff)
initial working version
-rwxr-xr-xcgi-bin/activities.py125
-rwxr-xr-xcgi-bin/fetchFile.py4
-rwxr-xr-xcgi-bin/fetch_milestone.py198
-rwxr-xr-xcgi-bin/getIndex.py2
-rwxr-xr-xcgi-bin/gettree.py2
-rwxr-xr-xcgi-bin/results.py425
-rwxr-xr-xcontent/index.html3
-rwxr-xr-xcontent/js/global.js12
-rwxr-xr-xcontent/js/learner_lesson.js6
-rwxr-xr-xcontent/js/learner_subject.js22
-rwxr-xr-xcontent/js/lesson.js5
-rwxr-xr-xcontent/js/subject.js35
-rwxr-xr-xcontent/menu.css12
-rwxr-xr-xlaunch.py208
-rw-r--r--menu/faculty_menu2
15 files changed, 552 insertions, 509 deletions
diff --git a/cgi-bin/activities.py b/cgi-bin/activities.py
new file mode 100755
index 0000000..35b9d05
--- /dev/null
+++ b/cgi-bin/activities.py
@@ -0,0 +1,125 @@
+#!/usr/bin/python
+
+import os, sys, subprocess
+from sugar.activity import activity
+from path import path
+
+DATAPATH = path(activity.get_activity_root())/ 'data'
+WORKPATH = DATAPATH / 'work'
+USB = path('/media/2011/courseware')
+SS = path('/library/courseware')
+
+#executes sftp command contained in scrpt
+#note scrpt must be written to disk and read by sftp command
+def sftp(script, folder = None):
+ pth = WORKPATH / 'script'
+ subprocess.call('rm -rf ' + pth, shell=True)
+ fout = open(pth, 'w')
+ fout.write(script)
+ fout.close()
+ authpth = '/home/olpc/.sugar/default/owner.key'
+ auth = ' -oIdentityFile=' + authpth
+ scrpt = ' -b ' + pth
+ fin = open('/ofw/serial-number','r')
+ serial_number = fin.read()
+ fin.close()
+ srvr = serial_number[:-1] + '@schoolserver'
+ cmd = 'sftp ' + auth + scrpt + ' ' + srvr
+ if folder:
+ subprocess.call(cmd, cwd=folder, shell=True)
+ else:
+ subprocess.call(cmd, shell=True)
+ return 0
+
+def getInstalled(subject):
+ pth = path('content') / subject
+ temp = pth.dirs()
+ milestones = []
+ for item in temp:
+ milestones.append(str(item.namebase))
+ milestones.remove('karma')
+ return milestones
+
+def getEntries(subject, milestone):
+ pth = path('content') /subject
+ if len(milestone) > 0:
+ fpth = pth / milestone / 'activities.js'
+ else:
+ fpth = pth / 'activities.js'
+ fin = open(fpth,'r')
+ txt = fin.read()
+ fin.close()
+ entries = []
+ lines = txt.split('\n')
+ for line in lines:
+ try:
+ entry = eval(line)[0]
+ entries.append(entry)
+ except:
+ continue
+ return entries
+
+def setEntries(subject, grade, milestone, entries):
+ pth = path('content') /subject
+ if len(milestone) > 0:
+ fpth = pth / milestone / 'activities.js'
+ else:
+ fpth = pth / 'activities.js'
+ fin = open(fpth,'r')
+ txt = fin.read()
+ fin.close()
+ txtout = 'var activities = [\n'
+ for entry in entries:
+ txtout = txtout + str(entry) + ',\n'
+ txtout = txtout + '];\nvar assetList = [];\nvar logos = [];\n'
+ fout = open(fpth,'w')
+ fout.write(txtout)
+ fout.close()
+ if grade > 0:
+ fout = open(pth /milestone / 'activities_'+grade+'.js','w')
+ fout.write(txtout)
+ fout.close()
+
+def getMilestones(subject):
+ milestones = getEntries(subject, "")
+ return milestones
+
+def getActivities(subject, milestone):
+ activities = getEntries(subject, milestone)
+ return activities
+
+def setMilestones(subject, grade, milestones):
+ setEntries(subject,grade, "", milestones)
+
+def setActivities(subject, milestone, activities):
+ setEntries(subject, 0, milestone, activities)
+
+def fetchMilestone(subject, grade, milestone):
+ if USB.exists(): #get from usb drive
+ pth = USB / subject
+ cmd = 'cp -r ' + pth / milestone + '.msxo ' + 'content/'+ subject
+ try:
+ subprocess.call(cmd,shell=True)
+ except:
+ print 'failed',sys.exc_info()[:2]
+ else: #get from schoolserver
+ folder = 'content/'+ subject
+ pth = SS / subject
+ script = 'cd ' + str(pth) + '\nget ' + milestone + '.msxo'
+ result = sftp(script, folder)
+ cmd = 'unzip '+ milestone +'.msxo'
+ cwd = path('content') / subject
+ subprocess.call(cmd,cwd=cwd,shell=True)
+ cmd = 'rm -rf content/'+subject+'/'+milestone+'.msxo'
+ subprocess.call(cmd, shell=True)
+
+def getActivitiesJs(subject):
+ if USB.exists(): #get from usb drive
+ pth = USB / subject
+ cmd = 'cp -r ' + pth / 'activities*' + ' ' + 'content/'+ subject
+ subprocess.call(cmd,shell=True)
+ else: #get from schoolserver
+ folder = 'content/'+ subject
+ pth = SS / subject
+ script = 'cd ' + str(pth) + '\nget activities*'
+ result = sftp(script, folder)
diff --git a/cgi-bin/fetchFile.py b/cgi-bin/fetchFile.py
index d905a1a..ca6d874 100755
--- a/cgi-bin/fetchFile.py
+++ b/cgi-bin/fetchFile.py
@@ -12,9 +12,9 @@ f = fin.read()
fin.close()
fpth = path(f)
print >> log, 'f=', fpth
-srcpth = fpth.parent / 'source'
+srcpth = fpth.parent
print >> log, 'srcpth=', srcpth
-fpth = srcpth / 'a.txt'
+fpth = srcpth / 'source.txt'
print >> log, 'f=',fpth, srcpth, fpth
fin = open(fpth, 'r')
txt = fin.read()
diff --git a/cgi-bin/fetch_milestone.py b/cgi-bin/fetch_milestone.py
index 0b13db7..b69e911 100755
--- a/cgi-bin/fetch_milestone.py
+++ b/cgi-bin/fetch_milestone.py
@@ -4,102 +4,107 @@ import os, sys, subprocess
from sugar.activity import activity
import cgi, cgitb
from path import path
+import activities
+from activities import getInstalled
+from activities import getActivitiesJs
+from activities import fetchMilestone
+from activities import getMilestones
+from activities import getActivities
+from activities import setMilestones
+from activities import setActivities
DATAPATH = path(activity.get_activity_root())/ 'data'
WORKPATH = DATAPATH / 'work'
-USB = path('/media/2011/content')
+USB = path('/media/2011/courseware')
SS = path('/library/courseware')
-#executes sftp command contained in scrpt
-#note scrpt must be written to disk and read by sftp command
-def sftp(script, folder = None):
- flog = open('/tmp/flog','w')
- pth = WORKPATH / 'script'
- subprocess.call('rm -rf ' + pth, shell=True)
- fout = open(pth, 'w')
- fout.write(script)
- fout.close()
- print >> flog, 'script', script
- authpth = '/home/olpc/.sugar/default/owner.key'
- auth = ' -oIdentityFile=' + authpth
- scrpt = ' -b ' + pth
- fin = open('/ofw/serial-number','r')
- serial_number = fin.read()
- fin.close()
- srvr = serial_number[:-1] + '@schoolserver'
- cmd = 'sftp ' + auth + scrpt + ' ' + srvr
- print >>flog, 'cmd=',cmd
- if folder:
- pid= subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=folder, shell=True)
- pid.wait()
- if pid.returncode == 0:
- result = pid.communicate()[0]
- else:
- result = pid.returncode
- else:
- pid = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
- pid.wait()
- if pid.returncode == 0:
- result = pid.communicate()[0]
- else:
- result = pid.returncode
- print >> flog, pid.returncode
- flog.close()
- return result
-
-def getInstalled(subject):
- pth = path('content') / subject
- temp = pth.dirs()
- milestones = []
- for item in temp:
- milestones.append(str(item.namebase))
- milestones.remove('karma')
- return milestones
-
-def getMilestone(subject, grade, milestone):
- print >>log, 'getMilestone', subject, grade, milestone
- if USB.exists: #get from usb drive
- pth = USB / subject
- cmd = 'cp -r ' + pth / milestone + ' ' + 'content/'+ subject
- subprocess.call(cmd,shell=True)
- else: #get from schoolserver
- folder = 'content/'+ subject
- pth = SS / subject
- script = 'cd ' + pth + '\nget -r ' + milestone
- result = sftp(script, folder)
+log = open('/tmp/logfm','w')
def process_milestones(subject, grade, current_ms):
#base on activities.js not milestone name
- current_milestone = (sbj+grade+'m'+current_ms).lower()
- next_milestone = (sbj+grade+'m'+next_ms).lower()
- print >> log, 'process_student_mode',grade,current_milestone,next_milestone
+ #need to get milestones as list where current_ms is index
+ fin = open('content/'+subject+'/activities_'+grade.lower()+'.js','r')
+ txt = fin.read()
+ fin.close()
+ lines = txt.split('\n')
+ milestones = []
+ for line in lines:
+ try:
+ milestone = eval(line)[0]
+ except:
+ continue
+ milestones.append(milestone)
+ current_milestone = milestones[int(current_ms)-1][4]
+ next_milestone = milestones[int(current_ms)][4]
installed = getInstalled(subject)
- print >> log, 'installed',subject,installed
+ if len(installed) < 1:
+ initialFlag = True
+ else:
+ initialFlag = False
if not current_milestone in installed:
- getMilestone(subject, current_milestone);
+ fetchMilestone(subject, grade, current_milestone)
+ milestones = getMilestones(subject)
+ for milestone in milestones:
+ if milestone[4] == current_milestone:
+ milestone[5] = 'blue'
+ setMilestones(subject,grade,milestones)
if not next_milestone in installed:
- getMilestone(subject, next_milestone)
+ fetchMilestone(subject, grade, next_milestone)
+ milestones = getMilestones(subject)
+ for milestone in milestones:
+ if milestone[4] == next_milestone:
+ milestone[5] = 'blue'
+ setMilestones(subject,grade,milestones)
+ if initialFlag and not mode == 'faculty':
+ #mark first milestone and first activity red
+ milestones = getMilestones(subject)
+ entry = milestones[0]
+ entry[5] = 'red'
+ milestone = entry[4]
+ setMilestones(subject, grade, milestones)
+ activities = getActivities(subject, milestone)
+ activities[0][5] = 'red'
+ setActivities(subject, milestone, activities)
def process_student(student,student_record):
- #copy grade activities.js to activities.js
- subprocess.call('cp ' + 'content/English/activities_' + grade.lower()+'.js content/activities.js',shell=True)
- subprocess.call('cp ' + 'content/Mathematics/activities_' + grade.lower()+'.js content/activities.js',shell=True)
- #download needed milestones
grade = student_record['grade']
en_milestone = student_record['milestones'][0]
ma_milestone = student_record['milestones'][1]
- print>>log, grade, en_milestone, ma_milestone
+ #copy activities.js for grade to activities.js
+ src = path('content') / 'English/activities_'+ grade.lower() + '.js'
+ dst = path('content') / 'English' / 'activities.js'
+ if not dst.exists():
+ cmd = 'cp ' + src + ' ' + dst
+ subprocess.call(cmd,shell=True)
+ src = path('content') / 'Mathematics/activities_'+ grade.lower() + '.js'
+ dst = path('content') / 'Mathematics' / 'activities.js'
+ if not dst.exists():
+ cmd = 'cp ' + src + ' ' + dst
+ subprocess.call(cmd,shell=True)
+ #return student menu
+ fin = open('menu/student_menu','r')
+ txt = fin.read()
+ fin.close()
+ print txt
+ #download needed milestones
#English
current_ms = en_milestone.split('.')[0]
process_milestones('English',grade, current_ms)
#Mathematics
current_ms = ma_milestone.split('.')[1]
process_milestones('Mathematics',grade, current_ms)
- #return student menu
- fin = open('menu/student_menu','r')
- txt = fin.read()
- fin.close()
- print txt
+
+def setColor(subject, grade, milestone, color):
+ milestones = getMilestones(subject)
+ for ms in milestones:
+ if ms[4] == milestone:
+ ms[5] = color
+ setMilestones(subject, grade, milestones)
+ milestones = getMilestones(subject, grade = grade)
+ for ms in milestones:
+ if ms[4] == milestone:
+ ms[5] = color
+ setMilestones(subject, grade, milestones)
def process_faculty():
sbj = form.getfirst('code', default="")
@@ -110,14 +115,14 @@ def process_faculty():
fin.close()
print txt
else:
+ if sbj[:2] == 'en':
+ subject = 'English'
+ else:
+ subject = 'Mathematics'
+ grade = sbj[2:]
milestone = form.getfirst('milestone', default = "")
- if len(milestone)>0:
- #fetch requested milestone
- if sbj[:2] == 'en':
- subject = 'English'
- else:
- subject = 'Mathematics'
- getMilestone(subject, grade, milestone)
+ fetchMilestone(subject,grade,milestone)
+ setColor(subject, grade, milestone, 'blue')
#main
#
@@ -125,7 +130,18 @@ def process_faculty():
#
cgitb.enable(display=True)
print 'Content-Type:text/html\n\n'
-log = open('/tmp/logfm','w')
+form = cgi.FieldStorage()
+#if milestone activities.js not installed, install them
+pth = path('content') / 'English'
+fs = pth.files('*.js')
+if len(fs) < 3:
+ #get them
+ getActivitiesJs('English')
+pth = path('content') / 'Mathematics'
+fs = pth.files('*.js')
+if len(fs) < 3:
+ #get them
+ getActivitiesJs('Mathematics')
#get nick
fin = open(DATAPATH / 'learner','r')
learner = fin.read()
@@ -137,12 +153,20 @@ fin.close()
student_record = eval(txt)
grade = student_record['grade']
if grade == 'F':
- mode = 'CW'
+ mode = 'faculty'
else:
mode = 'student'
-print >> log, 'mode', mode
-if mode == 'CW':
- process_faculty()
+print >> log, mode
+if mode == 'faculty':
+ try:
+ process_faculty()
+ except:
+ print >> log, 'process_faculty failed',sys.exc_info()[:2]
else:
- process_student(learner,student_record)
+ try:
+ process_student(learner,student_record)
+ except:
+ print >> log, 'process student failed', sys.exc_info()[:2]
+print >> log, 'done'
log.close()
+
diff --git a/cgi-bin/getIndex.py b/cgi-bin/getIndex.py
index c602c63..8e26f2f 100755
--- a/cgi-bin/getIndex.py
+++ b/cgi-bin/getIndex.py
@@ -13,7 +13,7 @@ from path import path
print 'Content-Type:text/html\n\n'
subjects = ['English', 'Mathematics']
contents = []
-d = path('/media/SS/content')
+d = path('/media/2011/courseware')
for subject in subjects:
pth = d / subject
course = []
diff --git a/cgi-bin/gettree.py b/cgi-bin/gettree.py
index eadb0b0..83aebaa 100755
--- a/cgi-bin/gettree.py
+++ b/cgi-bin/gettree.py
@@ -36,7 +36,7 @@ def outTree(treelist, n):
print 'Content-Type:text/html\n\n'
txt = ""
-d = path('/media/SS/content')
+d = path('/media/2011/courseware')
treelist = []
level = 0
stack = []
diff --git a/cgi-bin/results.py b/cgi-bin/results.py
index 8508d5c..9e5da11 100755
--- a/cgi-bin/results.py
+++ b/cgi-bin/results.py
@@ -4,6 +4,13 @@ import sys, subprocess, time
import cgi, cgitb
from sugar.activity import activity
from path import path
+from activities import getInstalled
+from activities import getActivitiesJs
+from activities import fetchMilestone
+from activities import getMilestones
+from activities import getActivities
+from activities import setMilestones
+from activities import setActivities
DATAPATH = path(activity.get_activity_root())/ 'data'
@@ -11,225 +18,233 @@ log = open('/tmp/logr','w')
retval = 0
cgitb.enable(display=True)
print 'Content-type:text/html\n\n'
-#parameters are activity, score
+#parameters is score
form = cgi.FieldStorage()
-score = form.getfirst('score', default='70')
-print >> log, 'score', score
-#close current session (/tmp/current_session)
-#update student record (/tmp/learner)
-#update milestone activities.js
-#if milestone is complete,
-#update subject activities.js
-#
-#update activities.js for next milestone
-#check for log in
-try:
- fin=open('/tmp/learner','r')
- learner = fin.read()
- fin.close()
-except:
- #no one is logged in
- print >> log, 'no one is logged in'
- learner = 'unknown'
-print >> log, 'learner',learner
-#read student record
-try:
- fin = open(DATAPATH / learner,'r')
- txt = fin.read()
- fin.close()
-except:
- print >> log, 'no matching student record'
- #no matching student_record - force blank student_record
- learner = 'unknown'
- txt = '{}'
-try:
- student_record = eval(txt)
-except:
- student_record = {}
- student_record['grade'] = ''
- student_record['milestones'] = ['1.1','1.1']
- student_record['progress'] = []
- print >> log, 'student_record eval failed',sys.exc_info()[:2]
- print >> log, 'student record txt',txt
-#read current_session
-try:
- fin = open('/tmp/current_session','r')
- txt = fin.read()
- fin.close()
-except:
- #no session open
- txt = ""
- print >> log,'no session open'
-print >> log, 'session', txt
-session_data = txt.split(',')
-if len(session_data)>1:
- activity=session_data[0]
- starttime = session_data[1]
- stoptime = str(int(time.time()))
- result = score
- print >> log, 'session data', activity, starttime, stoptime, result
-else:
- activity = ""
- result = ''
- print >> log, 'no session data'
-#update activities.js
-print >> log, 'update activities.js', activity, result
-if len(activity)==10 and int(result) >= 70:
- #update activities.js
- milestone = activity[:7]
- if activity[:2] == 'en':
- subject = 'English'
- else:
- subject = 'Mathematics'
- pth = path('content') / subject / milestone / 'activities.js'
- print >> log, 'read activities activities.js',pth
+score = form.getfirst('score', default="")
+subject = form.getfirst('subject',default="")
+milestone = form.getfirst('milestone',default="")
+activity = form.getfirst('activity',default="")
+print >> log, 'score', score, subject, milestone, activity
+if len(score) > 0 and len(subject) > 0 and len(milestone) >0 and len(activity) > 0:
+ #close current session (/tmp/current_session)
+ #update student record (/tmp/learner)
+ #check for log in
+ try:
+ fin=open(DATAPATH / 'learner','r')
+ learner = fin.read()
+ fin.close()
+ except:
+ #no one is logged in
+ print >> log, 'no one is logged in'
+ learner = 'unknown'
+ print >> log, 'learner',learner
+ #read student record
try:
- fin = open(pth,'r')
+ fin = open(DATAPATH / learner,'r')
txt = fin.read()
fin.close()
except:
- print 'open activities activities.js failed', sys.exc_info()[:2]
- lines = txt.split('\n')
- txtout = ""
- nxtflag = False
- print >>log, 'activities.js lines',len(lines)
- for line in lines:
- line = line + '\n'
- if activity in line:
- nxtflag=True
- retval = 1
- txtout=txtout+line.replace('red','green')
- elif nxtflag and line.find('blue')>-1:
- nxtflag=False
- txtout=txtout+line.replace('blue','red')
- else:
- txtout = txtout+line
+ print >> log, 'no matching student record'
+ #no matching student_record - force blank student_record
+ learner = 'unknown'
+ txt = '{}'
try:
- fout = open(pth,'w')
- fout.write(txtout)
- fout.close()
+ student_record = eval(txt)
except:
- print >> log, 'write activities activities.js failed',sys.exc_info()[:2]
- print >> log, 'activity activities.js updated', nxtflag
- #if nxtflag == True - means end of milestone
- if nxtflag:
- #update milestones in student record
+ student_record = {}
+ student_record['grade'] = ''
+ student_record['milestones'] = ['1.1','1.1']
+ student_record['progress'] = []
+ print >> log, 'student_record eval failed',sys.exc_info()[:2]
+ print >> log, 'student record txt',txt
+ #read current_session
+ try:
+ fin = open('/tmp/current_session','r')
+ txt = fin.read()
+ fin.close()
+ except:
+ #no session open
+ txt = ""
+ print >> log,'no session open'
+ print >> log, 'session', txt
+ session_data = txt.split(',')
+ if len(session_data)>1:
+ activity=session_data[0]
+ starttime = session_data[1]
+ stoptime = str(int(time.time()))
+ result = score
+ print >> log, 'session data', activity, starttime, stoptime, result
+ else:
+ activity = ""
+ result = ''
+ print >> log, 'no session data'
+ #update activities.js
+ print >> log, 'update activities.js', activity, result
+ if len(activity)>0 and int(result) >= 70:
+ #we can do this via the form
+ #update activities.js
+ #find current milestone
+ #get milestones, find red one
+ #find current activity
+ #get activities
+ #find red one
+ #update to green
+ #find next one
+ #update to red
+ milestone = activity[:7]
+ if activity[:2] == 'en':
+ subject = 'English'
+ else:
+ subject = 'Mathematics'
+ pth = path('content') / subject / milestone / 'activities.js'
+ print >> log, 'read activities activities.js',pth
try:
- milestones = student_record['milestones']
- print >> log, 'milestones', milestones
- if subject == 'English':
- msstate = milestones[0]
- else:
- msstate = milestones[1]
- print >> log, 'msstate', msstate
- try:
- temp = msstate.split('.')
- msstr = int(temp[0])+1
- temp[0] = str(int(msstr))
- temp[1] = '1'
- msstate = temp[0]+'.'+temp[1]
- except:
- print >> log, 'msstate set up failed', sys.exc_info()[:2]
- if subject == 'English':
- milestones[0] = msstate
- else:
- milestones[1] = msstate
- student_record['milestones']=milestones
+ fin = open(pth,'r')
+ txt = fin.read()
+ fin.close()
except:
- print >> log, 'update milestones failed',sys.exc_info()[:2]
- #update activities.js for subject
- milestone = activity[:7]
- pth = path('content') / subject / 'activities.js'
- print >> log, 'milestone',milestone,'pth',pth
- fin = open(pth,'r')
- txt = fin.read()
- fin.close()
+ print 'open activities activities.js failed', sys.exc_info()[:2]
lines = txt.split('\n')
txtout = ""
- nxtmsflag = False
+ nxtflag = False
+ print >>log, 'activities.js lines',len(lines)
for line in lines:
line = line + '\n'
- if milestone in line:
- nxtmsflag = True
- retval = 2
- txtout = txtout + line.replace('red','green')
- elif nxtmsflag == True:
- if line.find('blue')>0:
- nxtmsflag = False
- txtout = txtout + line.replace('blue','red')
- elif line.find('Blue')>0:
- nxtmsflag = False
- txtout = txtout + line.replace('Blue','red')
+ if activity in line:
+ nxtflag=True
+ retval = 1
+ txtout=txtout+line.replace('red','green')
+ elif nxtflag and line.find('blue')>-1:
+ nxtflag=False
+ txtout=txtout+line.replace('blue','red')
else:
- print >> log, nxtmsflag, line
- txtout = txtout + line
- fout = open(pth,'w')
- fout.write(txtout)
- fout.close()
- if nxtmsflag:
- #what do we do now - this learner is done!
- print >> log, 'learner is done!'
- retval = 3
- #update first activity in next milestone
- print >> log, 'first activity in next milestone', milestone
- nxt = str(int(milestone[5:7])+1)
- if len(nxt)<2:
- nxt = '0'+nxt
- next_milestone = milestone[:5]+nxt
- next_activity = next_milestone + 'a01'
- print >> log, 'next', next_milestone, next_activity
- pth = path('content') / subject / next_milestone / 'activities.js'
- print >> log, 'pth', pth
- fin = open(pth,'r')
- txt = fin.read()
- fin.close()
- lines = txt.split('\n')
- txtout = ""
- for line in lines:
- line = line + '\n'
- if next_activity in line:
- t1 = line.replace('Blue','red')
- txtout = txtout + t1.replace('blue','red')
- else:
- txtout = txtout + line
- fout = open(pth,'w')
- fout.write(txtout)
- fout.close()
- else:
- #update milestones in student record
- milestones = student_record['milestones']
- if subject == 'English':
- msstate = milestones[0]
- else:
- msstate = milestones[1]
- temp = msstate.split('.')
- msstr = int(temp[1])+1
- temp[1] = str(int(msstr))
- msstate = temp[0]+'.'+temp[1]
- if subject == 'English':
- milestones[0] = msstate
- else:
- milestones[1] = msstate
- student_record['milestones']=milestones
-#update student_record
-#if there is a problem, above processing should leave activity = ''
-print >> log, activity, len(activity)
-if len(activity) == 10:
- try:
- progress = student_record['progress']
- status = (starttime, stoptime, result)
- progress.append({activity:status})
- student_record['progress'] = progress
- except:
- print >> log, 'update progress failed', sys.exc_info()[:2]
- try:
- fout = open(DATAPATH / learner,'w')
- fout.write(str(student_record))
- fout.close()
- except:
- print >> log, 'update student record failed', sys.exc_info()[:2]
- #close current session - works even if none open
- subprocess.call('rm -rf /tmp/current_session',shell=True)
+ txtout = txtout+line
+ try:
+ fout = open(pth,'w')
+ fout.write(txtout)
+ fout.close()
+ except:
+ print >> log, 'write activities activities.js failed',sys.exc_info()[:2]
+ print >> log, 'activity activities.js updated', nxtflag
+ #if nxtflag == True - means end of milestone
+ if nxtflag:
+ #update milestones in student record
+ try:
+ milestones = student_record['milestones']
+ print >> log, 'milestones', milestones
+ if subject == 'English':
+ msstate = milestones[0]
+ else:
+ msstate = milestones[1]
+ print >> log, 'msstate', msstate
+ try:
+ temp = msstate.split('.')
+ msstr = int(temp[0])+1
+ temp[0] = str(int(msstr))
+ temp[1] = '1'
+ msstate = temp[0]+'.'+temp[1]
+ except:
+ print >> log, 'msstate set up failed', sys.exc_info()[:2]
+ if subject == 'English':
+ milestones[0] = msstate
+ else:
+ milestones[1] = msstate
+ student_record['milestones']=milestones
+ except:
+ print >> log, 'update milestones failed',sys.exc_info()[:2]
+ #update activities.js for subject
+ milestone = activity[:7]
+ pth = path('content') / subject / 'activities.js'
+ print >> log, 'milestone',milestone,'pth',pth
+ fin = open(pth,'r')
+ txt = fin.read()
+ fin.close()
+ lines = txt.split('\n')
+ txtout = ""
+ nxtmsflag = False
+ for line in lines:
+ line = line + '\n'
+ if milestone in line:
+ nxtmsflag = True
+ retval = 2
+ txtout = txtout + line.replace('red','green')
+ elif nxtmsflag == True:
+ if line.find('blue')>0:
+ nxtmsflag = False
+ txtout = txtout + line.replace('blue','red')
+ elif line.find('Blue')>0:
+ nxtmsflag = False
+ txtout = txtout + line.replace('Blue','red')
+ else:
+ print >> log, nxtmsflag, line
+ txtout = txtout + line
+ fout = open(pth,'w')
+ fout.write(txtout)
+ fout.close()
+ if nxtmsflag:
+ #what do we do now - this learner is done!
+ print >> log, 'learner is done!'
+ retval = 3
+ #update first activity in next milestone
+ print >> log, 'first activity in next milestone', milestone
+ nxt = str(int(milestone[5:7])+1)
+ if len(nxt)<2:
+ nxt = '0'+nxt
+ next_milestone = milestone[:5]+nxt
+ next_activity = next_milestone + 'a01'
+ print >> log, 'next', next_milestone, next_activity
+ pth = path('content') / subject / next_milestone / 'activities.js'
+ print >> log, 'pth', pth
+ fin = open(pth,'r')
+ txt = fin.read()
+ fin.close()
+ lines = txt.split('\n')
+ txtout = ""
+ for line in lines:
+ line = line + '\n'
+ if next_activity in line:
+ t1 = line.replace('Blue','red')
+ txtout = txtout + t1.replace('blue','red')
+ else:
+ txtout = txtout + line
+ fout = open(pth,'w')
+ fout.write(txtout)
+ fout.close()
+ else:
+ #update milestones in student record
+ milestones = student_record['milestones']
+ if subject == 'English':
+ msstate = milestones[0]
+ else:
+ msstate = milestones[1]
+ temp = msstate.split('.')
+ msstr = int(temp[1])+1
+ temp[1] = str(int(msstr))
+ msstate = temp[0]+'.'+temp[1]
+ if subject == 'English':
+ milestones[0] = msstate
+ else:
+ milestones[1] = msstate
+ student_record['milestones']=milestones
+ #update student_record
+ #if there is a problem, above processing should leave activity = ''
+ print >> log, activity, len(activity)
+ if len(activity) == 10:
+ try:
+ progress = student_record['progress']
+ status = (starttime, stoptime, result)
+ progress.append({activity:status})
+ student_record['progress'] = progress
+ except:
+ print >> log, 'update progress failed', sys.exc_info()[:2]
+ try:
+ fout = open(DATAPATH / learner,'w')
+ fout.write(str(student_record))
+ fout.close()
+ except:
+ print >> log, 'update student record failed', sys.exc_info()[:2]
+ #close current session - works even if none open
+ subprocess.call('rm -rf /tmp/current_session',shell=True)
print >> log, 'exception?',sys.exc_info()[:2]
print retval
diff --git a/content/index.html b/content/index.html
index 4023043..b6be074 100755
--- a/content/index.html
+++ b/content/index.html
@@ -5,10 +5,11 @@
<meta charset="UTF-8"/>
<link rel="stylesheet" href="menu.css" type="text/css"/>
<script type="text/javascript" src="../js/jquery-1.4.js"></script>
-<script type="text/javascript" src="../js/jquery-ui-1.js"></script>
<script type="text/javascript">
+$(function(){
$('#content')
.load('http://localhost:8008/cgi-bin/fetch_milestone.py')
+});
</script>
</head>
<body>
diff --git a/content/js/global.js b/content/js/global.js
index 851e541..9ac7c57 100755
--- a/content/js/global.js
+++ b/content/js/global.js
@@ -18,8 +18,18 @@ function gobackTwo(){
window.location = backTwo;
}
function apply(){
+ alert(window.location+' type '+typeof(window.location+''));
+ items = (window.location+"").split('/');
+ score = '70';
+ subject = items[4];
+ milestone = items[5];
+ activity = items[6];
+ alert(score+' '+subject+' '+milestone+' '+activity);
$('#content').load('http://localhost:8008/cgi-bin/results.py',{
- 'score':'70',
+ 'score':score,
+ 'subject':subject,
+ 'milestone':milestone,
+ 'activity':activity
},function(responseText, status, xhr){
if (responseText==1){ goback();
} else if (responseText==2){ gobackOne();
diff --git a/content/js/learner_lesson.js b/content/js/learner_lesson.js
index e9ca38a..fe874d3 100755
--- a/content/js/learner_lesson.js
+++ b/content/js/learner_lesson.js
@@ -48,7 +48,10 @@ $(document).ready(
xy = this;
// directory structure: content/subject/milestone/activity
// for learners, we want the 'red' activity
- if(xy[5]=='red'){
+ url = window.location+"";
+ alert(url.indexOf('?F'));
+ if ((x > xy[1])&&(x < xy[1]+cellsize)&&(y < xy[2])&&(y > xy[2] - cellsize) ){
+ if ((xy[5]=='red') || (url.indexOf('?F') > -1)){
//set path
if (xy[3] == "EPaath"){
pth = "../../../src/FrameWork.html#" + xy[4];
@@ -70,6 +73,7 @@ $(document).ready(
function(){
window.location = pth;
});
+ };
};
});
});
diff --git a/content/js/learner_subject.js b/content/js/learner_subject.js
index 443355a..069586a 100755
--- a/content/js/learner_subject.js
+++ b/content/js/learner_subject.js
@@ -46,6 +46,13 @@ $(document).ready(
var pth;
var count = 0;
+ url = window.location+"";
+ if(url.indexOf('index')<0){
+ mode = 'faculty'
+ }else{
+ mode = 'student'
+ }
+ alert(mode);
$("canvas").click(function($e) {
// find out which act in acts was clicked
x = $e.pageX
@@ -53,11 +60,16 @@ $(document).ready(
$.each(acts, function() {
xy = this;
// directory structure: content/subject/milestone/activity
- // for learners, we want the red milestone
- if( xy[5] == 'red'){
- pth = xy[4]+'/index.html';
- window.location = pth;
- };
+ if ( (x > xy[1]) && (x < xy[1] + cellsize) && (y < xy[2])
+ && (y > xy[2] - cellsize)
+ && (mode == 'faculty')) {
+ pth = xy[4]+'/index.html';
+ window.location = pth;
+ }else if (xy[5] == 'red'){
+ pth = xy[4]+'/index.html';
+ window.location = pth;
+ };
+ });
});
});
// ladder
diff --git a/content/js/lesson.js b/content/js/lesson.js
index c8617eb..902fefe 100755
--- a/content/js/lesson.js
+++ b/content/js/lesson.js
@@ -47,7 +47,10 @@ $(document).ready(
$.each(acts, function() {
xy = this;
// directory structure: activity/karma/courses/course/milestone.html + folder per activity
- if ( (x > xy[1]) && (x < xy[1] + cellsize) && (y < xy[2]) && (y > xy[2] - cellsize) ) {
+ if ( (x > xy[1])
+ && (x < xy[1] + cellsize)
+ && (y < xy[2])
+ && (y > xy[2] - cellsize) ) {
pth = "../../" + "content/unavailable.html";
if (xy[3] == "EPaath"){
pth = "../../../src/FrameWork.html#" + xy[4];
diff --git a/content/js/subject.js b/content/js/subject.js
index e0e8fa2..c670d79 100755
--- a/content/js/subject.js
+++ b/content/js/subject.js
@@ -1,9 +1,9 @@
$(document).ready(
function(){
- var k = Karma(assetList);
+ var k = Karma();
- k.ready(function() {
- logos;
+ k.ready(function() {
+
activities;
k.ready(function(){
@@ -50,18 +50,21 @@ $(document).ready(
y = $e.pageY;
$.each(acts, function() {
xy = this;
- // here we need to download
- if ( (x > xy[1]) && (x < xy[1] + cellsize) && (y < xy[2]) && (y > xy[2] - cellsize) ) {
- // find out if year is 2010 or 2011
- if (xy[5] == 'cyan') {
- $('#content').load(
+ // here we need to download or go to activity
+ if ( (x > xy[1]) && (x < xy[1] + cellsize) && (y < xy[2])
+ && (y > xy[2] - cellsize) ) {
+ if (xy[5].indexOf('cyan')>-1) { //download
+ $('<div id="temp" />').load(
'http://localhost:8008/cgi-bin/fetch_milestone.py',
- {'code':xy[2],'milestone':xy[4]},
+ {'code':xy[0],'milestone':xy[4]},
function(responseText, status, xhr) {
//refresh when done
window.onunload=function(){return true;};
window.location.reload(true);
});
+ }else{ //go to activity
+ pth = xy[4]+'/index.html';
+ window.location = pth+'?F';
};
};
});
@@ -202,22 +205,12 @@ $(document).ready(
};
idx = idx + 1;
acts[idx] = [il, x, y, ty, ls, cc, id];
- if (id < 2){
- drawmilestone(acts[idx]);
- } else {
- // draw logo
- alert('draw logo - should not happen');
- ctx.drawImage(k.image[logos[id-1]].media, x, y - cellsize);
- if (ix > 0) {
- ctx.textAlign = 'center'
- ctx.fillStyle = 'black'
- ctx.fillText(ix, x + cellsize/2, y+cellsize/4, cellsize);
- };
- };
+ drawmilestone(acts[idx]);
};
};
draw();
+
});
});
});
diff --git a/content/menu.css b/content/menu.css
index f31bd05..a2a6de3 100755
--- a/content/menu.css
+++ b/content/menu.css
@@ -37,7 +37,7 @@
#c12{
position:absolute;
top:50px;
- left:250px;
+ left:350px;
width:200px;
height:200px;
}
@@ -45,7 +45,7 @@
#c13{
position:absolute;
top:50px;
- left:450px;
+ left:650px;
width:200px;
height:200px;
}
@@ -61,7 +61,7 @@
#c22{
position:absolute;
top:300px;
- left:250px;
+ left:350px;
width:200px;
height:200px;
}
@@ -69,13 +69,13 @@
#c23{
position:absolute;
top:300px;
- left:450px;
+ left:650px;
width:200px;
height:200px;
}
#c1b{
position:absolute;
- top:450px;
+ top:550px;
left:50px;
width:250px;
height:200px;
@@ -83,7 +83,7 @@
#c2b{
position:absolute;
- top:450px;
+ top:550px;
left:600px;
width:250px;
height:200px;
diff --git a/launch.py b/launch.py
index 80b3249..55d7598 100755
--- a/launch.py
+++ b/launch.py
@@ -1,14 +1,5 @@
#!/usr/bin/python
-#demo version
-#XO2 is P1..P3
-#XO3 is P4..P6
-#loads one module per 'nick'
-#ignore faculty
-#if current module not installed, install it
-#remove previous module if installed
-##essentially one student per grade for demo purposes
-#maintain journal entry by 'nick'
from sugar.activity import activity
from sugar.activity.activity import get_bundle_path
from sugar.datastore import datastore
@@ -21,11 +12,12 @@ import BaseHTTPServer
DATAPATH = path(activity.get_activity_root()) / "data"
WORKPATH = DATAPATH / "work"
-SUBJECTS = ['Mathematics','Mathematics11']
+SUBJECTS = ['English','Mathematics']
+
+log = open('/tmp/loglaunch','w')
class Learn(activity.Activity):
def __init__(self, handle):
- self.flog = open('logfile','w')
activity.Activity.__init__(self, handle)
#get serial number and nick
fin = open('/ofw/serial-number','r')
@@ -46,27 +38,28 @@ class Learn(activity.Activity):
except:
self.nickname = 'newbuild'
self.grade = 'P6'
- print >> self.flog, self.serial, self.nickname, self.grade
+ print >> log, self.serial, self.nickname, self.grade
if path('firstrun').exists():
+ print >> log, 'firstrun'
subprocess.call('cp -rf .mozilla/ .macromedia /home/olpc', shell=True)
subprocess.call('rm firstrun', shell=True)
#set up student record based on nick
fout = open(DATAPATH / self.nickname,'w')
- fout.write("{'grade':'P4','progress':[],'milestones:['1.1','1.2']}")
+ fout.write("{'grade':'P4','progress':[],'milestones':['1.1','1.1']}")
fout.close()
#set up learner based on nick
fout = open(DATAPATH / 'learner', 'w')
fout.write(self.nickname)
fout.close()
- #add links for karma folder
- base = path(get_bundle_path()) / 'content'
- karma = base / 'karma'
- for pth in SUBJECTS:
- cwd = base / pth
- subprocess.call('ln -s ' + karma + ' karma',shell=True,cwd=cwd)
+ #add links for karma folder
+ base = path(get_bundle_path()) / 'content'
+ karma = base / 'karma'
+ for pth in SUBJECTS:
+ cwd = base / pth
+ subprocess.call('ln -s ' + karma + ' karma',shell=True,cwd=cwd)
#start localserver
- #print 'close any open localserver'
+ #print >> log, 'close any open localserver'
tpid = subprocess.Popen('ps aux |grep CGIHTTPServer', stdout = subprocess.PIPE, shell=True)
tstr = tpid.communicate()[0]
tt = tstr.split('\n')
@@ -74,172 +67,33 @@ class Learn(activity.Activity):
if t.find('python') > -1:
cmd = 'kill -9 ' + t[4:13].strip()
subprocess.call(cmd, shell=True)
- try:
- rt = subprocess.call('ls /media/SS', shell=True)
- except:
- print >> self.flog, '/media/SS not found', sys.exc_info()[:2]
- rt = 2
cmd = 'python -m CGIHTTPServer 8008'
- if rt > 0:
- p= subprocess.Popen(cmd, stdout=subprocess.PIPE,shell=True)
- self.sftpflag = True
- else:
- p= subprocess.Popen(cmd, stdout=subprocess.PIPE,shell=True,cwd = '/media/SS')
- self.sftpflag = True
- print >> self.flog, 'CGIHTTPServer started', p.pid, 'rt=', rt, self.sftpflag
+ p= subprocess.Popen(cmd, stdout=subprocess.PIPE,shell=True)
+ self.sftpflag = True
+ print >> log, 'CGIHTTPServer started', p.pid, self.sftpflag
- subprocess.call('mkdir -p ' + WORKPATH, shell=True)
- print 'sftp flag=',self.sftpflag
- if self.sftpflag == True:
- print >> self.flog, 'call openLearn'
- self.openLearn()
#start Firefox
cmd = './firefox http://localhost:8008/content/index.html'
subprocess.call(cmd, shell=True)
- #is it possible to save state here?
-
- def openLearn(self):
- #set up current state for this learner
- #this should all be in openLearn
- print >> self.flog, 'processing openLearn'
- self.sinfo = {'English':{'1':[]},'Mathematics':{'1':[]}}
- self.sinfo['nick'] = self.nickname
- self.sinfo['grade'] = self.grade
- print >> self.flog, 'openLearn', str(self.sinfo)
- #open local statefile and set self.sinfo from it
- #if none, we can use the default
- try:
- fin = open(DATAPATH / self.nickname,'r')
- sinfo = eval(fin.read())
- fin.close()
- self.sinfoflag = True
- except:
- print >> self.flog, 'user', self.nickname, 'not found'
- self.sinfoflag = False
- if self.sinfoflag:
- keys = self.sinfo.keys()
- keys.sort()
- for key in keys:
- try:
- self.sinfo[key] = sinfo[key]
- except:
- print >> self.flog, 'key error', key
- print >> self.flog, 'sinfoflag', self.sinfoflag
- #gets most recent Journal entry
- timestamp = 0
- jentry = None
- ds_objects, num_objects = datastore.find({'title':'Learn Activity'})
- print >> self.flog, 'journal entries', num_objects
- for i in xrange(0, num_objects, 1):
- ds_objects[i].destroy()
- try:
- nick = ds_objects[i].metadata['nick']
- if not nick == self.nickname:
- continue
- except:
- nick = ""
- continue
- try:
- this = ds_objects[i].metadata['timestamp']
- except:
- this = timestamp
- if this > timestamp:
- jentry = ds_objects[i]
- timestamp = this
- if jentry:
- #the values from the Journal entry should be the same as the
- #local copy
- #we should read the local file and compare to the latest entry
- #for now, any discrepancy will be logged but the local copy will be
- #used
- print >> self.flog, 'latest journal entry', this
- temp = self.sinfo.keys()
- try:
- keys= temp.sort()
- except:
- keys = []
- print >> self.flog, 'no keys', str(self.sinfo)
- for key in keys:
- try:
- if not self.sinfo[key] == jentry.metadata[key]:
- print >> self.flog, 'key value differs', key, self.sinfo[key], jentry.metadata[key]
- except:
- print >> self.flog, 'key error', key
- else:
- print 'journal entry not found'
- cfg = str(self.sinfo)
- print >> self.flog, self.nickname, cfg
- fout = open(DATAPATH / self.nickname, 'w')
- fout.write(cfg)
- fout.close()
-
- #executes sftp command contained in scrpt
- #note scrpt must be written to disk and read by sftp command
- def sftp(self, script, folder = None):
- pth = WORKPATH / 'script'
-
- try:
- fout = open(pth, 'w')
- fout.write(script)
- fout.close()
- except:
- print >> self.flog, 'write of script failed', sys.exc_info()[:2]
- print >> self.flog, 'in sftp, script written'
- authpth = '/home/olpc/Activities/Learn.activity/.ssh/id_rsa'
- auth = ' -oIdentityFile=' + authpth
- scrpt = ' -b ' + pth
- srvr = ' admin@schoolserver'
- cmd = 'sftp ' + auth + scrpt + srvr
-
- if folder:
- pid= subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=folder, shell=True)
- pid.wait()
- print >> self.flog, 'sftp', folder, pid.returncode
- if pid.returncode == 0:
- result = pid.communicate()[0]
- if len(result) < 1:
- print >> self.flog, 'not connected'
- else:
- result = pid.communicate()[0]
- #err = pid.communicate()[1]
- else:
- pid = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
- pid.wait()
- print >> self.flog, 'sftp', pid.returncode
- if pid.returncode == 0:
- result = pid.communicate()[0]
- if len(result) < 1:
- print >> self.flog, 'not connected'
- else:
- result = pid.communicate()[0]
- #err = pid.communicate()[1]
- if pid.returncode == 0:
- print >> self.flog, 'in sftp, result', result
- #print >> self.flog, 'in sftp, err', err
- return result
+ activity_close()
def write_file(self, file_path):
- #nick of learner is in /tmp/learner
+ #nick of learner is in DATAPATH / learner
+ fin = open(DATAPATH / 'learner','r')
+ learner = fin.read()
+ fin.close()
+ #we need to read the student record
+ fin = open(DATAPATH / learner,'r')
+ txt = fin.read()
+ fin.close()
+ #and save it to the Journal
+ fout = open(file_path,'w')
try:
- fin = open('/tmp/learner','r')
- learner = fin.read()
- fin.close()
- except:
- return
- if not learner == 'unknown':
- #we need to read the student record
- fin = open(DATAPATH / learner,'r')
- txt = fin.read()
- fin.close()
- #and save it to the Journal
- fout = open(file_path,'w')
- try:
- fout.write(txt)
- finally:
- fout.close()
- #rm /tmp/learner to log out
- subprocess.call('rm -rf /tmp/learner',shell=True)
+ fout.write(txt)
+ finally:
+ fout.close()
def activity_close(self):
+ log.close()
self.close(True)
diff --git a/menu/faculty_menu b/menu/faculty_menu
index 1912ff8..d526bb4 100644
--- a/menu/faculty_menu
+++ b/menu/faculty_menu
@@ -25,12 +25,14 @@
<img src="assets/image/mathematics.png" alt="Mathematics" width=175 height=175 />
</a>
</div>
+ </div>
<div id = 'c22'>
<div class = 'main'>
<a href="Mathematics/p5.html">Mathematics P5
<img src="assets/image/mathematics.png" alt="Mathematics" width=175 height=175 />
</a>
</div>
+ </div>
<div id = 'c23'>
<div class = 'main'>
<a href="Mathematics/p6.html">Mathematics P6