Friday, October 06, 2006
Importing Users in Plone 2.5
To get a new site going from an old Plone 1.0.5 site, I decided to recreate everything from scratch rather than upgrading (not sure that would even be possible). Most of the content I will just manually convert since there isn't much of that to do.
But I wanted to move at least the old 'acl_users' list over programatically. I found this page which was pretty helful in that respect:
http://www.parit.ca/documentation/plonestuff/plone-training-part-7-scripting-users
So I have written the Python code shown below to do what I want. I put this code in the file 'acl_users_import.py' in the 'Extensions' directory of my Plone/Zope instance.
Then I went into the ZMI and created an "External Method" with the following entries:
Here is the code I put in the 'PLONEHOME/Extentions' dirctory as 'acl_users_import.py':
Then I created a tab separated file with the info I wanted to import and put it in the 'PLONEHOME/Extensions' directory as well. The file path in the code above needs to be changed to reflect the full path to that file. Here is an example of the 'acl_users_import_list.txt' file:
But I wanted to move at least the old 'acl_users' list over programatically. I found this page which was pretty helful in that respect:
http://www.parit.ca/documentation/plonestuff/plone-training-part-7-scripting-users
So I have written the Python code shown below to do what I want. I put this code in the file 'acl_users_import.py' in the 'Extensions' directory of my Plone/Zope instance.
Then I went into the ZMI and created an "External Method" with the following entries:
Id: acl_users_import
Title: acl_users_import
Module Name: acl_users_import
Function Name: acl_users_import
Here is the code I put in the 'PLONEHOME/Extentions' dirctory as 'acl_users_import.py':
def acl_users_import(self):
""""""
#self.doAddUser(name='foo', password='foo', roles=['Member'],
# domains=[], groups=['Reviewers'])
ret = 'Running acl_users_import.py.\n'
pr = self.portal_registration
filename = '/home/zope6/Extensions/acl_users_import_list.txt'
ret += 'Reading tab separated file \"%s\".\n' % filename
try:
fp = open(filename, 'r')
except IOError, msg:
ret += 'Error: %s\n' % msg
return ret
ret += 'Skipping first line.\n'
# Skip first line.
fp.readline()
for line in fp.readlines():
line = line.strip()
elements = line.split('\t')
id = elements[0]
pw = elements[1]
email = elements[2]
fullname = elements[3]
roles=('Member',)
ret += 'Adding %s (%s)\n' % (id, fullname)
try:
member = pr.addMember(id, pw, roles,
properties={ 'username': id,
'email' : email,
'fullname': fullname,
})
except ValueError, msg:
ret += ' Error: %s\n' % msg
fp.close()
return ret
Then I created a tab separated file with the info I wanted to import and put it in the 'PLONEHOME/Extensions' directory as well. The file path in the code above needs to be changed to reflect the full path to that file. Here is an example of the 'acl_users_import_list.txt' file:
ID pw email Name
foo foobar sim@noisygecko.com Foo
foo2 foobar sim@noisygecko.com Foo2
foo3 foobar sim@noisygecko.com Foo3