# -*- coding: utf-8 # $Id$ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # IVA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA __version__ = "$Revision$"[11:-2] import time import Globals, os, cPickle from threading import Lock l = Lock() data_dir = os.path.join(Globals.INSTANCE_HOME,'var','iva_stat') try: os.mkdir(data_dir) except: pass def load_data(path): #global ug_stat, uc_stat, c_stat, o_stat ug_stat = {} # not course spec. user stats uc_stat = {} # course spec. user stats c_stat = {} # course stats o_stat = {} # object views ug = os.path.join(data_dir, path+'ug_stat.dat') uc = os.path.join(data_dir, path+'uc_stat.dat') c = os.path.join(data_dir, path+'c_stat.dat') o = os.path.join(data_dir, path+'o_stat.dat') try: f = open(ug, "r") ug_stat = cPickle.load(f) f.close() except: pass try: f = open(uc, "r") uc_stat = cPickle.load(f) f.close() except: pass try: f = open(c, "r") c_stat = cPickle.load(f) f.close() except: pass try: f = open(o, "r") o_stat = cPickle.load(f) f.close() except: pass return ug_stat, uc_stat, c_stat, o_stat def load_stats(app, iva_instances): """ create stats objects into temp_folder """ from stats2_engine import load_data from OFS import SimpleItem for iva in iva_instances: path = '_'.join(iva.getPhysicalPath()[1:]).lower()+'_' print "preparing IVA@", iva, "loading files starting with", path tf = iva.temp_folder ug_stat, uc_stat, c_stat, o_stat = load_data(path) ug = SimpleItem.SimpleItem() ug.ug_stat = ug_stat uc = SimpleItem.SimpleItem() uc.uc_stat = uc_stat c = SimpleItem.SimpleItem() c.c_stat = c_stat o = SimpleItem.SimpleItem() o.o_stat = o_stat try: tf._setObject('ug_stat', ug) except: pass try: tf._setObject('uc_stat', uc) except: pass try: tf._setObject('c_stat', c) except: pass try: tf._setObject('o_stat', o) except: pass try: tf.ug_stat._p_changed = True tf._p_changed = True except: pass