source: WAeUP_SRP/base/Extensions/SetupDemoDB.py @ 2377

Last change on this file since 2377 was 1882, checked in by Henrik Bettermann, 17 years ago

that works (slowly but steadily)

  • 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 1882 2007-06-12 08:18:16Z henrik $
20"""
21remove Data from live db to make a demodb
22"""
23import random
24import transaction
25import logging
26logger = logging.getLogger('Extension.SetupDemoDB.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 = 5
39    #all = students_catalog()
40    all=students.objectIds()
41    todel = (len(all)/10)
42    sample = random.sample(all,todel)
43    logger.info("starting to delete %d students" % todel)
44    for i in range(0,len(sample),step):
45        ids = [b  for b in sample[i:i + step]]
46        logger.info("deleting students %s" % (ids))
47        for sid in ids:
48            if hasattr(stdir, sid):
49                stdir.deleteEntry(sid)
50        try:
51            students.manage_delObjects(ids)
52        except:
53            logger.info("error deleting %s" % (ids))
54        logger.info("deleted %d students %s" % (step,ids))
55        transaction.commit()
Note: See TracBrowser for help on using the repository browser.