source: WAeUP_SRP/trunk/Extensions/SetupDemoDB.py @ 1881

Last change on this file since 1881 was 1878, checked in by joachim, 18 years ago

new speed improved version

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1#-*- mode: python; mode: fold -*-
2# (C) Copyright 2005 The WAeUP group  <http://www.waeup.org>
3# Author: Joachim Schmitz (js@aixtraware.de)
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
18#
19# $Id: SetupDemoDB.py 1878 2007-06-11 18:20:17Z joachim $
20"""
21remove Data from live db to make a demodb
22"""
23import random
24import transaction
25import logging
26logger = logging.getLogger('Extension.removeStudents')
27
28def removeStudents(self):
29    "remove nearly all students to form a lightweight demodb"
30    context = self.uniben
31    wftool = context.portal_workflow
32    mtool = context.portal_membership
33    member = mtool.getAuthenticatedMember()
34    roles = member.getRolesInContext(context)
35    stdir = context.portal_directories.students
36    students_catalog = context.students_catalog
37    students = context.portal_url.getPortalObject().campus.students
38    step = 10
39    all = students_catalog()
40    todel = (len(all)/10)
41    sample = random.sample(all,todel)
42    logger.info("starting to delete %d students" % todel)
43    for i in range(0,len(sample),step):
44        ids = [b.id  for b in sample[i:i + step]]
45        logger.info("deleting students %s" % (ids))
46        for sid in ids:
47            if hasattr(stdir, sid):
48                stdir.deleteEntry(sid)
49        try:
50            students.manage_delObjects(ids)
51        except:
52            logger.info("erro deleting %s" % (ids))
53        logger.info("deleted %d students %s" % (step,ids))
54        transaction.commit()
Note: See TracBrowser for help on using the repository browser.