diff options
author | Tony Anderson <tony@traveler.(none)> | 2011-03-02 07:04:25 (GMT) |
---|---|---|
committer | Tony Anderson <tony@traveler.(none)> | 2011-03-02 07:04:25 (GMT) |
commit | 19ee99d100dee0403d1ba23f0d07140f2bf475ee (patch) | |
tree | c8ac6d608569cb1b431475ced1b07002af68cfc6 | |
parent | 7307b74f13329171f58f59550f4f14e03be5d5da (diff) |
version 12.2
-rwxr-xr-x | activity/activity.info | 2 | ||||
-rwxr-xr-x | cgi-bin/activities.py | 45 | ||||
-rwxr-xr-x | cgi-bin/setUpSubject.py | 40 | ||||
-rwxr-xr-x | launch.py | 28 |
4 files changed, 66 insertions, 49 deletions
diff --git a/activity/activity.info b/activity/activity.info index af6bed0..9c6aeb0 100755 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,5 +1,5 @@ [Activity] -#version = 12.1 +#version = 12.2 name = Learn service_name = rw.olpc.Learn icon = activity-learn diff --git a/cgi-bin/activities.py b/cgi-bin/activities.py index 5c4f56c..741a70f 100755 --- a/cgi-bin/activities.py +++ b/cgi-bin/activities.py @@ -144,50 +144,47 @@ def getSubjects(): pth = USB / 'subjects.js' cmd = 'cp -r ' + pth + ' ' + 'content/' subprocess.call(cmd,shell=True) + pth = USB / 'index.html' + cmd = 'cp -r ' + pth + ' ' + 'content/' + subprocess.call(cmd,shell=True) else: #get from schoolserver folder = 'content/' pth = SS - script = 'cd ' + str(pth) + '\nget subjects.js' + script = 'cd ' + str(pth) + '\nget subjects.js\nget index.html' result = sftp(script, folder) -def lsFile(path,filename): +def getKarma(): if USB.exists(): #get from usb drive - pth = USB / path / filename - cmd = 'ls ' + pth + ' ' - pid = subprocess.Popen(cmd,stdout=PIPE,shell=True) - pid.wait() - result = pid.communicate() - else: + pth = USB / 'karma.zip' + cmd = 'cp -r ' + pth + ' ' + 'content/' + subprocess.call(cmd,shell=True) + else: #get from schoolserver + folder = 'content/' pth = SS - script = 'cd ' + str(pth) + '\nls '+filename - log = open('/tmp/logls','w') - print >> log,'pth',pth,'script',script - result = sftp(script) - print >> log,'result',result - log.close() - return result + script = 'cd ' + str(pth) + '\nget karma.zip' + result = sftp(script, folder) + cmd = 'unzip karma.zip' + cwd = path('content') + subprocess.call(cmd,cwd=cwd,shell=True) + cmd = 'rm -rf content/karma.zip' + subprocess.call(cmd, shell=True) -def getFile(subject,filename): +def getFile(tgtpth,filename): log = open('/tmp/loggetfile','w') + subject = tgtpth.name if USB.exists(): #get from usb drive pth = USB / subject / filename cmd = 'cp -r ' + pth + ' ' + tgtpth - log = open('/tmp/loggetfile','w') print >> log, 'usb',cmd - pid = subprocess.Popen(cmd,shell=True) - pid.wait() - (result,err) = pid.communicate() + subprocess.call(cmd,shell=True) else: #get from schoolserver - print >> log, 'params', subject, filename pth = SS / subject if filename.find('*') > -1: script = 'cd ' + str(pth) + '\nmget ' + filename else: script = 'cd ' + str(pth) + '\nget ' + filename print >> log, 'sftp', pth, script - log.close() - result = sftp(script, path('content') / subject) - log = open('/tmp/loggetfile1','w') + result = sftp(script, tgtpth) print >> log,'sftp result', result print >> log,'getFile done' log.close() diff --git a/cgi-bin/setUpSubject.py b/cgi-bin/setUpSubject.py index 79feb0f..edfb649 100755 --- a/cgi-bin/setUpSubject.py +++ b/cgi-bin/setUpSubject.py @@ -4,23 +4,31 @@ import cgi, cgitb from path import path from activities import getFile -cgitb.enable(display=True) log = open('/tmp/logsetup','w') -print >> log, 'log opened' +basepth = path('content') +cgitb.enable(display=True) print 'Content-Type:text/html\n\n' -form = cgi.FieldStorage() -subject = form.getfirst('subject') -tgtpth = path('content') / subject -srcpth = path('courseware') / subject -print >> log, subject, tgtpth.exists(), tgtpth, srcpth -if not tgtpth.exists(): - pid = subprocess.Popen('mkdir ' + tgtpth,stdout=subprocess.PIPE,shell=True) - pid.wait() - (result,err) = pid.communicate() - print >> log, 'mkdir', result, err - result = getFile(subject, '*.js') - print >> log, 'js result', result - result = getFile(subject, '*.html') - print >> log, 'html result', result +pth = basepth / 'subjects.js' +fin = open(pth,'r') +txt = fin.read() +fin.close() +lines = txt.split('\n') +for line in lines: + try: + entry = eval(line)[0] + except: + continue + print >> log, line, len(entry) + print >> log, entry[0],entry[1],entry[2] + subject = entry[1] + tgtpth = basepth / subject + print >> log, 'tgtpth', tgtpth + if not tgtpth.exists(): + subprocess.call('mkdir ' + tgtpth,shell=True) + result = getFile(tgtpth, '*.js') + result = getFile(tgtpth, '*.html') + result = getFile(tgtpth,'*.png') + result = getFile(tgtpth,'*.gif') + print >> log, 'loaded',tgtpth print >> log, 'done' log.close() @@ -6,11 +6,17 @@ from sugar.datastore import datastore import subprocess, time, sys from path import path -from activities import getSubjects -from activities import Config import CGIHTTPServer import BaseHTTPServer +firstrun = False +if not path('activities.py').exists(): + subprocess.call('ln -s cgi-bin/activities.py activities.py',shell=True) + firstrun = True +from activities import getSubjects +from activities import getKarma +from activities import Config + try: from sugar import profile _using_gconf = False @@ -38,9 +44,8 @@ class Learn(activity.Activity): self.grade = self.nickname[:2] print >> log, self.serial, self.nickname, self.grade if not path(DATAPATH / self.nickname).exists(): - print >> log, 'firstrun' - subprocess.call('cp -rf .mozilla/ .macromedia /home/olpc', shell=True) #set up student record based on nick + print 'new student - set up student record',self.nickname student_record = {'grade':self.grade, 'progress':[], 'milestones':['1.1','1.1'] @@ -48,12 +53,16 @@ class Learn(activity.Activity): fout = open(DATAPATH / self.nickname,'w') fout.write(str(student_record)) fout.close() + if firstrun: #reset content - print >> log,'reset content' + print >> log,'firstrun: reset content' subprocess.call('rm -rf content/*',shell=True) + subprocess.call('cp -rf .mozilla/ .macromedia /home/olpc', shell=True) pth = path('content') / 'karma' if not pth.exists(): - subprocess.call('cp -r karma content',shell=True) + getKarma() + if not pth.exists(): + print >> log, 'karma folder is not loaded' pth = path('content') / 'subjects.js' if not pth.exists(): getSubjects() @@ -84,9 +93,12 @@ class Learn(activity.Activity): #start Firefox cmd = './firefox http://localhost:8008/content/index.html?'+self.nickname print >> log, 'launch Firefox', cmd + pid = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) + pid.wait() + (result,err) = pid.communicate() + print >> log, 'Firefox quit', result, err log.close() - subprocess.call(cmd, shell=True) - activity.close() + activity.close() def get_nick_from_sugar(self): """ Returns nick from Sugar """ |