summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul James Adams (Kolab Systems) <adams@kolabsys.com>2010-10-23 00:39:18 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2010-10-23 00:39:18 +0100
commit717bb2bfade7713fd011d53002df0a1ecb9492ad (patch)
treee0db304a21e31fae051313c4205bb37ac9d8e1b0
parent416ee1d06b67b68cd4d50415c2cb2d04b41c6df1 (diff)
downloadpykolab-717bb2bfade7713fd011d53002df0a1ecb9492ad.tar.gz
Check in Paul's script for mass-creating contacts
-rw-r--r--pykolab/tests/create-contacts.py96
-rw-r--r--pykolab/tests/kaddressbook-contact.tpl54
2 files changed, 150 insertions, 0 deletions
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 <adams a 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 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"
+
+<?xml version="1.0" encoding="UTF-8"?>
+<contact version="1.0">
+ <product-id>KAddressBook 3.3, Kolab resource</product-id>
+ <uid>@@uid@@</uid>
+ <sensitivity>public</sensitivity>
+ <name>
+ <given-name>@@given_name@@</given_name>
+ <middle-names>@@middle_names@@</middle-names>
+ <last-name>@@last_name@@</last-name>
+ <full-name>@@full_name@</full-name>
+ </name>
+ <email>
+ <display-name>@@display_name@@</display-name>
+ <smtp-address>@@email_address@@</smtp-address>
+ </email>
+ <phone>
+ <type>mobile</type>
+ <number>@@number@@</number>
+ </phone>
+ <birthday>@@birthday@@</birthday>
+ <preferred-address>home</preferred-address>
+</contact>
+
+--Boundary-00=@@uid@@-- \ No newline at end of file