diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2010-10-22 21:43:14 +0100 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2010-10-22 21:43:14 +0100 |
commit | 0b3390839207a82956cf996fec79cc7b5696bb98 (patch) | |
tree | 748768a67d6a5596669e2ae11b3d511d7f15807c | |
parent | 9d6bb677ffe6a362dc939c9fd152f9c27a4a96d6 (diff) | |
download | pykolab-0b3390839207a82956cf996fec79cc7b5696bb98.tar.gz |
Populate a bunch of user calendar directories with a bunch of events
-rwxr-xr-x | kolabtest.py | 41 | ||||
-rw-r--r-- | pykolab/tests/__init__.py | 118 | ||||
-rw-r--r-- | pykolab/tests/kcal-event.tpl | 67 |
3 files changed, 226 insertions, 0 deletions
diff --git a/kolabtest.py b/kolabtest.py new file mode 100755 index 0000000..8e94de3 --- /dev/null +++ b/kolabtest.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# +# Copyright 2010 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program 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; version 2 only +# +# This program 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 Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import logging +import os +import sys + +# For development purposes +sys.path.extend(['.', '..']) + +from pykolab.translate import _ +from pykolab.tests import * + +try: + import pykolab.logger +except ImportError, e: + print >> sys.stderr, _("Cannot load pykolab/logger.py:") + print >> sys.stderr, "%s" % e + sys.exit(1) + +if __name__ == "__main__": + kolab = Tests() + kolab.run() + diff --git a/pykolab/tests/__init__.py b/pykolab/tests/__init__.py new file mode 100644 index 0000000..3abceba --- /dev/null +++ b/pykolab/tests/__init__.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# Copyright 2010 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# This program 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; version 2 only +# +# This program 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 Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import datetime +import os +import random +import time + +from pykolab.conf import Defaults, Runtime +import pykolab.conf + +class Tests(object): + def __init__(self): + print "yeah i'm here" + + def run(self): + print "and now i start running" + + # Create 3 users, john, joe and max + # Create the default groupware folders for each user + # Mark each of them as groupware folders (annotations, in python, how?) + # Generate a lot of content for each folder + + event_tpl_file = open('./pykolab/tests/kcal-event.tpl', 'r') + event_tpl_orig = event_tpl_file.read() + event_tpl_file.close() + + users = [ 'john', 'joe', 'max' ] + domains = [ 'doe.org', 'sixpack.com', 'imum.net' ] + + mydate = datetime.date(1111, 11, 11).today() + + this_month = mydate.month + + uids_alloc = [] + + for user in users: + # Each of the users gets 500 events + num = 1 + while num < 501: + uid = "%s.%s" %(str(random.randint(1000000000,9999999999)),str(random.randint(0,999)).zfill(3)) + if not uid in uids_alloc: + uids_alloc.append(uid) + else: + continue + + success = False + while not success: + try: + myday = mydate.replace(day=random.randint(1,31)) + success = True + except: + success = False + + event_tpl = event_tpl_orig + + domain = domains[random.randint(0,2)] + + time_start = random.randint(0,21) + time_end = time_start + 2 + + time_start = str(time_start).zfill(2) + time_end = str(time_end).zfill(2) + + event = { + 'uid': uid, + 'user': user, + 'user_email': "%s@%s" %(user,domain), + 'date_start': "2010-%s-%s" %(this_month,str(myday).zfill(2)), + 'date_end': "2010-%s-%s" %(this_month,str(myday).zfill(2)), + 'time_start': time_start, + 'time_end': time_end + } + + if num % 100 == 0: + print "User %s calendaring events %s done" %(user,num) + event['recurrence'] = """<recurrence cycle="weekly"> + <interval>1</interval> + <day>thursday</day> + <range type="none"></range> + </recurrence>""" + else: + event['recurrence'] = "" + + directory = "/kolab/var/imapd/spool/domains/t/test90.kolabsys.com/%s/user/%s/Calendar" %(user[0],user) + if not os.path.isdir(directory): + directory = "./kolab/var/imapd/spool/domains/t/test90.kolabsys.com/%s/user/%s/Calendar" %(user[0],user) + if not os.path.isdir(directory): + os.makedirs(directory) + + out = open("%s/%d." %(directory,num), 'w') + + for key in event.keys(): + event_tpl = event_tpl.replace("@@%s@@" % key, '%s' % event[key]) + + out.write(event_tpl) + out.close() + try: + os.chown("%s/%d." %(directory,num), 19415, 19415) + except: + pass + num += 1 diff --git a/pykolab/tests/kcal-event.tpl b/pykolab/tests/kcal-event.tpl new file mode 100644 index 0000000..5e668cc --- /dev/null +++ b/pykolab/tests/kcal-event.tpl @@ -0,0 +1,67 @@ +From: @@user@@ von Test <@@user_email@@> +Subject: libkcal-@@uid@@ +Date: Thu, 21 Oct 2010 14:40:32 +0100 +MIME-Version: 1.0 +X-Kolab-Type: application/x-vnd.kolab.event +Content-Type: Multipart/Mixed; + boundary="Boundary-00=@@uid@@" +Status: RO +X-Status: OT +X-KMail-EncryptionState: +X-KMail-SignatureState: +X-KMail-MDN-Sent: +X-UID: 0 + +--Boundary-00=@@uid@@ +Content-Type: Text/Plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +Content-Disposition: + +This is a Kolab Groupware object. +To view this object you will need an email client that can understand the Kolab Groupware format. +For a list of such email clients please visit +http://www.kolab.org/kolab2-clients.html +--Boundary-00=@@uid@@ +Content-Type: application/x-vnd.kolab.event; + name="kolab.xml" +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; + filename="kolab.xml" + +<?xml version="1.0" encoding="UTF-8"?> +<event version="1.0"> + <product-id>KOrganizer 4.4.5, Kolab resource</product-id> + <uid>libkcal-@@uid@@</uid> + <creation-date>2010-10-21T13:40:32Z</creation-date> + <last-modification-date>2010-10-21T13:42:14+00:00</last-modification-date> + <sensitivity>public</sensitivity> + <start-date>@@date_start@@T@@time_start@@:00:00Z</start-date> + <summary>test event</summary> + <location>somewhere else</location> + <organizer> + <display-name>@@user@@ von Test</display-name> + <smtp-address>@@user_email@@</smtp-address> + </organizer> + <attendee> + <display-name>@@user@@ von Test</display-name> + <smtp-address>@@user_email@@</smtp-address> + <status>accepted</status> + <request-response>false</request-response> + <invitation-sent>false</invitation-sent> + <role>required</role> + </attendee> +@@recurrence@@ + <alarm>15</alarm> + <advanced-alarms> + <alarm type="display"> + <enabled>1</enabled> + <start-offset>-15</start-offset> + </alarm> + </advanced-alarms> + <revision>0</revision> + <show-time-as>busy</show-time-as> + <end-date>@@date_end@@T@@time_end@@:00:00Z</end-date> +</event> + +--Boundary-00=@@uid@@-- |