From 717bb2bfade7713fd011d53002df0a1ecb9492ad Mon Sep 17 00:00:00 2001 From: "Paul James Adams (Kolab Systems)" Date: Sat, 23 Oct 2010 00:39:18 +0100 Subject: Check in Paul's script for mass-creating contacts --- pykolab/tests/create-contacts.py | 96 ++++++++++++++++++++++++++++++++++ pykolab/tests/kaddressbook-contact.tpl | 54 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 pykolab/tests/create-contacts.py create mode 100644 pykolab/tests/kaddressbook-contact.tpl (limited to 'pykolab') diff --git a/pykolab/tests/create-contacts.py b/pykolab/tests/create-contacts.py new file mode 100644 index 0000000..0b60da6 --- /dev/null +++ b/pykolab/tests/create-contacts.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +# -*- coding: utf-8 -*- +# Copyright 2010 Kolab Systems AG (http://www.kolabsys.com) +# +# Paul James Adams +# Jeroen van Meeuwen (Kolab Systems) +# +# 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 os, random, sys + +if __name__ == "__main__": + num = int(sys.argv[1]) + + contact_tpl_file = open('./kaddress-contact.tpl', 'r') + contact_tpl_orig = contact_tpl_file.read() + contact_tpl_file.close() + + users = ['john', 'joe', 'max'] + domains = ['doe.org', 'sixpack.com', 'imum.net'] + uid_alloc = [] + + alphabet = "abcdefghijklmnopqrstuvwxwz" + + for user in users: + for contact in xrange(num): + uid = "%s.%s" %(str(random.randint(1000000000,9999999999)),str(random.randint(0,999)).zfill(3)) + if not uid in uid_alloc: + uid_alloc.append(uid): + else: + continue + + domain = domains[random.randint(0,2)] + + birthday = "" + if random.randint(0,100) => 75: + year = str(random.randint(1960, 2010)) + month = str(random.randint(1,12)) + day = str(random.randint(1,27)) + birthday = "%s-%s-%s" % (year, month, day) + + middle_names = "" + if random.randint(0,100) => 50: + middle_names = random.sample(alphabet, (4, 8)).capitalize() + + number = "" + if random.randint(0,100) => 25: + number = "+441234567890" + + given_name = random.sample(alphabet, (4, 8)).capitalized() + last_name = random.sample(alphabet, (4, 8)).capitalized() + + contact = { + 'user': user, + 'user_email': "%s@%s" % (user, domain), + 'given_name': given_name, + 'middle_names': middle_names. + 'last_name': last_name, + 'full_name': "%s %s %s" % (given_name, middle_names, last_name), + 'display_name': "%s %s" % (given_name, last_name), + 'email_address': "%s@%s" % (given_name, domain), + 'number': number, + 'birthday': birthday + } + + directory = "/kolab/var/imapd/spool/domains/%s/%s/%s/user/%s/Contacts" %(domains[user_num][0],domains[user_num],user[0],user) + if not os.path.isdir(directory): + directory = "./kolab/var/imapd/spool/domains/%s/%s/%s/user/%s/Contacts" %(domains[user_num][0],domains[user_num],user[0],user) + if not os.path.isdir(directory): + os.makedirs(directory) + + out = open("%s/%d." %(directory,num), 'w') + + for key in contact.keys(): + contact_tpl = contact_tpl.replace("@@%s@@" % key, '%s' % contact[key]) + + out.write(event_tpl) + out.close() + try: + os.chown("%s/%d." %(directory,num), 19415, 19415) + except: + pass + diff --git a/pykolab/tests/kaddressbook-contact.tpl b/pykolab/tests/kaddressbook-contact.tpl new file mode 100644 index 0000000..542498a --- /dev/null +++ b/pykolab/tests/kaddressbook-contact.tpl @@ -0,0 +1,54 @@ +From: @@user@@ <@@user_email@@> +Subject: @@uid@@ +Date: Thu, 20 May 2010 09:04:51 +0100 +MIME-Version: 1.0 +X-Kolab-Type: application/x-vnd.kolab.contact +Content-Type: Multipart/Mixed; + boundary="Boundary-00=_j0O9Lpj9TsAjYEA" +Status: RO +X-Status: OT +X-KMail-EncryptionState: +X-KMail-SignatureState: +X-KMail-MDN-Sent: +X-UID: 57 + +--Boundary-00=@@uid@@ +Content-Type: Text/Plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +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.contact; + name="kolab.xml" +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; + filename="kolab.xml" + + + + KAddressBook 3.3, Kolab resource + @@uid@@ + public + + @@given_name@@ + @@middle_names@@ + @@last_name@@ + @@full_name@ + + + @@display_name@@ + @@email_address@@ + + + mobile + @@number@@ + + @@birthday@@ + home + + +--Boundary-00=@@uid@@-- \ No newline at end of file -- cgit v1.1