I am at a real loss for what to do. My boss wants me to devise a way to extract user data from a Plone installation and I don't know how to do it. The best option I've found so far is the following piece of Python code. Below it is the executed code from the console. Can anyone tell me what I'm doing wrong? I am no coder and have no experience with Python at all. Is there some easier way to do what I'm trying to do that anyone knows of? Any suggestions would help, thanks.


***********************************Here is the unexecuted code:


#!/usr/bin/python2.3


#
# Authors - Stephan February, Michael Clark
#
# License - LGPL - http://www.gnu.org/licenses/lgpl.txt
#


import sys

#set your zope directory as appropriate
sys.path.append('/usr/lib/zope/lib/python/')

from ZODB import FileStorage, DB

# set this to point to your ZODB
# NOTE: Zope/Plone needs to be stopped first
#
storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
db = DB(storage)
connection = db.open()
root = connection.root()

#obtain a list of all acl_users for the plone site
userList = root.items()[0][1]
.getUsers()

portalData = root.items()[0][1]

#obtain a portal_membership tool
mtool = root.items()[0][1]

#the following loop will print user information as:
# username, password, emailaddress, fullname,<list of user's roles>
for user in userList:
user_wrapper = mtool.getMemberById( user.getUserName() )
email = user_wrapper.getProperty('email')
fullname = user_wrapper.getProperty('fullname')

print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
email, fullname, user.getRoles())

db.close()


***************************************Now the executed code:


Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:0Cool [MSC v.1310 32 bit (Intel)] o
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python2.3
...
>>>
>>> #
... # Authors - Stephan February, Michael Clark
... #
... # License - LGPL - http://www.gnu.org/licenses/lgpl.txt
... #
...
>>>
>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('/usr/lib/zope/lib/python/')
>>>
>>> from ZODB import FileStorage, DB
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ZODB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
... storage = FileStorage.FileStorage('/var/lib/zope/data/Data.fs')
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
NameError: name 'FileStorage' is not defined
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'DB' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'connection' is not defined
>>>
>>> #obtain a list of all acl_users for the LUGS plone site
... userList = root.items()[0][1]
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>> .getUsers()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'getUsers'
>>>
>>> portalData = root.items()[0][1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'root' is not defined
>>>
>>> #obtain a portal_membership tool
... mtool = root.items()[0][1]
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'root' is not defined
>>>
>>> #the following loop will print user information as:
... # username, password, emailaddress, fullname,<list of user's roles>
... for user in userList:
... user_wrapper = mtool.getMemberById( user.getUserName() )
... email = user_wrapper.getProperty('email')
... fullname = user_wrapper.getProperty('fullname')
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
NameError: name 'userList' is not defined
>>> print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
File "<stdin>", line 1
print("'%s','%s','%s','%s'\"%s\" ") % (user, user._getPassword(),
^
IndentationError: unexpected indent
>>> email, fullname, user.getRoles())
File "<stdin>", line 1
email, fullname, user.getRoles())
^
SyntaxError: invalid syntax
>>>
>>> db.close()

***************************************

My configuration is as follows:

Python 2.5.1
Zope 2.9.5
Plone 2.5.2

Given:#!/usr/bin/python2.3
...
>>> from ZODB import FileStorage, DB
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ZODB
>>>
...
My configuration is as follows:

Python 2.5.1
It looks like you problem stems from not having the right version of ZODB installed in the right place, or not running the right version of Python. Shouldn't the top line read #!/usr/bin/python2.5?

Okay, I made some changes now, and this is what happens.....


>>> import sys
>>>
>>> #set your zope directory as appropriate
... sys.path.append('C:\Program Files\Plone 2\Data\var')
>>> sys.path.append('C:\Program Files\Plone 2\Zope\lib\python\ZODB')
>>>
>>> from ZODB import FileStorage, DB
>>>
>>> # set this to point to your ZODB
... # NOTE: Zope/Plone needs to be stopped first
... #
...
>>> storage = FileStorage.FileStorage ('C:\Program Files\Plone 2\Data\var\data.f
s')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\FileStorage\FileStorage.py
", line 112, in __init__
self._lock_file = LockFile(file_name + '.lock')
File "C:\Program Files\Plone 2\Zope\lib\python\ZODB\lock_file.py", line 60, in
__init__
self._fp = open(path, 'w+')
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\Plone 2\\Data\
x0bar\\data.fs.lock'
>>> db = DB(storage)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'storage' is not defined
>>> connection = db.open()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'db' is not defined
>>> root = connection.root()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'connection' is not defined
>>>

Any suggestions?

This article has been dead for over six months. Start a new discussion instead.