[1877] | 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 | """ |
---|
[1882] | 21 | remove Data from live db to make a demodb |
---|
[1877] | 22 | """ |
---|
| 23 | import random |
---|
[1878] | 24 | import transaction |
---|
| 25 | import logging |
---|
[1882] | 26 | logger = logging.getLogger('Extension.SetupDemoDB.removeStudents') |
---|
[1877] | 27 | |
---|
| 28 | def 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 |
---|
[1882] | 36 | #students_catalog = context.students_catalog |
---|
[1878] | 37 | students = context.portal_url.getPortalObject().campus.students |
---|
[1882] | 38 | step = 5 |
---|
| 39 | #all = students_catalog() |
---|
| 40 | all=students.objectIds() |
---|
[1878] | 41 | todel = (len(all)/10) |
---|
| 42 | sample = random.sample(all,todel) |
---|
[1882] | 43 | logger.info("starting to delete %d students" % todel) |
---|
[1878] | 44 | for i in range(0,len(sample),step): |
---|
[1882] | 45 | ids = [b for b in sample[i:i + step]] |
---|
| 46 | logger.info("deleting students %s" % (ids)) |
---|
[1878] | 47 | for sid in ids: |
---|
| 48 | if hasattr(stdir, sid): |
---|
| 49 | stdir.deleteEntry(sid) |
---|
| 50 | try: |
---|
| 51 | students.manage_delObjects(ids) |
---|
| 52 | except: |
---|
[1882] | 53 | logger.info("error deleting %s" % (ids)) |
---|
[1878] | 54 | logger.info("deleted %d students %s" % (step,ids)) |
---|
| 55 | transaction.commit() |
---|