summaryrefslogtreecommitdiffstats
path: root/pykolab/tests/create-contacts.py
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 /pykolab/tests/create-contacts.py
parent416ee1d06b67b68cd4d50415c2cb2d04b41c6df1 (diff)
downloadpykolab-717bb2bfade7713fd011d53002df0a1ecb9492ad.tar.gz
Check in Paul's script for mass-creating contacts
Diffstat (limited to 'pykolab/tests/create-contacts.py')
-rw-r--r--pykolab/tests/create-contacts.py96
1 files changed, 96 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
+